Comments on: KSP Scripting (NI Kontakt) :: BASICS :: Callbacks & Basic Structure https://blog.yummybeats.com/ksp-kontakt-scripting/ksp-scripting-ni-kontakt-basics-3-scripting-basics-structure/ Kontakt Scripting Tutorials (KSP), Free Massive Presets, Mixing Tips Sun, 12 Apr 2026 02:22:49 +0000 hourly 1 https://wordpress.org/?v=7.1.3 By: Dave https://blog.yummybeats.com/ksp-kontakt-scripting/ksp-scripting-ni-kontakt-basics-3-scripting-basics-structure/comment-page-1/#comment-9092 Thu, 11 Jun 2020 15:51:23 +0000 http://blog.yummybeats.com/?p=1045#comment-9092 In reply to YummyBeats.

HA! Well at least its fun….So, I haven’t tried your solution yet (stuck at day job) but this is exactly what I was thinking to try when I got home. Disallow groups at the start of the on note and then just enable after.

Perfect. Thanks again!!!! Will try out your code when I get home.

]]>
By: YummyBeats https://blog.yummybeats.com/ksp-kontakt-scripting/ksp-scripting-ni-kontakt-basics-3-scripting-basics-structure/comment-page-1/#comment-9091 Thu, 11 Jun 2020 14:25:06 +0000 http://blog.yummybeats.com/?p=1045#comment-9091 In reply to Dave.

Yeah KSP often means “find a workaround” 🙂

But try this, I cleaned up the code a lot and modified it to your needs. Only one group is playing at the same time now.

Cold Keys and loops are not required here which also saves some lines of code.

on init
	{SETTINGS}
		declare const $NUMBER_OF_GROUPS := 5	
		declare $active_group := 0 { set to -1 if no group should be active on init }
	
	{GLOBAL VARS}
		declare %hot_key[$NUMBER_OF_GROUPS]
		declare $i

	{ set midi note numbers for enabling keys => C1, D1, E1, F1, G1 }
		%hot_key[0] := 36
		%hot_key[1] := 38
		%hot_key[2] := 40
		%hot_key[3] := 41
		%hot_key[4] := 43

	 {set key color}
	 	$i := 0
	 	while ($i < $NUMBER_OF_GROUPS)
	 		set_key_color(%hot_key[$i], $KEY_COLOR_RED)
	 		inc($i)
	 	end while
end on

on note
	disallow_group($ALL_GROUPS)

	{ get current allowed group }
		if(search(%hot_key, $EVENT_NOTE) # -1)
			$active_group := search(%hot_key, $EVENT_NOTE)
		end if

	message($active_group) {console output}
	allow_group($active_group)
end on
]]>
By: Dave https://blog.yummybeats.com/ksp-kontakt-scripting/ksp-scripting-ni-kontakt-basics-3-scripting-basics-structure/comment-page-1/#comment-9089 Thu, 11 Jun 2020 10:20:35 +0000 http://blog.yummybeats.com/?p=1045#comment-9089 In reply to YummyBeats.

Thanks you so much! This example works.

Seems a bit wild to me that loading a group on init requires this much code but I suppose that’s Kontakt for you. lol

Now all I have to do is figure out how to layer in disallow groups because I dont want them to be layered but only one group active at a time. Cheers.

]]>
By: YummyBeats https://blog.yummybeats.com/ksp-kontakt-scripting/ksp-scripting-ni-kontakt-basics-3-scripting-basics-structure/comment-page-1/#comment-9088 Wed, 10 Jun 2020 06:40:23 +0000 http://blog.yummybeats.com/?p=1045#comment-9088 In reply to Dave.

You can do this via a status array since the allow_group command is only allowed inside the on note callback.

Try this. C1,D1,E1 enables group 0,1,2 where F1,G1,A1 disables them again.

Edit: sorry I missed the important part. I’ve updated the script. You can set a default active group now inside the on init



Note: This will layer all activated groups

on init
	{SETTINGS}
		declare const $NUMBER_OF_GROUPS := 3	
		declare $active_group := 0 { set to -1 if no group should be active on init }
	
	{GLOBAL VARS}
		declare %allowed_groups[$NUMBER_OF_GROUPS]
		declare %hot_key[$NUMBER_OF_GROUPS]
		declare %cold_key[$NUMBER_OF_GROUPS]
		declare $i

	{ set midi note numbers for enabling keys C1, D1, E1 }
		%hot_key[0] := 36
		%hot_key[1] := 38
		%hot_key[2] := 40

	{ set midi note numbers for disbaling keys F1, G1, A1 }
		%cold_key[0] := 41
		%cold_key[1] := 43
		%cold_key[2] := 45

	 {set key color hot & cold}
	 	$i := 0
	 	while ($i < $NUMBER_OF_GROUPS)
	 		set_key_color(%hot_key[$i], $KEY_COLOR_RED)
	 		set_key_color(%cold_key[$i], $KEY_COLOR_BLUE)
	 		inc($i)
	 	end while

	{ deactivate all groups }
		$i:=0
		while ($i < $NUMBER_OF_GROUPS)
			%allowed_groups[$i] := 0
			inc($i)
		end while
end on

on note
	disallow_group($ALL_GROUPS)
	message("")

	{activate group by key}
		$i := 0
		while ($i < $NUMBER_OF_GROUPS)
			if ($EVENT_NOTE = %hot_key[$i])
				%allowed_groups[$i] := 1
				message("group " & $i & " enabled")
				$i := $NUMBER_OF_GROUPS {breaks the while loop}
			end if
			inc($i)
		end while

	{ activate group by default}
		if ($active_group # -1)
			%allowed_groups[$active_group] := 1
		end if

	{ deactivate group by key}
		$i := 0
		while ($i < $NUMBER_OF_GROUPS)
			if ($EVENT_NOTE = %cold_key[$i])
				%allowed_groups[$i] := 0
				message("group " & $i & " disabled")
				$i := $NUMBER_OF_GROUPS {breaks the while loop}
			end if
			inc($i)
		end while

	{ only allow group when %allowed_groups[this] = 1 }
		$i := 0
		while($i < $NUMBER_OF_GROUPS)
			if(%allowed_groups[$i] = 1)
				allow_group($i)
			end if
			inc($i)
		end while
end on
]]>
By: Dave https://blog.yummybeats.com/ksp-kontakt-scripting/ksp-scripting-ni-kontakt-basics-3-scripting-basics-structure/comment-page-1/#comment-9087 Wed, 10 Jun 2020 02:17:47 +0000 http://blog.yummybeats.com/?p=1045#comment-9087 Is there a way to load a group in the on init callback?

I have made an instrument with 5 groups.

For each group in the group editor I have set Group Starts: on key “if key is between” and provided a single key for each group

When I load up my instrument no group of samples will play until I press one of the keys that I have specified in the group start settings.

What I would like to do is have one group available to be played when load the instrument.

I cant seem to find a way to do it via the on init function. Am I missing something obvious?

]]>
By: Serge https://blog.yummybeats.com/ksp-kontakt-scripting/ksp-scripting-ni-kontakt-basics-3-scripting-basics-structure/comment-page-1/#comment-9036 Fri, 03 Jan 2020 13:30:57 +0000 http://blog.yummybeats.com/?p=1045#comment-9036 In reply to YummyBeats.

Hello!
Thanks a lot for Your feedback. Your proposal has been tested today with both knobs & sliders versions, working fine. Especially useful, if some earlier programmed buttons can’t be learnt by soft.
NOTA => please, take into account, that while using the “select()…” function, several cases/situations can be appointed to the same one slider.
Big thanks once again, wish You all the best!
03/01/2020
Serge.

]]>