Make an Array
-
Is it possible to make an array like this:
const var Keyswitches = [Message.getNoteNumber() == 47),
Message.getNoteNumber() == 48),
Message.getNoteNumber() == 50)];and if, in what callback do I declare it?
-
@ulrik That looks nasty. What are you trying to do?
-
@d-healey I'm trying to control several functions with an array of key switches , if Message.getNoteNumber() == 47) then, ignore midi events in MidiMuter1, enable RoutingMatrix1, make panel visible, etc...
I am able to get this to work using one (Message.getNoteNumber()) at the time, controlling several functions but it would spare me a lot of writing if it was possible to use all (Message.getNoteNumber()) in an array.
I guess I'm, as we in Sweden say "Helt ute och cyklar" (translated "completely outdoor biking") :)
-
Yes there‘s no way this snippet will compile no matter where you put it:
- you can‘t declare const variables in a callback
- you can‘t call Message.x() functions outside a callback.
In general it is bad practice to create and insert array elements in a MIDI callback and should be avoided at all costs. You have to create the array and preallocate elements using Array.reserve() in the initialisation. Then you can access and store things in the callbacks (or use one of the special object types like MidiList or MessageHolder if it suits your purpose).
-
Ah ok in this case create the array in onInit and use the indexOf() method.
But don‘t mix GUI and Audio stuff. This has severe performance implications. What you need to do is to define this array as global, do the UI stuff in your deferred interface script (call Synth.deferCallbacks(true);) and the keyswitch logic in each script processor of your modules.
-
@christoph-hart Ok, I think I understand a little bit, I will try to follow your suggestions. Thanks a lot!