turnoff2
Prev | Orchestra Opcodes and Operators | Next

## turnoff2

turnoff2 — Turn off instance(s) of other instruments at performance time.

## Description

Turn off instance(s) of other instruments at performance time.

## Syntax

    turnoff2 kinsno, kmode, krelease

## 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

The following example uses the turnoff2 opcode, s written by Lou Cohen..

Example 1087. Example of the turnoff2 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
    -odac     ;;;realtime audio out
    ;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
    ; For Non-realtime ouput leave only the line below:
    ; -o sin.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    sr        =          48000    ;samples per second for sound
    kr        =        4800
    nchnls    =        1
    0dbfs    =        32767

    gisine    ftgen    1, 0, 131073, 9, 1, 1, 0                ;single sine tone

    ;-----------------------------------------
    instr 2 ;start
        ktrigger        init        0
        if (ktrigger = 0) then
            kMultiple    =    1.1
            kHz            =    440
            kAmp            =    (0dbfs/10)
    ;startup four instances of instrument 200
            event    "i", 200, 0, 3000, kAmp, kHz
            kAmp    =    kAmp * 0.75
            kHz    =    kHz * kMultiple

            event    "i", 200, 0, 3000, kAmp, kHz
            kAmp    =    kAmp * 0.75
            kHz    =    kHz * kMultiple

            event    "i", 200, 0, 3000, kAmp, kHz
            kAmp    =    kAmp * 0.75
            kHz    =    kHz * kMultiple

            event    "i", 200, 0, 3000, kAmp, kHz
            kAmp    =    kAmp * 0.75
            kHz    =    kHz * kMultiple
            ktrigger        =    1
        endif
    endin
    ;---------------------------------------------
    instr 3 ;after 10 seconds, turn off the instruments
        ktrigger init 1
       if (ktrigger==1) then
            turnoff2 200, 1, 1    ;turn off must recently started instrument instance
            kactive active 200    ;find out how many are still active
            printk2 kactive       ;print mainly to show progress

            turnoff2    200, 0, 1    ;turn off all the rest of the instruments
            kactive    active 200    ;find out how many are still active
            printk2    kactive, 10    ;print to show progress
    endif
    endin
    ;----------------------------------------------------
    instr 200 ;play the tone
    kEnv    linen    1, 0.1, p3, 0.1
    ar      oscil    kEnv*p4, p5, 1
            out      ar
            print    p4, p5

    endin
    </CsInstruments>
    <CsScore>

    i2 0 0.1
    i3 10 0.1
    </CsScore>

    </CsoundSynthesizer>

## See Also

turnoff

## Credits

Author: Istvan Varga
2005

New in Csound 5.00

Prev | Up | Next
turnoff | Home | turnon