active

active --  Returns the number of active instances of an instrument.

Description

Returns the number of active instances of an instrument.

Syntax

ir active insnum

kr active kinsnum

Initialization

insnum -- number of the instrument to be reported

Performance

kinsnum -- number of the instrument to be reported

active returns the number of active instances of instrument number insnum/kinsnum. As of Csound4.17 the output is updated at k-rate (if input arg is k-rate), to allow running count of instr instances.

Examples

Here is a simple example of the active opcode. It uses the files active.orc and active.sco.

Example 1. Simple example of the active opcode.

/* active.orc */
/* Written by Kevin Conder */
; Initialize the global variables.
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1

; Instrument #1 - a noisy waveform.
instr 1
  ; Generate a really noisy waveform.
  anoisy rand 44100
  ; Turn down its amplitude.
  aoutput gain anoisy, 2500
  ; Send it to the output.
  out aoutput
endin

; Instrument #2 - counts active instruments.
instr 2
  ; Count the active instances of Instrument #1.
  icount active 1
  ; Print the number of active instances.
  print icount
endin
/* active.orc */
        
/* active.sco */
/* Written by Kevin Conder */
; Start the first instance of Instrument #1 at 0:00 seconds.
i 1 0.0 3.0

; Start the second instance of Instrument #1 at 0:015 seconds.
i 1 1.5 1.5

; Play Instrument #2 at 0:01 seconds, when we have only 
; one active instance of Instrument #1.
i 2 1.0 0.1

; Play Instrument #2 at 0:02 seconds, when we have 
; two active instances of Instrument #1.
i 2 2.0 0.1
e
/* active.sco */
        
Its output should include lines like this:
instr 2:  icount = 1.000
instr 2:  icount = 2.000
      

Here is a more advanced example of the active opcode. It displays the results of the active opcode at k-rate instead of i-rate. It uses the files active_k.orc and active_k.sco.

Example 2. Example of the active opcode at k-rate.

/* active_k.orc */
/* Written by Kevin Conder */
; Initialize the global variables.
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1

; Instrument #1 - a noisy waveform.
instr 1
  ; Generate a really noisy waveform.
  anoisy rand 44100
  ; Turn down its amplitude.
  aoutput gain anoisy, 2500
  ; Send it to the output.
  out aoutput
endin

; Instrument #2 - counts active instruments at k-rate.
instr 2
  ; Count the active instances of Instrument #1.
  kcount active 1
  ; Print the number of active instances.
  printk2 kcount
endin
/* active_k.orc */
        
/* active_k.sco */
/* Written by Kevin Conder */
; Start the first instance of Instrument #1 at 0:00 seconds.
i 1 0.0 3.0

; Start the second instance of Instrument #1 at 0:015 seconds.
i 1 1.5 1.5

; Play Instrument #2 at 0:01 seconds, when we have only 
; one active instance of Instrument #1.
i 2 1.0 0.1

; Play Instrument #2 at 0:02 seconds, when we have 
; two active instances of Instrument #1.
i 2 2.0 0.1
e
/* active_k.sco */
        
Its output should include lines like:
 i2     1.00000
 i2     2.00000
      

Credits

Author: John ffitch
University of Bath/Codemist Ltd.
Bath, UK
July, 1999

New in Csound version 3.57