schedwhen — Adds a new score event.
schedwhen ktrigger, kinsnum, kwhen, kdur [, ip4] [, ip5] [...]
schedwhen ktrigger, "insname", kwhen, kdur [, ip4] [, ip5] [...]
kinsnum -- instrument number. Equivalent to p1 in a score i statement.
“insname” -- A string (in double-quotes) representing a named instrument.
ktrigger -- trigger value for new event
kwhen -- start time of the new event. Equivalent to p2 in a score i statement.
kdur -- duration of event. Equivalent to p3 in a score i statement.
schedwhen adds a new score event. The event is only scheduled when the k-rate value ktrigger is first non-zero. 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.
Warning | |
---|---|
Support for named instruments is broken in version 4.23 |
Here is an example of the schedwhen opcode. It uses the file schedwhen.csd.
Example 418. Example of the schedwhen 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 schedwhen.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> ; Initialize the global variables. sr = 44100 kr = 44100 ksmps = 1 nchnls = 1 ; Instrument #1 - oscillator with a high note. instr 1 ; Use the fourth p-field as the trigger. ktrigger = p4 kinsnum = 2 kwhen = 0 kdur = p3 ; Play Instrument #2 at the same time, if the trigger is set. schedwhen ktrigger, kinsnum, kwhen, kdur ; 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 ; p4 = trigger for Instrument #2 (when p4 > 0). ; Play Instrument #1 for half a second, trigger Instrument #2. i 1 0 0.5 1 ; Play Instrument #1 for half a second, no trigger. i 1 1 0.5 0 e </CsScore> </CsoundSynthesizer>