instance — Schedules a new instrument instance, storing the instance handle in a variable.
Schedules a new instrument instance, returning a handle that can be used later to refer directly to the running instance. This opcode is similar to schedule, but has the added facility of retrieving the instance handle.
iHandle instance insnum, iwhen, idur [, ip4] [, ip5] [...]
iHandle instance "insname", iwhen, idur [, ip4] [, ip5] [...]
iHandle -- this variable will contain a handle to the event instance. It can be used, for example, to stop the given instrument instance via the kill opcode. Note that the instance handle is only valid once the instrument is initialised.
insnum -- instrument number. Equivalent to p1 in a score i statement. insnum must be a number greater than the number of the calling instrument.
“insname” -- A string (in double-quotes) representing a named instrument.
iwhen -- start time of the new event. Equivalent to p2 in a score i statement. iwhen must be nonnegative. If iwhen is zero, insum must be greater than or equal to the p1 of the current instrument.
idur -- duration of event. Equivalent to p3 in a score i statement.
ip4, ip5, ... -- Equivalent to p4, p5, etc., in a score i statement.
instance adds a new score event. The arguments, including options, are the same as in a score. The iwhen time (p2) is measured from the time of this event.
If the duration is zero or negative the new event is of MIDI type, and inherits the release sub-event from the scheduling instruction.
![]() |
Note |
---|---|
Note that the instance opcode can't accept string p-fields. If you need to pass strings when instantiating an instrument, use the scoreline or scoreline_i opcode. |
Here is an example of the instance opcode. It uses the file instance.csd.
Example 394. Example of the instance opcode.
See the sections Real-time Audio and Command Line Flags for more information on using command line flags.
<CsoundSynthesizer> <CsOptions> ; 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 instance.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> ; Initialize the global variables. sr = 44100 kr = 4410 ksmps = 10 nchnls = 1 ; Instrument #1 - oscillator with a high note. instr 1 ; Play Instrument #2 at the same time. iHandleinstance 2, 0, p3 ; Play a high note. a1 oscils 10000, 880, 1 out a1 endin ; Instrument #2 - oscillator with a low note. instr 2 ; Play a low note. a1 oscils 10000, 220, 1 out a1 endin </CsInstruments> <CsScore> ; Table #1, a sine wave. f 1 0 16384 10 1 ; Play Instrument #1 for half a second. i 1 0 0.5 ; Play Instrument #1 for half a second. i 1 1 0.5 e </CsScore> </CsoundSynthesizer>
event, event_i, schedwhen, schedkwhen, schedkwhennamed, scoreline, scoreline_i
More information on this opcode: http://www.csounds.com/journal/issue15/phrase_loops.html , written by Jim Aikin