I'm creating a script on Kontakt 4 that works with a keyswitch (C0 = midi note 24) which turn ON and OFF also the instrument volume slider and remembers its value when is reactivated.
So far, when I'd achived half of this:
Pressing the C0 note and it turns ON and OFF without problem. I can play notes on mode ON and if I turn it OFF, it remembers the volume level when its ON again.
The problem is that if I play midi notes when the switch is OFF; if I press the C0 for turn it ON again, it just doesn't, the volume stays OFF (-oo).
Here is the script:
Code: Select all
on init
message("")
declare const $KEY_SWITCH := 24 { MIDI note C0 }
declare $volume { here is stored the instrument's volume before its switched OFF}
declare ui_switch $mute
set_key_color($KEY_SWITCH, $KEY_COLOR_RED) { Set key button to color red }
end on
on note
if ($EVENT_NOTE = $KEY_SWITCH) { if the incoming note is the same note than KEY_SWITCH (24 = C0)... }
$mute := 1-$mute {...we gonna toggle button }
end if
if ($mute = 1) { if the switch is ON }
$volume := get_engine_par($ENGINE_PAR_VOLUME, -1, -1, -1) { the instrument volume is saved before is changed... }
set_engine_par($ENGINE_PAR_VOLUME, 0, -1, -1, -1) { ...and the switch is turned OFF }
ignore_event($EVENT_ID) { we gonna ignore any incoming midi NOTE }
else { otherwise, if it's OFF, we gonna turn it ON }
set_engine_par($ENGINE_PAR_VOLUME, $volume, -1, -1, -1) { instead of set it to zero, its restored to the value stored before changed }
end if
end on
Cheers