# Group manipulation



## stevemazzaro (May 16, 2011)

I'm trying to change specific group parameters with knobs/menus and I'm having a bit of trouble.

To start off, anyone have an idea why this won't work:



> change_pan(find_group("Group_1"), -1000, 0)



It works if I set the ID to $EVENT_ID, but I want to pan each group specifically depending on the menu setting.

Another issue I'm having is an easier way to allow specific groups:



> on init
> declare %five[5] := (1, 2, 3, 4, 5)
> declare ui_knobs $Number (0,10,1)
> end on
> ...



The problem with this is it's only allowing the first group instead of all 5 of them. Obviously I could just copy paste that code 5 times, but to do that for the amount groups I have would be an eyesore. Also; not absolutely necessary, but is there a way to make it so if you hold a note and change the knob, the groups allow/disallow in real time?

Thanks for your help, guys!


----------



## EvilDragon (May 17, 2011)

Why not use the group Pan controls? Every group has its own Pan control, which you can approach with $ENGINE_PAR_PAN engine parameter. Let's say you have a menu to choose a group to edit (with an entry to edit all groups), and basic controls for volume, pan and tune.


```
on init
	make_perfview

	declare $i

	declare ui_menu $Menu
	add_menu_item($Menu,"EDIT ALL GROUPS",-1)
	while ($i < $NUM_GROUPS)
		add_menu_item($Menu,"#" & $i + 1 & " - " & group_name($i),$i)
		inc($i)
	end while

	declare ui_knob $Volume (0,631000,1)
	declare ui_knob $Pan (0,1000000,1)
	declare ui_knob $Tune (0,1000000,1)

	set_knob_unit($Volume,$KNOB_UNIT_DB)
	set_knob_unit($Tune,$KNOB_UNIT_ST)

	set_knob_defval($Volume,500000)
	set_knob_defval($Pan,500000)
	set_knob_defval($Tune,500000)

	set_control_par(get_ui_id($Menu),$CONTROL_PAR_WIDTH,272)
	set_control_par(get_ui_id($Menu),$CONTROL_PAR_TEXT_ALIGNMENT,1)

	$Menu := 0
	$Volume := get_engine_par($ENGINE_PAR_VOLUME,$Menu,-1,-1)
	$Pan := get_engine_par($ENGINE_PAR_PAN,$Menu,-1,-1)
	$Tune := get_engine_par($ENGINE_PAR_TUNE,$Menu,-1,-1)

	set_knob_label($Volume,get_engine_par_disp($ENGINE_PAR_VOLUME,$Menu,-1,-1))
	set_knob_label($Pan,get_engine_par_disp($ENGINE_PAR_PAN,$Menu,-1,-1))
	set_knob_label($Tune,get_engine_par_disp($ENGINE_PAR_TUNE,$Menu,-1,-1))

	move_control_px($Menu,66,2)
	move_control($Volume,1,2)
	move_control($Pan,2,2)
	move_control($Tune,3,2)

	make_persistent($Menu)
	make_persistent($Volume)
	make_persistent($Pan)
	make_persistent($Tune)

	message("")
end on

on ui_control($Menu)
	if ($Menu # -1)
		$Volume := get_engine_par($ENGINE_PAR_VOLUME,$Menu,-1,-1)
		$Pan := get_engine_par($ENGINE_PAR_PAN,$Menu,-1,-1)
		$Tune := get_engine_par($ENGINE_PAR_TUNE,$Menu,-1,-1)

		set_knob_label($Volume,get_engine_par_disp($ENGINE_PAR_VOLUME,$Menu,-1,-1))
		set_knob_label($Pan,get_engine_par_disp($ENGINE_PAR_PAN,$Menu,-1,-1))
		set_knob_label($Tune,get_engine_par_disp($ENGINE_PAR_TUNE,$Menu,-1,-1))
	end if
end on

on ui_control ($Volume)
	if ($Menu # -1)
		set_engine_par($ENGINE_PAR_VOLUME,$Volume,$Menu,-1,-1)
	else
		$i := 0
		while ($i < $NUM_GROUPS)
			set_engine_par($ENGINE_PAR_VOLUME,$Volume,$i,-1,-1)
			inc($i)
		end while
	end if

	set_knob_label($Volume,get_engine_par_disp($ENGINE_PAR_VOLUME,$Menu,-1,-1))
end on

on ui_control ($Pan)
	if ($Menu # -1)
		set_engine_par($ENGINE_PAR_PAN,$Pan,$Menu,-1,-1)
	else
		$i := 0
		while ($i < $NUM_GROUPS)
			set_engine_par($ENGINE_PAR_PAN,$Pan,$i,-1,-1)
			inc($i)
		end while
	end if

	set_knob_label($Pan,get_engine_par_disp($ENGINE_PAR_PAN,$Menu,-1,-1))
end on

on ui_control ($Tune)
	if ($Menu # -1)
		set_engine_par($ENGINE_PAR_TUNE,$Tune,$Menu,-1,-1)
	else
		$i := 0
		while ($i < $NUM_GROUPS)
			set_engine_par($ENGINE_PAR_TUNE,$Tune,$i,-1,-1)
			inc($i)
		end while
	end if

	set_knob_label($Tune,get_engine_par_disp($ENGINE_PAR_TUNE,$Menu,-1,-1))
end on
```



And, to answer your question - your method doesn't work because change_pan is an event-based command, while find_group() function just returns the index number of a particularly named group (as it appears on Monitor->Groups tab) - this is completely unrelated to events, and that's why you cannot use find_group() as an event ID, which is actually needed for any of change_xyz() functions to work.


----------



## stevemazzaro (May 17, 2011)

Hey EvilDragon. Thanks for this! This would work, (and I'm sorry I didn't mention this earlier), but due to the amount of groups, I feel it would be too tedious to have the user change them, so I wanted to have the menu as "preset pannings". My problem is that I can't seem to change the absolute value of a group's pan without inserting some sort of adjustable parameter (knob, slider, etc.)

I tried using _get_engine_par and declaring a bunch of variables set to numbers (thinking that would be the pan #):



> On Init
> declare $100 := 100
> end On
> 
> ...



But that didn't seem to work. Why can't there just be a change_group_pan command? 

Also, any ideas on the quick group allowing?


----------



## EvilDragon (May 17, 2011)

get_engine_par is for getting the engine parameter value. set_engine_par is for setting the engine parameter TO a certain value.  Also, don't confuse engine parameter value with ACTUAL parameter value - engine parameter value will always be in range from 0 to 1000000, for EVERY knob accessible to KSP. If you want to display the actual value of a certain control in Kontakt (say, volume in dB), then you need to use get_engine_par_disp() - as you can see in my example above.

So, you need to do this:


```
set_engine_par($ENGINE_PAR_PAN,<value from 0 to 1000000>,<group index>,-1,-1)
```

for each group you want (first group has a group index of 0). For example, if you want to put group 5 to 25L, then you would write:


```
set_engine_par($ENGINE_PAR_PAN,375000,4,-1,-1)
```

because engine parameter value of 500000 is center. But not all engine parameters have linear distribution! Thankfully, panning is linear (one unit of panning is 5000 engine parameter units).

Please get very well acquainted with these two commands because they are important for a lot of things. KSP reference should help.



stevemazzaro @ 17.5.2011 said:


> Why can't there just be a change_group_pan command?



Because all "change" commands in KSP (change_note, change_vol, change_velo, change_pan, change_tune) are *NOT* group-based! They are EVENT based instead (per-note). And since you can already set panning as I explained above, it is not necessary to have the command which you've requested, as it would be redundant 



stevemazzaro @ 17.5.2011 said:


> Also, any ideas on the quick group allowing?



What would be "quick" for you? :lol:


----------



## EvilDragon (May 17, 2011)

Don't worry about CPU - that's all done very fast. You'd need to have a ridiculous amount of calculations in the note callback to bog down the note event stream.

You can use while loop for allowing groups:


```
$i := 0
while ($i < $Number)
    allow_group($i)
    inc($i)
end while
```


----------



## stevemazzaro (May 17, 2011)

You are brilliant. Thanks again, Evil.


----------

