active — Returns the number of active instances of an instrument.
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.
Here is a simple example of the active opcode. It uses the file active.csd.
Example 26. Simple example of the active 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 active.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> ; 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 </CsInstruments> <CsScore> ; 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 </CsScore> </CsoundSynthesizer>
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 file active_k.csd.
Example 27. Example of the active opcode at k-rate.
<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 active_k.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> ; 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 </CsInstruments> <CsScore> ; 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 </CsScore> </CsoundSynthesizer>
Its output should include lines like:
i2 1.00000 i2 2.00000