best way to kill all voices?
-
I'm using add/remove Modulators a lot in a project
What is the best way to kill all voices before adding/removing a modulator?
I use AllNotesOff but it could still be voices fading out -
@ulrik I've added a function to the
BackgroundTask
object that kills all voices and then calls a function on the sample loading thread. This logic is used by almost every heavyweight operation (loading sample maps, user presets, etc), and it figures out whether to execute the function synchronously or not (eg. if you call it from a user preset loading callback, it will be executed synchronously because all notes are already killed and it will be called from the sample loading thread already).const var bt = Engine.createBackgroundTask("MyTask"); bt.killVoicesAndCall(function() { Console.print("I'm on the sample loading thread"); // Uncomment this to verify that the stacktrace is on // the sample loading thread (only in Debug mode obviously) //Console.breakInDebugger(); });
Be aware that there is no thread synchronisation so if you are trying to access common data on another scripting callback you might end up with race conditions, but this might be a use case where using this construct makes sense.
-
@Christoph-Hart said in best way to kill all voices?:
This logic is used by almost every heavyweight operation (loading sample maps, user presets, etc)
Is this performed also if I dynamically change/remove/add a modulator on, effects etc?
And what about changing modulator in the MacroModulatorSource module, will it also kick in? -
Recently had to do this myself and took a moment to figure it out, hence,
leaving this additional example here.// Spawn a background task to hard-stop all voices const var bt = Engine.createBackgroundTask("KillAllVoicesTask"); // Call this to kill voices inline function killAllVoices() { bt.killVoicesAndCall(function() { // nothing }); }
-
@griffinboy Why have you put it in an inline function?
-
Probably because I'm a fool and I didn't get how to call it in the natural state