# Allow and disallow specify groups



## rolemay (Aug 6, 2015)

Hi guys,
im here again...
Somebody help me please...

how to allow and disallow specify multiples groups?
or where are the error in the example?
----------------------------------------------

on init 
make_perfview 
set_ui_height_px(100)

declare const $NUM_CATEGORIES := 6

declare $i

declare $cat1
declare $selected1

declare $cat2
declare $selected2

declare $cat3
declare $selected3

declare $cat4
declare $selected4

declare $cat5
declare $selected5

declare $cat6
declare $selected6

declare ui_menu $Category1
add_menu_item($Category1,"Square",0) 
add_menu_item($Category1,"Triangle",1) 
add_menu_item($Category1,"Saw",2)
add_menu_item($Category1,"FM",3)
add_menu_item($Category1,"WaveTable",4)
add_menu_item($Category1,"Sample",5)


declare ui_menu $Square
add_menu_item($Square,"Square Shape",0) 
add_menu_item($Square,"Square Detune",1) 
add_menu_item($Square,"Square Pulse Synched",2) 

declare ui_menu $Triangle
add_menu_item($Triangle,"Triangle Shape",0) 
add_menu_item($Triangle,"Triangle Detune",1)
add_menu_item($Triangle,"Triangle Pulse Synched",2)

declare ui_menu $Saw
add_menu_item($Saw,"Saw Shape",0) 
add_menu_item($Saw,"Saw Detune",1)
add_menu_item($Saw,"Saw Pulse Synched",2)

declare ui_menu $FM
add_menu_item($FM,"2-OP 1:1:1",0) 
add_menu_item($FM,"2-OP (FB+) 1:1:1",1)
add_menu_item($FM,"2-OP (FB+)1:2:1",2)

declare ui_menu $WaveTable
add_menu_item($WaveTable,"Organ 1",0) 
add_menu_item($WaveTable,"Organ 2",1)
add_menu_item($WaveTable,"Organ 3",2)

declare ui_menu $Sample
add_menu_item($Sample,"Soft Pad",0) 
add_menu_item($Sample,"Angel Fire Pad",1)
add_menu_item($Sample,"Motion Scape",2)


declare %ID1[$NUM_CATEGORIES] 
%ID1[0] := get_ui_id($Square) 
%ID1[1] := get_ui_id($Triangle) 
%ID1[2] := get_ui_id($Saw) 
%ID1[3] := get_ui_id($FM) 
%ID1[4] := get_ui_id($WaveTable) 
%ID1[5] := get_ui_id($Sample) 

move_control_px($Category1,250,2) 
move_control_px($Square,250,23) 
move_control_px($Triangle,250,23) 
move_control_px($Saw,250,23) 
move_control_px($FM,250,23) 
move_control_px($WaveTable,250,23) 
move_control_px($Sample,250,23) 



make_persistent($Category1) 
make_persistent($Square) 
make_persistent($Triangle) 
make_persistent($Saw)
make_persistent($FM) 
make_persistent($WaveTable) 
make_persistent($Sample)


make_persistent($selected1) 

read_persistent_var($Category1) 


$i := 0
while ($i < $NUM_CATEGORIES) 
if ($i = $Category1) 
set_control_par(%ID1[$i],$CONTROL_PAR_HIDE,$HIDE_PART_NOTHING) 
else 
set_control_par(%ID1[$i],$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL) 
end if 
inc($i) 
end while 

message ("") 
end on 

on ui_control ($Category1) 
$i := 0
while ($i < $NUM_CATEGORIES) 
if ($i = $Category1) 
set_control_par(%ID1[$i],$CONTROL_PAR_HIDE,$HIDE_PART_NOTHING) 
$cat1 := $i 
else 
set_control_par(%ID1[$i],$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL) 
end if 
inc($i) 
end while 

select ($cat1) 
case 0 
$selected1 := $Square
case 1 
$selected1 := $Triangle 
case 2 
$selected1 := $Saw
case 3 
$selected1 := $FM
case 4 
$selected1 := $WaveTable
case 5
$selected1 := $Sample
end select 
end on 


on ui_control ($Square) 
$selected1 := $Square 
end on

on ui_control ($Triangle) 
$selected1 := $Triangle 
end on 

on ui_control ($Saw) 
$selected1 := $Saw 
end on 

on ui_control ($FM) 
$selected1 := $FM 
end on 

on ui_control ($WaveTable) 
$selected1 := $WaveTable 
end on 

on ui_control ($Sample) 
$selected1 := $Sample
end on 

{------------on note operations------------}

on note 



if ($Square #-1)
disallow_group($ALL_GROUPS) 
allow_group(0)
allow_group(1)
allow_group(2)
end if

if ($Square #0)
disallow_group($ALL_GROUPS) 
allow_group(3)
allow_group(4)
end if

if ($Square #1)
disallow_group($ALL_GROUPS) 
allow_group(5)
allow_group(6)
allow_group(7)
end if



if ($Triangle #-1)
disallow_group($ALL_GROUPS) 
allow_group(8)
allow_group(9)
allow_group(10)
end if

if ($Triangle #0)
disallow_group($ALL_GROUPS) 
allow_group(11)
allow_group(12)
end if

if ($Triangle #1)
disallow_group($ALL_GROUPS) 
allow_group(13)
allow_group(14)
allow_group(15)
end if



if ($Saw #-1)
disallow_group($ALL_GROUPS) 
allow_group(16)
allow_group(17)
allow_group(18)
end if

if ($Saw #0)
disallow_group($ALL_GROUPS) 
allow_group(19)
allow_group(20)
end if

if ($Saw #1)
disallow_group($ALL_GROUPS) 
allow_group(21)
allow_group(22)
allow_group(23)
end if


end on
--------------------------------------
Thank you for your help!!!


----------



## Luca Capozzi (Aug 7, 2015)

you can use whatever value at the end of your add_menu_item commands. the simplest thing would be to store there your group IDs and simply recall them when needed. Let's say you are allowing one waveform from your category->sub-category:

declare $selected_group <--- here you'll store the group to be allowed

declare ui_menu $Square
add_menu_item($Square,"Square Shape",10)
add_menu_item($Square,"Square Detune",15)
add_menu_item($Square,"Square Pulse Synched",22)

10, 15 and 22 are the group IDs for those waveforms (I'm just using random numbers here, for the sake of the example). You'll store the selected group ID on each of your waveform callbacks

on ui_control $Square
$selected_group := $Square
end on

Then you'll have on you "on note" callback:

on note
disallow_group($ALL_GROUPS)
allow_group($selected_group)
end on

I also suggest you to check the KSP Reference Manual sections about how to hide menu entries. In this way you may declare only a couple of menus (one for the category and one for the sub-category) and show/hide menu items accordingly.

Cheers,
Luca


----------



## rolemay (Aug 10, 2015)

Ok. Thank you.
But, if i need allow 2 or more groups at one time? This is my main problem... Thanx


----------



## d.healey (Aug 10, 2015)

You can either write the allow_group() line multiple times with the different group numbers you want or you can use a loop


```
disallow_group($ALL_GROUPS)
allow_group(0)
allow_group(1)
allow_group(2)
```

or

```
disallow_group($ALL_GROUPS)
$i := 0
while $i < 3
    allow_group($i)
    inc($i)
end while
```


----------



## rolemay (Aug 10, 2015)

on note

on init

declare ui_menu $square
add_menu_item ($square,"none",-1)
add_menu_item ($square,"Shape",0)
add_menu_item ($square,"Detune",1)
add_menu_item ($square,"Pulse Synched",2)



if ($square # -1)
disallow_group($ALL_GROUPS)
end if

if ($square # 0)
disallow_group($ALL_GROUPS)
allow_group(0)
allow_group(1)
allow_group(2)
end if

if ($square # 1)
disallow_group($ALL_GROUPS)
allow_group(3)
allow_group(4)
end if

if ($square # 2)
disallow_group($ALL_GROUPS)
allow_group(5)
allow_group(6)
allow_group(7)
end if

end on


---------------------------------------
Is no working for me... i don't know more how to do...
do you have some idea? where are my fail?


----------



## d.healey (Aug 10, 2015)

you have on init inside on note and only one end on


----------



## rolemay (Aug 10, 2015)

ok, i have this script working now. But, a detail:
The last if command is permanently set and no change more. Why?


----------



## d.healey (Aug 10, 2015)

You only need one disallow_group() command, put it before all your if statements. Also you should use a select rather than several if statements. Your if isn't working as you expect because you are saying if square is not 2, so what will happen if it is 2?


----------



## rolemay (Aug 11, 2015)

Ok!!! Thank you very much, and thank you for your patience.


----------



## d.healey (Aug 11, 2015)

no worries, let me know how you get on


----------



## Calg545 (Mar 24, 2022)

Hi, I wondering if i could get some advice, so im using this code, works a treat and does what I need however I decided to make an instrument in just one tab in kontakt and made the GUI bigger to accomodate this.
Since adding the Kontakt ARP to this code when I add the "on note section" it comes up with an error which I believe might be something to do with the Kontakt ARP code but for the life of me I can't figure out where to put it, I noted an "on note" section in the ARP script and it saved it but it didn't work an thats the end of where my skill lies sadly. How would I write it in or where can it be placed?

Thanks 

Cal

`declare ui_menu $Groups
add_menu_item($Groups,"Guitar",0)
add_menu_item($Groups,"Reverse Guitar",1)
make_persistent($Groups)
declare $GroupsId
$GroupsId := get_ui_id($Groups)
set_control_par_str($GroupsId, $CONTROL_PAR_PICTURE, "Blank3")
set_control_par ($GroupsId,$CONTROL_PAR_POS_X,290)
set_control_par ($GroupsId,$CONTROL_PAR_POS_Y,50)
set_control_par ($GroupsId,$CONTROL_PAR_TEXTPOS_Y,50)
set_control_par($GroupsId,$CONTROL_PAR_MOUSE_BEHAVIOUR,-500)
{on note
disallow_group($ALL_GROUPS)
allow_group($Groups)
end on}`


----------

