Turnoff/turnoff2 not affecting events in their release state?

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 chngets 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.

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

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

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!

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.