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.
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 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.
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’?
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.
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.