instr
Prev | Orchestra Opcodes and Operators | Next

## instr

instr — Starts an instrument block.

## Description

Starts an instrument block.

## Syntax

    instr i, j, ...

## Initialization

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
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).

## Performance

### Calling an Instrument within an Instrument

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
    ...
    endin

If an instrument is defined with a name, you simply call it directly like an opcode:

    asig MyOscil iamp, ipitch, iftable

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.

| 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.

## Examples

Here is an example of the instr opcode. It uses the files instr.orc and instr.sco.

Example 189. Example of the instr opcode.

    /* instr.orc */
    ; 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
    endin
    /* instr.orc */

    /* instr.sco */
    ; Play Instrument #1 for 2 seconds.
    i 1 0 2
    e
    /* instr.sco */

## See Also

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

## Credits

Example written by Kevin Conder.

Prev | Up | Next
instimes | Home | int