Skip to content

isactive

Reports whether an instrument instance is active.

Syntax

active:b = isactive(voice)
active:B = isactive(voice)
active:b isactive voice
active:B isactive voice

Initialization and performance

voice is an Instr reference to an initialized instance.

The b output checks the state once at initialization. The B output checks it on every control cycle. Both return a boolean that you can use in an if statement.

An active instance returns true. Pausing it makes this result false. A note can remain active during its release tail, so use isreleasing to check for that stage.

isactive reads the state of an existing instance. It cannot tell whether an uninitialized or deleted reference is safe to use. In particular, do not query a reference returned by schedule before the scheduled note has started.

Examples

The example prints 1 while the voice runs, 0 while it is paused, then 1 when it resumes. The if statement converts the boolean to a number for printk2. It uses instance-controls.csd.

Read the active state of a voice
<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

getinstance, isreleasing, pause, Instrument definitions, instances and opcode objects

Credits

Author Victor Lazzarini.

New in Csound 7.