KONTAKT - Retrieve notes from a group

Sampler and Sampling discussion (techniques, tips and tricks, etc.)
Post Reply New Topic
RELATED
PRODUCTS
Kontakt Kontakt Player

Post

Hi everybody,

How can be retrieved all the notes that belong to a specific group and display them on the keyboard in cyan?
On the following script I try to retrieve the notes from group 2.

Code: Select all

on init
	declare $a
	while ($a < 128)
		if (%GROUPS_SELECTED[get_engine_par($EVENT_PAR_NOTE,$a,-1,-1)] = 2)
			set_key_color($a, $KEY_COLOR_CYAN)
		end if
		inc($a)
	end while
end on
Cheers

Post

I think %GROUPS_SELETCED array tells you which groups are selected for editing in edit mode, so you may be on a wrong track. Also $EVENT_PAR_NOTE is not engine parameter?
To discover the mapping you may need to play actual notes, send them to groups and examine if they triggered anything. I don't think that's possible in init callback.

Post

Thank you for your help Zombie Queen, you f**king rule! And yes, you're right; so far that is the only thing that I have achieved, which feels limited, since I'll like to create a button that when is ON display the notes of the specified group. With the following script created by me yesterday, the notes played that belong to group 1 turn to green, and to yellow the ones from the group 2. But they have to be played one by one to see them... it could be more cool if were shown the colors just with apply the script.

Code: Select all

on init
	declare $count
end on

on note
	$count := 0
	while ($count < num_elements(%GROUPS_AFFECTED))
		select (%GROUPS_AFFECTED[$count])
			case 1 {group 1}
				set_key_color($EVENT_NOTE, $KEY_COLOR_GREEN)
			case 2
				set_key_color($EVENT_NOTE, $KEY_COLOR_YELLOW)
		end select
		message(group_name(%GROUPS_AFFECTED[$count]) & " -> " & $EVENT_NOTE)
		inc($count)
	end while
end on

Post

I'd rather use a lookup array here that contains minimum and maximum keys for every group, then use that when coloring the keyboard... needs a bit of time to build it but is a more efficient solution in the long run.

Post

Yeah, but I think what you mean is in the case when you already know what keys belong to each group, which is not this case; I want to load a random instrument, lets say for example Timpani Hits.nki (from the NI factory content), and when is applied this script (or when pressing a button configured to do this task on it), it shows in green the keys that belongs to the group "timpani flams" and to yellow or cyan the ones that belongs to "timpani ruffs".

Post

I hear you. I don't know any other way than to make a loop which plays all notes on all groups and checks if they hit something. Something like this...

Code: Select all

on init
	declare %note_map[16*128] {16 = $max number of groups}
	declare $c
	declare $n
	declare $i
	declare $z
	
	declare ui_button $scan
	declare ui_button $group_1_color
	declare ui_button $group_2_color
	declare ui_button $group_3_color
end on

function set_keys_color
	$n := 128 * $i
	$c := 0
	while($c < 128)
		if(%note_map[$n + $c] =0)
			set_key_color($c,$KEY_COLOR_INACTIVE)
		else
			set_key_color($c,$z)
		end if
		inc($c)
	end while
end function

on ui_control ($group_1_color)
	$i := 0 {group number}
	$z := $KEY_COLOR_BLUE
	$group_2_color := 0
	$group_3_color := 0
	call set_keys_color
end on

on ui_control ($group_2_color)
	$i := 1
	$z := $KEY_COLOR_RED
	$group_1_color := 0
	$group_3_color := 0
	call set_keys_color
end on

on ui_control ($group_3_color)
	$i := 2
	$z := $KEY_COLOR_GREEN
	$group_1_color := 0
	$group_2_color := 0
	call set_keys_color
end on


on ui_control ($scan)
	fade_out($ALL_EVENTS,5000,1)
	
	$c := 0
	while ($c < $NUM_GROUPS) {scan all groups}
		$n := 0
		while($n < 128) {scan all notes}
			
			{wait for voices to fade out}
			while($PLAYED_VOICES_INST >0)
				wait(100)
			end while
			
			$i := play_note($n,1,0,5000)
			change_vol ($i,-1000000,0)
			set_event_par_arr($i,$EVENT_PAR_ALLOW_GROUP,0,$ALL_GROUPS)
			set_event_par_arr($i,$EVENT_PAR_ALLOW_GROUP,1,$c)
			
			wait(500)
			$z := get_event_par($i,$EVENT_PAR_ZONE_ID)
			if($z = -1)
				%note_map[$c *128 + $n] := 0
			else
				%note_map[$c *128 + $n] := 1
			end if
			fade_out($i,100,1)
			
			inc($n)
		end while
		inc($c)
	end while
	$scan := 0
end on
It seems to work on your Timpani example. So, you need to scan the groups first, before the coloring switches can work. Possibly there's a simpler way than to examine $EVENT_PAR_ZONE_ID, you may need to investigate.

Post

There's no simpler way than that. However, you could do it once, then store results in a lookup array and use that on successive inits...

Either way, it's a bit of an overkill to do IMHO :)

Post

Zombie Queen wrote: Tue Jun 11, 2019 5:00 pm I hear you. I don't know any other way than to make a loop which plays all notes on all groups and checks if they hit something. Something like this...

Code: Select all

on init
	declare %note_map[16*128] {16 = $max number of groups}
	declare $c
	declare $n
	declare $i
	declare $z
	
	declare ui_button $scan
	declare ui_button $group_1_color
	declare ui_button $group_2_color
	declare ui_button $group_3_color
end on

function set_keys_color
	$n := 128 * $i
	$c := 0
	while($c < 128)
		if(%note_map[$n + $c] =0)
			set_key_color($c,$KEY_COLOR_INACTIVE)
		else
			set_key_color($c,$z)
		end if
		inc($c)
	end while
end function

on ui_control ($group_1_color)
	$i := 0 {group number}
	$z := $KEY_COLOR_BLUE
	$group_2_color := 0
	$group_3_color := 0
	call set_keys_color
end on

on ui_control ($group_2_color)
	$i := 1
	$z := $KEY_COLOR_RED
	$group_1_color := 0
	$group_3_color := 0
	call set_keys_color
end on

on ui_control ($group_3_color)
	$i := 2
	$z := $KEY_COLOR_GREEN
	$group_1_color := 0
	$group_2_color := 0
	call set_keys_color
end on


on ui_control ($scan)
	fade_out($ALL_EVENTS,5000,1)
	
	$c := 0
	while ($c < $NUM_GROUPS) {scan all groups}
		$n := 0
		while($n < 128) {scan all notes}
			
			{wait for voices to fade out}
			while($PLAYED_VOICES_INST >0)
				wait(100)
			end while
			
			$i := play_note($n,1,0,5000)
			change_vol ($i,-1000000,0)
			set_event_par_arr($i,$EVENT_PAR_ALLOW_GROUP,0,$ALL_GROUPS)
			set_event_par_arr($i,$EVENT_PAR_ALLOW_GROUP,1,$c)
			
			wait(500)
			$z := get_event_par($i,$EVENT_PAR_ZONE_ID)
			if($z = -1)
				%note_map[$c *128 + $n] := 0
			else
				%note_map[$c *128 + $n] := 1
			end if
			fade_out($i,100,1)
			
			inc($n)
		end while
		inc($c)
	end while
	$scan := 0
end on
It seems to work on your Timpani example. So, you need to scan the groups first, before the coloring switches can work. Possibly there's a simpler way than to examine $EVENT_PAR_ZONE_ID, you may need to investigate.
OMFG, that's really awesome!! thank you for your time coding this and help me again, Zombie Queen! you f**king rule, definelly !
And so far, make a script related to the zones is something new for me... but first I gonna dissect your script, it's a masterpiece !

Post

Hi, I just want to mention that, dont' know why, but it doesn't work with "Choir Morph [a-e-i-o-u].nki" (from the NI factory content\choir\vowel morphs). I though that maybe it was related to that it use the AET filter, but is the same without it.

Post

In Choir Morphs, look at group editor, you have "solo group" button in, so only selected group will play and only one group will be scanned. Turn "solo group" off and it will work.

Post

Another thing that I've learned, thank you !

Post Reply

Return to “Samplers, Sampling & Sample Libraries”