As promised: Optimized using the shift operator as proposed by @dhj. Some checking before use in production is advised, because I cannot verify all of it.
HapaxInput : MidiInBlock
ScaleValue : Integer
EmVoice1 : PluginBlock
ScaleValue = 0
On NoteEvent(m : NoteMessage) from HapaxInput
thisNote : Integer = 0
thisNote = GetNoteNumber(m)
ScaleValue = ScaleValue or (1 << (thisNote % 12))
ScaleValue = ScaleValue and not (1 << (thisNote % 12))
if GetChannel(m) == 1
SetParameter(EmVoice1,18, ScaleValue *(1.0/4095.0))
I won’t come into the details of what you discussed here, but I think it could be a little bit more efficient to use On NoteOnEvent and On NoteOffEvent callbacks here (you always need both when you use one). So, you wouldn’t need to do all the variable declarations, assignments and tests you do here in the On NoteOnEvent callback.
Not a real concern. @David-san thinks it can be optimized by using a separate noteon and noteoff eventhandler, but there is some other code involved, so that could be in a function, but there is only a real benefit when gp internally is much more efficient in using separate eventhandlers than gp script is in doing If IsNoteOn(m)