instr — Starts an instrument block.


Starts an instrument block.


instr i, j, ...


Starts an instrument block defining instruments i, j, ...

i, j, ... must be numbers, not expressions. Any positive integer is legal, and in any order, but excessively high numbers are best avoided.

[Note] Note

There may be any number of instrument blocks in an orchestra.

Instruments can be defined in any order (but they will always be both initialized and performed in ascending instrument number order, with the exception of notes triggered by real time events that are initialized in the order of being received but still performed in ascending instrument number order). Instrument blocks cannot be nested (i.e. one block cannot contain another).


Calling an Instrument within an Instrument

[Warning] Warning

This behavior is not fully available in Csound 5. In Csound 5, you must use the subinstr opcode.

You can call an instrument within an instrument as if it were an opcode either with the subinstr opcode or by specifying an instrument with a text name:

instr MyOscil

By default, all output parameters correspond to the called instrument's output with the signal output opcodes. All input parameters are mapped to the called instrument's p-fields starting with the fourth one, p4. The values of the called instrument's second and third p-fields, p2 and p3, are automatically set to those of the calling instrument's.

A named instrument must be defined before any instrument that calls it.

[Note] Hint

If you use the outc opcode, you can create an instrument that will compile and function in any orchestra of any number of channels greater than or equal to the output channels of the instrument.

A nice feature to use with named instruments is the #include feature. You can then define your named instruments in separate files, using #include when you need to use one.


Here is an example of the instr opcode. It uses the file instr.csd.

Example 387. Example of the instr opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

; Select audio/midi flags here according to platform
; Audio out   Audio in
-odac           -iadc    ;;;RT audio I/O
; For Non-realtime ouput leave only the line below:
; -o instr.wav -W ;;; for file output any platform

; Initialize the global variables.
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1

; Instrument #1.
instr 1
  iamp = 10000
  icps = 440
  iphs = 0

  a1 oscils iamp, icps, iphs
  out a1


; Play Instrument #1 for 2 seconds.
i 1 0 2


See Also

endin, in, out, opcode, endop, setksmps, xin, xout, subinstr, subinstrinit


Example written by Kevin Conder.