insno
-- instrument to be turned off (can be fractional) if zero or negative, no instrument is turned off
imode -- sum of the following values:
0, 1, or 2: turn off all instances (0), oldest only (1), or newest only (2)
4: only turn off notes with exactly matching (fractional) instrument number, rather than ignoring fractional part
8: only turn off notes with indefinite duration (p3 < 0 or MIDI)
irelease -- if non-zero, the turned off instances are allowed to release, otherwise are deactivated immediately (possibly resulting in clicks)
Performance
kinsno
-- instrument to be turned off (can be fractional) if zero or negative, no instrument is turned off
kmode -- sum of the following values:
0, 1, or 2: turn off all instances (0), oldest only (1), or newest only (2)
4: only turn off notes with exactly matching (fractional) instrument number, rather than ignoring fractional part
8: only turn off notes with indefinite duration (p3 < 0 or MIDI)
krelease -- if non-zero, the turned off instances are allowed to release, otherwise are deactivated immediately (possibly resulting in clicks)
Note
As a rule of thumb, you should turn off instruments with a higher instrument number than the one where turnoff is called, as doing otherwise might cause initialization issues.
Examples
Here is an example of the turnoff2 opcode. It uses the file turnoff2-modern.csd.
<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform-odac ;;;realtime audio out;-iadc ;;;uncomment -iadc if realtime audio input is needed too; For Non-realtime ouput leave only the line below:; -o turnoff2.wav -W ;;; for file output any platform</CsOptions><CsInstruments>sr=44100;samples per second for soundksmps=32nchnls=20dbfs=1; example by Lou Cohensine@global:i=ftgen(1,0,131073,9,1,1,0);single sine tone;-----------------------------------------instr2;startTrigger:k=init(0)ifTrigger==0thenMultiple:k=1.1Hz:k=440Amp:k=(0dbfs/10);startup four instances of instrument 200event("i",200,0,3000,Amp,Hz)Amp*=0.75Hz*=Multipleevent("i",200,0,3000,Amp,Hz)Amp*=0.75Hz*=Multipleevent("i",200,0,3000,Amp,Hz)Amp*=0.75Hz*=Multipleevent("i",200,0,3000,Amp,Hz)Amp*=0.75Hz*=MultipleTrigger=1endifendin;---------------------------------------------instr3;after 10 seconds, turn off the instrumentsTrigger:k=init(1)ifTrigger==1thenturnoff2(200,1,1);turn off most recently started instrument instanceActive:k=active(200);find out how many are still activeprintk2(Active);print mainly to show progressturnoff2(200,0,1);turn off all the rest of the instrumentsActive=active(200);find out how many are still activeprintk2(Active,10);print to show progressendifendin;----------------------------------------------------instr200;play the toneEnv:k=linen(1,0.1,p3,0.1)ar=oscil(Env*p4,p5,sine)out(ar,ar)print(p4,p5)endin</CsInstruments><CsScore>i200.1i3100.1</CsScore></CsoundSynthesizer>
Here is an example of the turnoff2 opcode. It uses the file turnoff2.csd.
<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform-odac ;;;realtime audio out;-iadc ;;;uncomment -iadc if realtime audio input is needed too; For Non-realtime ouput leave only the line below:; -o turnoff2.wav -W ;;; for file output any platform</CsOptions><CsInstruments>sr=44100;samples per second for soundksmps=32nchnls=20dbfs=1; example by Lou Cohengisineftgen1,0,131073,9,1,1,0;single sine tone;-----------------------------------------instr2;startktriggerinit0if(ktrigger=0)thenkMultiple=1.1kHz=440kAmp=(0dbfs/10);startup four instances of instrument 200event"i",200,0,3000,kAmp,kHzkAmp=kAmp*0.75kHz=kHz*kMultipleevent"i",200,0,3000,kAmp,kHzkAmp=kAmp*0.75kHz=kHz*kMultipleevent"i",200,0,3000,kAmp,kHzkAmp=kAmp*0.75kHz=kHz*kMultipleevent"i",200,0,3000,kAmp,kHzkAmp=kAmp*0.75kHz=kHz*kMultiplektrigger=1endifendin;---------------------------------------------instr3;after 10 seconds, turn off the instrumentsktriggerinit1if(ktrigger==1)thenturnoff2200,1,1;turn off most recently started instrument instancekactiveactive200;find out how many are still activeprintk2kactive;print mainly to show progressturnoff2200,0,1;turn off all the rest of the instrumentskactiveactive200;find out how many are still activeprintk2kactive,10;print to show progressendifendin;----------------------------------------------------instr200;play the tonekEnvlinen1,0.1,p3,0.1aroscilkEnv*p4,p5,1outsar,arprintp4,p5endin</CsInstruments><CsScore>i200.1i3100.1</CsScore></CsoundSynthesizer>