Skip to content

pause

Pauses or resumes an instrument instance.

Syntax

pause(voice, kPause)
pause voice, kPause

Performance

voice is an Instr reference to an initialized instance.

kPause controls the instance on every control cycle. Zero enables performance. Any other value pauses it. A paused instance keeps its variables and opcode state, and isactive reports false.

Pausing skips the instance's performance code. It does not shift a scheduled note's end time or restart its envelopes. Resume only an instance that you paused and that is still available. pause does not restart a note that has ended.

This also works with manually performed instances. While paused, a call to perf skips the instance's performance code.

Examples

The tone pauses at 0.5 seconds and resumes at 1 second. The controller continues to update its frequency during the pause. It uses instance-controls.csd.

Pause and resume a tone
<CsoundSynthesizer>
<CsOptions>
-odac -d -m0
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 1
0dbfs = 1

instr Tone
  aTone poscil p4, p5
  out aTone
endin

instr 1
  voice:Instr = play(Tone, 0.1, 440)
  self:Instr = getinstance()
  running:b = isactive(self)
  if running then
    prints "Controller is active\n"
  endif

  kTime timeinsts
  ; Pause from half a second to one second, then resume.
  kPause = (kTime >= 0.5 && kTime < 1) ? 1 : 0
  pause(voice, kPause)

  activeNow:B = isactive(voice)
  if activeNow then
    kActive = 1
  else
    kActive = 0
  endif
  printk2 kActive

  ; The instance reads its frequency from p5 during performance.
  kFrequency line 440, p3, 660
  setp(voice, 5, kFrequency)
  kAmplitude linseg 0, 0.01, 0.1, p3 - 0.02, 0.1, 0.01, 0
  setp(voice, 4, kAmplitude)

  ; play has no duration argument. The controller owns its cleanup.
  delete(voice)
endin
</CsInstruments>
<CsScore>
i 1 0 1.5
e
</CsScore>
</CsoundSynthesizer>

See also

play, perf, isactive, turnoff, Instrument definitions, instances and opcode objects

Credits

Author Victor Lazzarini.

New in Csound 7.