Skip to content

unschedule

Removes the first matching queued note event.

Use it to cancel a note queued by schedule before the note starts.

Syntax

unschedule(instrument, iStart, iDuration[, ip4, ip5, ...])
unschedule instrument, iStart, iDuration[, ip4, ip5, ...]

Initialization

instrument is an instrument number, a name string or an InstrDef reference.

iStart is the queued event's stored start position in beats from the start of the current score section. It is not a delay from this call.

iDuration must match the event's stored duration. Positive durations use beats. At the default tempo of 60 beats per minute, beats and seconds have the same length.

ip4, ip5, ... must match the event's remaining p-fields, including strings. Supply every p-field in order. The number of arguments must also match.

unschedule runs once at initialization and returns no value. Numeric values must match exactly. If nothing matches, nothing happens.

Use unscheduleall to remove every matching event.

Only pending orchestra-generated note events are eligible. Active notes keep playing, and future notes written in the score stay in the score. Use turnoff2 to stop active notes.

When you queue a note at the start of a section at tempo 60, you can use the same start and duration values for both calls, as the example does. For notes queued later, repeating the original delay may fail to match the stored start position. Time conversions and rounding can also prevent an exact match.

Examples

The example queues duplicate notes, then cancels one copy of the 440 Hz note and both copies of the 660 Hz note. The 880 Hz note has a different p4, so it stays in the queue. You hear 440 Hz followed by 880 Hz.

It uses unschedule.csd.

Cancel matching queued notes
<CsoundSynthesizer>
<CsOptions>
-odac -d -m0
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 32
nchnls = 1
0dbfs = 1

instr Tone
  printf_i "Playing %g Hz\n", 1, p4
  aEnvelope linseg 0, 0.01, 0.1, p3 - 0.02, 0.1, 0.01, 0
  aTone poscil aEnvelope, p4
  out aTone
endin

instr 1
  ; Queue two identical notes. Remove one and leave the other to play.
  schedule("Tone", 0.5, 0.25, 440)
  schedule("Tone", 0.5, 0.25, 440)
  unschedule("Tone", 0.5, 0.25, 440)

  ; Remove both 660 Hz notes. The different 880 Hz note stays queued.
  schedule("Tone", 1, 0.25, 660)
  schedule("Tone", 1, 0.25, 660)
  schedule("Tone", 1, 0.25, 880)
  unscheduleall("Tone", 1, 0.25, 660)
endin
</CsInstruments>
<CsScore>
i 1 0 1.5
e
</CsScore>
</CsoundSynthesizer>

See also

unscheduleall, schedule, turnoff2, Instrument Invocation

Credits

Author Victor Lazzarini.

New in Csound 7.