Kontakt 4 - Keyswitch that work along with instrument's volume slider

VST, AU, AAX, CLAP, etc. Plugin Virtual Instruments Discussion
Locked New Topic
RELATED
PRODUCTS
Kontakt

Post

Hi everybody !

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
Any help will be appreciated
Cheers

Post

Logic is a bit off... You should do something like this:

Code: Select all

on init
    declare const $KEY_SWITCH := 24

    declare ui_switch $mute

    declare $volume
    $volume := get_engine_par($ENGINE_PAR_VOLUME,-1,-1,-1)

    set_key_color($KEY_SWITCH,$KEY_COLOR_RED)

    message("")
end on

on note
    if ($EVENT_NOTE = $KEY_SWITCH)
        $mute := 1 - $mute
        set_engine_par($ENGINE_PAR_VOLUME,$volume * $mute,-1,-1,-1)
    end if
end on

on ui_update
    if (get_engine_par($ENGINE_PAR_VOLUME,-1,-1,-1) # $volume)
        $volume := get_engine_par($ENGINE_PAR_VOLUME,-1,-1,-1)
    end if
end on

on ui_control ($mute)
    set_engine_par($ENGINE_PAR_VOLUME,$volume * $mute,-1,-1,-1)
end on

And even cooler could be if it weren't a toggle keyswitch but a momentary one - so you would return the volume back to full on key release...

There's no need for any note ignoring if you're using that key only as a keyswitch and have no samples mapped on it.

Post

Thanks EvilDragon! Now I'll dissect your code and try to figure out how you did it!
I'm learning to script on Kontakt, and I got the idea and the script from here:
https://www.youtube.com/watch?v=ZCDyXty_yQM
I liked the idea of save CPU by avoid voice count suggested on the video, that why the note ignoring.
And yeah, I thought also in remove the toggle keyswitch!

Cheers from Canary Islands (IsPain)
Last edited by hellishvictor on Sun Feb 26, 2017 2:14 pm, edited 1 time in total.

Post

You can simply remove "ui_switch" from "declare ui_switch $mute" to remove the switch.

Post

Great, now I can to do it in both ways!

Is possible for inverse the behaviour of the button?
This is how is looking now:
sshot.jpg
but I'll like that when keyswitch is ON, the mute appear as OFF
You do not have the required permissions to view the files attached to this post.
Last edited by hellishvictor on Sun Feb 26, 2017 3:28 pm, edited 1 time in total.

Post

Sure, just do $volume * (1 - $mute) everywhere instead of $volume * $mute.

Post

That worked like a charm, brutal!

Now trying to make a version without the toggle option for the keyswitch (removing the "ui_switch" from "declare ui_switch $mute") I got this:
sshot-1.png
I removed that three lines and the error disappear, but still works as in toggle mode.
I guess that maybe I need to add it some kind of "on release" behaviour or something, but its ok, it's not really necessary for me.

Thanks for your help EvilDragon
You do not have the required permissions to view the files attached to this post.
Last edited by hellishvictor on Fri Mar 03, 2017 4:28 pm, edited 2 times in total.

Post

Yeah, you would need to add "on release" callback if you want to return the volume value to normal on release. Like this:

Code: Select all

on note
    if ($EVENT_NOTE = $KEY_SWITCH)
        set_engine_par($ENGINE_PAR_VOLUME,0,-1,-1,-1)
    end if
end on

on release
    if ($EVENT_NOTE = $KEY_SWITCH)
        set_engine_par($ENGINE_PAR_VOLUME,$volume,-1,-1,-1)
    end if
end on
And yes, remove the $mute callback in that case. In fact, you can remove the variable completely. :)

Post

:)

Locked

Return to “Instruments”