Skip to content

subinstrinit

Runs the initialization code of a numbered or named instrument.

The called instrument can print messages or set up data at initialization. subinstrinit has no output arguments and does not run the called instrument at performance time. Its audio processing and audio output opcodes do not run. Use subinstr when you need audio from the called instrument.

Syntax

subinstrinit(instrnum [, p4] [, p5] [...])
subinstrinit("insname" [, p4] [, p5] [...])
subinstrinit instrnum [, p4] [, p5] [...]
subinstrinit "insname" [, p4] [, p5] [...]

Initialization

instrnum -- Number of the instrument to be called.

“insname” -- A string (in double-quotes) representing a named instrument.

p4, p5, ... -- Values passed to the called instrument as p4, p5, and so on.

The called instrument's p2 and p3 values will be identical to the host instrument's values. While the host instrument can control its own duration, any such attempts inside the called instrument will most likely have no effect.

Examples

Instrument 1 uses its p4 to choose instrument 2, 3, or 4, then passes its p5 as the called instrument's p4. Each called instrument prints a message during initialization. This example makes no sound and needs no audio device.

Here is an example of the subinstrinit opcode. It uses the file subinstrinit-modern.csd.

Example of the subinstrinit opcode.
<CsoundSynthesizer>
<CsOptions>
; This example prints messages and makes no sound.
-n -d
; By Stefano Cucchi 2020
</CsOptions>
<CsInstruments>

; Initialize the global variables.
sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

instr 1
; Choose a child with p4 and pass p5 as the child's p4.
  subinstrinit(p4, p5)
endin

instr 2
  prints("Instrument 2 initialized with p4 = %g\n", p4)
endin

instr 3
  prints("Instrument 3 initialized with p4 = %g\n", p4)
endin

instr 4
  prints("Instrument 4 initialized with p4 = %g\n", p4)
endin

</CsInstruments>
<CsScore>

i1 0 2 2 10
i1 2 2 3 20
i1 4 2 4 30

e

</CsScore>
</CsoundSynthesizer>

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

Example of the subinstrinit opcode.
<CsoundSynthesizer>
<CsOptions>
; This example prints messages and makes no sound.
-n -d
; By Stefano Cucchi 2020
</CsOptions>
<CsInstruments>

; Initialize the global variables.
sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

instr 1
; Choose a child with p4 and pass p5 as the child's p4.
subinstrinit p4, p5
endin

instr 2
prints "Instrument 2 initialized with p4 = %g\n", p4
endin

instr 3
prints "Instrument 3 initialized with p4 = %g\n", p4
endin

instr 4
prints "Instrument 4 initialized with p4 = %g\n", p4
endin


</CsInstruments>
<CsScore>


i1 0 2 2 10
i1 2 2 3 20
i1 4 2 4 30

e

</CsScore>
</CsoundSynthesizer>

The console output includes these messages. Each message appears once when the corresponding score event starts.

Instrument 2 initialized with p4 = 10
Instrument 3 initialized with p4 = 20
Instrument 4 initialized with p4 = 30

See also

Sub-instrument Control

Credits

New in version 4.23