# Turnoff/turnoff2 not affecting events in their release state?

**URL:** <https://forum.csound.com/t/turnoff-turnoff2-not-affecting-events-in-their-release-state/351>\
**Category:** General\
**Created:** [May 20, 2021, 9:22pm UTC](https://forum.csound.com/t/turnoff-turnoff2-not-affecting-events-in-their-release-state/351 "2021-05-20T21:22:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![fellusive](https://forum.csound.com/user_avatar/forum.csound.com/fellusive/32/59_2.png) [@fellusive](https://forum.csound.com/u/fellusive)\
**Post date:** [May 20, 2021, 9:22pm UTC](https://forum.csound.com/t/turnoff-turnoff2-not-affecting-events-in-their-release-state/351/1 "2021-05-20T21:22:26Z")

</div>

In a MIDI instrument I’m working on, I’ve been trying to implement a “kill button” of sorts that terminates any notes that are currently being played. I’ve figured that this effect would be useful to have when I’m initializing a patch or switching through presets. While using `turnoff`/`turnoff2` to attempt to do this, I’ve found that events are only turned off if they are currently being sustained as the “button” is pressed. If I set notes to have a long release, and I press the terminate button during the release state of a note, `turnoff` and `turnoff2` have no effect, and the note keeps “releasing”. Why is this the case, and is there a way to turn off events that are in their release state?

Here is some code for reference. I’m using Cabbage to create my instrument, so the Cabbage widgets are what any of the `chnget`s are reading from.

Using `turnoff2` in a separate, always-running instr to try to turn off any events in a MIDI-receiving instr:

```
   gkinit chnget "Init" 
       if (changed2(gkinit) == 1) then
       
            event "i", 1003, 0, .1 ;call instr that initializes all widgets
            turnoff2 10, 8, 0.02 ;attempt to turn off all instances of MIDI-receiving instr
            
       endif

```

and using `turnoff` within the MIDI-receiving instr itself:

```
   gkinit chnget "Init" 
   if (changed2(gkinit) == 1) then
   
        event "i", 1003, 0, .1 ;call instr that initializes all widgets
        turnoff ;turn off current instrument (MIDI instr)
        
   endif 

```

Both of these methods only terminate notes that are being sustained (by my fingers on the controller), and any notes in their release state are ignored.

---

<div class="post-metadata">

**Author:** ![rory](https://forum.csound.com/user_avatar/forum.csound.com/rory/32/7_2.png) [@rory](https://forum.csound.com/u/rory)\
**Post date:** [May 21, 2021, 8:03am UTC](https://forum.csound.com/t/turnoff-turnoff2-not-affecting-events-in-their-release-state/351/2 "2021-05-21T08:03:24Z")

</div>

I was also surprised this doesn’t work. I thought `turnoff` was the great destroyer of instances. Anyhow have any ideas?

---

<div class="post-metadata">

**Author:** ![joachim](https://forum.csound.com/letter_avatar_proxy/v4/letter/j/a87d85/32.png) [@joachim](https://forum.csound.com/u/joachim)\
**Post date:** [May 21, 2021, 10:22am UTC](https://forum.csound.com/t/turnoff-turnoff2-not-affecting-events-in-their-release-state/351/3 "2021-05-21T10:22:14Z")

</div>

this works for me:

instr 1  
aSound poscil .2, 400  
aOut linenr aSound, .1, 2, .1  
out aOut, aOut  
if release()==1 then  
printks “release\n”, 1  
turnoff2 1, 0, 0  
endif  
endin  
schedule(1,0,1)

to use turnoff instead of turnoff2 is indeed not working … interesting  
…

```
j
```

---

<div class="post-metadata">

**Author:** ![rory](https://forum.csound.com/user_avatar/forum.csound.com/rory/32/7_2.png) [@rory](https://forum.csound.com/u/rory)\
**Post date:** [May 21, 2021, 6:04pm UTC](https://forum.csound.com/t/turnoff-turnoff2-not-affecting-events-in-their-release-state/351/4 "2021-05-21T18:04:18Z")

</div>

Thanks @joachim. That’s interesting. I didn’t try with `turnoff2` because one would need to manage the instances then. But in this case @fellusive is looking to kill all instances, so this works well. Using channels is looks like this:

```
instr 1
    aSound poscil .2, random:i(200, 1000)
    aOut madsr .1, .1, .5, 5
    out aSound*aOut, aSound*aOut
    if changed2:k(chnget:k("button")) == 1 then
        turnoff2 1, 0, 0
    endif
endin 

```

Thanks!

---

<div class="post-metadata">

**Author:** ![fellusive](https://forum.csound.com/user_avatar/forum.csound.com/fellusive/32/59_2.png) [@fellusive](https://forum.csound.com/u/fellusive)\
**Post date:** [May 21, 2021, 9:02pm UTC](https://forum.csound.com/t/turnoff-turnoff2-not-affecting-events-in-their-release-state/351/5 "2021-05-21T21:02:19Z")

</div>

Thanks for the examples @joachim and @rory . Just tried this method of using `turnoff2` within the MIDI instr itself and it works for me too! Having the `krelease` argument set to 0 seems to be important (at least in my instrument, not sure if this is a universal thing) because any value greater than 0 causes the released notes to be unaffected yet again, accompanied with a bunch of clicks.

---

<div class="post-metadata">

**Author:** ![ReinerZ](https://forum.csound.com/letter_avatar_proxy/v4/letter/r/eb9ed0/32.png) [@ReinerZ](https://forum.csound.com/u/ReinerZ)\
**Post date:** [January 4, 2025, 8:25am UTC](https://forum.csound.com/t/turnoff-turnoff2-not-affecting-events-in-their-release-state/351/6 "2025-01-04T08:25:19Z")

</div>

Hi Rory,

Happy New Year and nice to see you on this forum too.

I was exactly looking for this, a way to turn off an instrument without completing the release phase. I overlooked that `turnoff2` has this option. But now I have another problem: Playing chords, if one instance decides to turn itself off it also turns off the other instances. I have a vague understanding that `turnoff2 kinst, 8, 0` should do the trick with a fractional `kinst `. But how do I get this fractional value within the instance? In principle, it should work like in the example from the floss manual, EXAMPLE 07B04\_MidiMultiTrigg.csd. But do I really need this ‘subinstrument trick’?

---

<div class="post-metadata">

**Author:** ![joachim](https://forum.csound.com/letter_avatar_proxy/v4/letter/j/a87d85/32.png) [@joachim](https://forum.csound.com/u/joachim)\
**Post date:** [January 4, 2025, 10:43am UTC](https://forum.csound.com/t/turnoff-turnoff2-not-affecting-events-in-their-release-state/351/7 "2025-01-04T10:43:02Z")

</div>

i think you only _get_ the fractional number if you _call_ the instance  
with this number. if so, you should simply see it when you do print(p1).

otherwise you can perhaps build an own counter and connect one instance  
with this counter, like

giCountInstr1 init 1  
instr 1  
iInstance = giCountInstr1  
giCountInstr1 += 1  
…  
endin

ciao -  
joachim

---

<div class="post-metadata">

**Author:** ![ReinerZ](https://forum.csound.com/letter_avatar_proxy/v4/letter/r/eb9ed0/32.png) [@ReinerZ](https://forum.csound.com/u/ReinerZ)\
**Post date:** [January 7, 2025, 11:23am UTC](https://forum.csound.com/t/turnoff-turnoff2-not-affecting-events-in-their-release-state/351/8 "2025-01-07T11:23:51Z")

</div>

Hi Joachim, thanks for the helpful answer. I was clearly wrong in assuming that the fractional part is automatically assigned. So one needs some mechanism like in the floss manual example. But your counter maybe easier than the use of the note number in the example.

Still I wonder why `turnoff` does not have a parameter `krelease` as `turnoff2` has. Or `turnoff2` a default to act on the calling instance itself as `turnoff` has.

---

<div class="post-metadata">

**Author:** ![ReinerZ](https://forum.csound.com/letter_avatar_proxy/v4/letter/r/eb9ed0/32.png) [@ReinerZ](https://forum.csound.com/u/ReinerZ)\
**Post date:** [January 7, 2025, 11:26am UTC](https://forum.csound.com/t/turnoff-turnoff2-not-affecting-events-in-their-release-state/351/9 "2025-01-07T11:26:20Z")

</div>

PS: Is there some suggested place in the forum for this as a feature request?

---

<div class="post-metadata">

**Author:** ![rory](https://forum.csound.com/user_avatar/forum.csound.com/rory/32/7_2.png) [@rory](https://forum.csound.com/u/rory)\
**Post date:** [January 7, 2025, 12:55pm UTC](https://forum.csound.com/t/turnoff-turnoff2-not-affecting-events-in-their-release-state/351/10 "2025-01-07T12:55:54Z")

</div>

> [@ReinerZ](#):
>
> Still I wonder why `turnoff` does not have a parameter `krelease` as `turnoff2` has. Or `turnoff2` a default to act on the calling instance itself as `turnoff` has.

`turnoff2` came after `turnoff`, so that explains the first part of your question. With regards to the second part of your question, why would `turnoff2` need this functionality when it’s already there in `turnoff`. And adding a default behaviour after the fact would potentially break older orchestras.

In general I tend to use `turnoff` in all cases, and manage the instances myself. I make sure all instances have a fractional part, and if I need to kill an instance of an instrument I set a kill flag via a channel. I think Csound7 might have some better mechanism for destroying instances.
