schedkwhen

schedkwhen — Adds a new score event generated by a k-rate trigger.

Description

Adds a new score event generated by a k-rate trigger.

Syntax

schedkwhen ktrigger, kmintim, kmaxnum, kinsnum, kwhen, kdur \
      [, ip4] [, ip5] [...]
schedkwhen ktrigger, kmintim, kmaxnum, "insname", kwhen, kdur \
      [, ip4] [, ip5] [...]

Initialization

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

ip4, ip5, ... -- Equivalent to p4, p5, etc., in a score i statement

Performance

ktrigger -- triggers a new score event. If ktrigger = 0, no new event is triggered.

kmintim -- minimum time between generated events, in seconds. If kmintim <= 0, no time limit exists. If the kinsnum is negative (to turn off an instrument), this test is bypassed.

kmaxnum -- maximum number of simultaneous instances of instrument kinsnum allowed. If the number of existant instances of kinsnum is >= kmaxnum, no new event is generated. If kmaxnum is <= 0, it is not used to limit event generation. If the kinsnum is negative (to turn off an instrument), this test is bypassed.

kinsnum -- instrument number. Equivalent to p1 in a score i statement.

kwhen -- start time of the new event. Equivalent to p2 in a score i statement. Measured from the time of the triggering event. kwhen must be >= 0. If kwhen > 0, the instrument will not be initialized until the actual time when it should start performing.

kdur -- duration of event. Equivalent to p3 in a score i statement. If kdur = 0, the instrument will only do an initialization pass, with no performance. If kdur is negative, a held note is initiated. (See ihold and i statement.)

[Note] Note

While waiting for events to be triggered by schedkwhen, the performance must be kept going, or Csound may quit if no score events are expected. To guarantee continued performance, an f0 statement may be used in the score.

[Note] Note

Note that the schedkwhen opcode cannot accept string p-fields. If you need to pass strings when instantiating an instrument, use the scoreline or scoreline_i opcode.

Examples

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

Example 939. Example of the schedkwhen 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 schedkwhen.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
  kmintim = 0
  kmaxnum = 2
  kinsnum = 2
  kwhen = 0
  kdur = 0.5

  ; Play Instrument #2 at the same time, if the trigger is set.
  schedkwhen ktrigger, kmintim, kmaxnum, 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, no trigger.
i 1 0 0.5 0
; Play Instrument #1 for half a second, trigger Instrument #2.
i 1 1 0.5 1
e


</CsScore>
</CsoundSynthesizer>


See also

event, event_i, schedule, schedwhen, schedkwhennamed, scoreline, scoreline_i

Credits

Author: Rasmus Ekman
EMS, Stockholm, Sweden

Example written by Kevin Conder.

New in Csound version 3.59