# How to allow or disallow many groups, with 2 menus ?



## jcnoel (Jan 29, 2012)

Hi,

First, I'm French, so my english is really bad ... :? 
But i try to explain you what is my problem.

I have a nki instrument with 74 groups. already, I did a script to allow or disallow some group, one by one. My script works well, but I have only 1 menu to select each group. So, if I want to "allow" the last group ( group n° 74 ) ... It's too long to access it !

So I want 2 menus : 
- The first menu " Category" ( with 8 category )

exemple ( only for 3 category ): 
Category 1 : Guitars
Category 2 : Pianos
Category 3 : Bass
etc .....

- The second menu " Groups" give me the groups for each categoy.
exemple :
If I select "Guitar" ( Category 1 ) the second menu offers me
Acoustic Guitar ( Group 1 )
Electric Guitar ( Group 2 )
Nylon Guitar ( Group 3 )
etc ...

But I Can't "allow" or "disallow" the differents groups ! With only 1 menu, the script works well, But I don't know how to do with 2 menus.

Here is my script that I do with 2 menus ( In fact, it's a light script with only 3 Category and 9 groups only for example ! Because the script is too long ! )


on init

message("")
declare $count

{***************** CATEGORIES *******************}

declare ui_menu $Category

declare ui_menu $Guitars
declare ui_menu $Pianos
declare ui_menu $Bass

declare %subcat_menu_id[3]
%subcat_menu_id[0] := get_ui_id($Guitars)
%subcat_menu_id[1] := get_ui_id($Pianos)
%subcat_menu_id[2] := get_ui_id($Bass)

add_menu_item($Category, "Acoustic Guitar", 0)
add_menu_item($Category, "Electric Guitar", 1)
add_menu_item($Category, "Nylon Guitar", 2)

$count := 0


{********************** GROUPS ************************}

declare $a
declare $b

{------------- GUITARS ------------------}

declare $Acoustic_Guitar := 0
declare $Electric_Guitar := 1
declare $Nylon_Guitar := 2

{------------- PIANOS ------------------}

declare $Acoustic_Piano := 3
declare $Electric_Piano_1 := 4
declare $Electric_Piano_2:= 5

{------------- BASS ------------------}

declare $Acoustic_Bass := 6
declare $Slap_Bass := 7
declare $Finger_Bass := 8


{********************** MENUS PRESETS ************************}


declare %Offset_Category[4] := (0,3,6,9)

declare !ir_type[9]
!ir_type[0] := "Acoustic Guitar "
!ir_type[1] := "Electric Guitar"
!ir_type[2] := "Nylon Guitar "

!ir_type[3] := "Acoustic Piano "
!ir_type[4] := "Electric Piano 1"
!ir_type[5] := "Electric Piano 2"

!ir_type[6] := "Acoustic Bass "
!ir_type[7] := "Slap Bass "
!ir_type[8] := "Finger Bass "

$count := 0
while ($count < 9)
if ($count < 3)
add_menu_item($Guitars,!ir_type[$count],$count)
else
if ($count < 6)
add_menu_item($Pianos,!ir_type[$count],$count)
else
if ($count < 9)
add_menu_item($Bass,!ir_type[$count],$count)
end if
end if
end if

inc ($count)
end while

make_persistent($Category)
make_persistent($Guitars)
make_persistent($Pianos)
make_persistent($Bass)

_read_persistent_var($Category)
_read_persistent_var($Guitars)
_read_persistent_var($Pianos)
_read_persistent_var($Bass)

$count := 0
while ($count < 3)

if ($count = $Category)
set_control_par(%subcat_menu_id[$count],$CONTROL_PAR_HIDE,$HIDE_PART_NOTHING)
else
set_control_par(%subcat_menu_id[$count],$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)
end if

inc ($count)
end while

end on


{**************** ALLOW GROUPS *******************}

on note


$a := 0
$b := 9
while($a <= $b) 
{ 1 }	disallow_group ($Acoustic_Guitar)
{ 2 }	disallow_group ($Electric_Guitar)
{ 3 }	disallow_group ($Nylon_Guitar)
{ 4 }	disallow_group ($Acoustic_Piano)
{ 5 }	disallow_group ($Electric_Piano_1)
{ 6 }	disallow_group ($Electric_Piano_2)
{ 7 }	disallow_group ($Acoustic_Bass)
{ 8 }	disallow_group ($Slap_Bass)
{ 9 }	disallow_group ($Finger_Bass)

inc($a)

end while 
{ 1 }	disallow_group ($Acoustic_Guitar)
{ 2 }	disallow_group ($Electric_Guitar)
{ 3 }	disallow_group ($Nylon_Guitar)
{ 4 }	disallow_group ($Acoustic_Piano)
{ 5 }	disallow_group ($Electric_Piano_1)
{ 6 }	disallow_group ($Electric_Piano_2)
{ 7 }	disallow_group ($Acoustic_Bass)
{ 8 }	disallow_group ($Slap_Bass)
{ 9 }	disallow_group ($Finger_Bass)


if ($Category = 1)
allow_group ($Acoustic_Guitar)
end if
if ($Category = 2)
allow_group ($Electric_Guitar)
end if
if ($Category = 3)
allow_group ($Nylon_Guitar)
end if
if ($Category = 4)
allow_group ($Acoustic_Piano)
end if
if ($Category = 5)
allow_group ($Electric_Piano_1)
end if
if ($Category = 6)
allow_group ($Electric_Piano_2)
end if
if ($Category = 7)
allow_group ($Acoustic_Bass)
end if
if ($Category = 8 )
allow_group ($Slap_Bass)
end if
if ($Category = 9)
allow_group ($Finger_Bass)
end if

end on

{********** CONTROL CATEGORY - GROUPS ******************}

on ui_control ($Category)

$count := 0
while ($count <3)

if ($count = $Category)
set_control_par(%subcat_menu_id[$count],$CONTROL_PAR_HIDE,$HIDE_PART_NOTHING)
else
set_control_par(%subcat_menu_id[$count],$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)
end if

inc ($count)
end while

end on



I know that is the script into the ***** ALLOW GROUPS ****
wich is wrong, but I don't know how to do to have a correct script with the 2 menus !
:cry: :cry: :cry: 

Can you help me, please ? ... And if you can give me the good script, it will be faboulous ! :lol: 

Thank You for your reponses.

jcnoel

PS I hope you understand me, and excuse me for my bad english !


----------



## Big Bob (Jan 30, 2012)

Hi jc,

Right now I don't have enough time to wade through all the details of your example code in order to see how you might modify it. However, I can suggest a few ideas you should be able to exploit to accomplish your objective.

First off, make a mapping array to 'linearize' the indexing of groups. For example, if you had only 3 categories and a maximum of say 10 sub types per category, you would have a maximum of 30 groups in the .nki. Using this example to illustrate the idea, populate an array so that indices 0..9 would contain the actual group numbers for the 10 instruments in category 0. Then put the actual group numbers for category 1 in the the array slots 10..19 and finally, put the actual group indices for category 2 in the mapping array slots 20..29.

Assume we name the category menu *CatMenu *and the specific instrument menu *SubMenu*. Of course I assume you are using K5 so you can dynamically rename the 10 specific instruments in *SubMenu* depending on which category you choose in the *CatMenu*. Further let's assume for simplicity that you build these menus so they return an index of 0..2 and 0..9 respectively.

Then the mechanism for enabling/disabling groups would look something like this:


```
on note

{ blah, blah, blah }

disallow($ALL_GROUPS)
allow_group(%Map[CatMenu*10+SubMenu])

{ blah, blah, blah }
```

Hopefully, this might point you in the right direction?

BTW Your English is very readable so you don't need to apologize for it.

Rejoice,

Bob


----------



## jcnoel (Jan 30, 2012)

Hi Bob,

Thank you for your reponse, but I'm desolate because I don't understand how to do.
I tried your suggestion, but all my tentatives don't work !!! :? 

In fact I have Kontakt 4 ( and no K5 )

Really, I have 74 groups. 
Each group = 1 sound ( electric guitar, synthe 1, synthe 2, ...)
I have 8 Category. Each category have between 7 to 16 groups ( a maximum )

I send you my script, but with only 3 Category and 9 Groups for example. 
( It's a "lite script" , because my really script will be too long to post in your forum )

What do I want ? 

When I want to play ( for example ) with the sound "Electric Guitar", first, I select the category ( guitar ), then I select in the second menu, my sound ( = the group ) "Electric Guitar".
At that moment, only the group "Electric Guitar" is "allowed" and all the others groups are "disallowed" ( muted )
But my script don't work.

I think it's the part of the script into the {****** ALLOW GROUPS *********} which is wrong, but I don' know how to do.

I'm not a expert in script, and there are a lot of things that I don't understand !
( And English is a little difficult for me )

I hope ( when you will have some time for me ) that you can tell me how to write the good script !!!  

Thanks

Rejoice

J.Claude


----------



## Big Bob (Jan 30, 2012)

Hi J.Claude,

I'm sorry that you didn't understand my suggestion. I took a quick look at your sample code and I find that it somewhat disagrees with your description. It looks to me as though you are declaring 4 menus not just 2. Apparently you intend to declare as many sub menus as you have categories and then intend to hide all but one submenu (based on your category selection). This is sort of the K4 counterpart of using K5's dynamic menus. 

My suggestion would still work except that you will have to set a submenu index from the 'active' submenu rather than just reading it from a 'one-and-only' submenu.

Let me flesh it out a little for you and then I'll post some illustrative code. Do you use Nils' Editor? If you do, I can just post an example without having to use all the $,%, etc. prefixes. If you don't use Nils' editor, I'll have to convert my code before I post it because I usually don't write code with the K4-required prefixes. 

Since I have to do this in-between a bunch of other things that I need to keep working on, it may take an hour or two before I can get back to you.

To be continued ...

Rejoice,

Bob


----------



## Big Bob (Jan 30, 2012)

I hope you aren't in a big hurry for this because I just took a more careful look at what I need to do before I can devote any time to this and it looks like I won't be able to get to this before tomorrow.

In the meantime, if anyone else wants to jump in here please feel free. However, if no one else rises to the occasion, I will post some illustrative code tomorrow morning (in the USA).

Rejoice,

Bob


----------



## jcnoel (Jan 30, 2012)

Hi Bob, 

Thank You very much. I will wait for you.
Don't worry for the time you need, for your future post !  

I don't move !!! :lol: 

Rejoice

J.Claude


----------



## mk282 (Jan 31, 2012)

Yes, in Kontakt 4 you will need one ui_menu for category selection, and x ui_menus for x categories you want to have. So, let's say you have in this example 10 groups that are spread out in 3 categories, first category 3 sounds, second category 2 sounds, third category 5 sounds. Let's also say that you named the groups according to the sound it plays. This is how I would do it:


```
on init
	make_perfview

	declare const $NUM_CATEGORIES := 3

	declare $i
	declare $cat
	declare $selected

	declare ui_menu $CatSel
	add_menu_item($CatSel,"Category 1",0)
	add_menu_item($CatSel,"Category 2",1)
	add_menu_item($CatSel,"Category 3",2)
	declare ui_menu $Cat1
	add_menu_item($Cat1,group_name(0),0)
	add_menu_item($Cat1,group_name(1),1)
	add_menu_item($Cat1,group_name(2),2)
	declare ui_menu $Cat2
	add_menu_item($Cat2,group_name(3),3)
	add_menu_item($Cat2,group_name(4),4)
	declare ui_menu $Cat3
	add_menu_item($Cat3,group_name(5),5)
	add_menu_item($Cat3,group_name(6),6)
	add_menu_item($Cat3,group_name(7),7)
	add_menu_item($Cat3,group_name(8),8)
	add_menu_item($Cat3,group_name(9),9)

	declare %ID[$NUM_CATEGORIES]
	%ID[0] := get_ui_id($Cat1)
	%ID[1] := get_ui_id($Cat2)
	%ID[2] := get_ui_id($Cat3)

	move_control_px($CatSel,250,2)
	move_control_px($Cat1,250,23)
	move_control_px($Cat2,250,23)
	move_control_px($Cat3,250,23)

	make_persistent($CatSel)
	make_persistent($Cat1)
	make_persistent($Cat2)
	make_persistent($Cat3)
	make_persistent($selected)

	read_persistent_var($CatSel)

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

	message ("")
end on


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

	select ($cat)
		case 0
			$selected := $Cat1
		case 1
			$selected := $Cat2
		case 2
			$selected := $Cat3
	end select
end on

on ui_control ($Cat1)
	$selected := $Cat1
end on

on ui_control ($Cat2)
	$selected := $Cat2
end on

on ui_control ($Cat3)
	$selected := $Cat3
end on


on note
	disallow_group($ALL_GROUPS)
	allow_group($selected)
end on
```


So, let me explain here what's happening. Variable $i is just a counter variable. Variable $selected saves the group index value of the group that is going to be played. Variable $cat just memorizes which category menu has been shown (important for setting the $selected variable to correct value when you select category, later on).

It is sad that we cannot add menu entries in a while loop, things would be a lot faster that way. Anyways, I hope you have your groups sorted exactly the way you want them to show up in the individual category menus (in my example, $Cat1, $Cat2, $Cat3). It is VERY IMPORTANT that the last value in add_menu_item command is the same as the value in group_name()! Otherwise things won't work as expected!

After that, I suggest you do the same thing I did and gather the UI IDs of the individual category menus ($Cat1, $Cat2, $Cat3...) in an array, so you can show and hide them real fast and simple, like I did.

It is very important that you use move_control_px() to set all category menus to the SAME POSITION.

In your version of the script, you will need to have case 0, case 1, case 2... case 7, because you have 8 categories. You'll figure it out, it's easy. This is needed so that $selected value gets set to correct value when you change the category, as I said above.

By using disallow_group($ALL_GROUPS) you save yourself a whole lot of lines!  And since we used a variable to save which group we're going to play, the "on note" callback is very short! 


I hope this helped!


----------



## Big Bob (Jan 31, 2012)

Hi jc,

I'm sorry for the delay but the forum was down this morning until just a short while ago.

I see MK has given you a nice example of how to do it already but, since I dashed some code off this morning before the forum came back, I'll just post it here since it will give you another slightly different example of how to accomplish your objective. I also illustrated using a mapping array so that the actual physical groups can be in any scrambled arrangement.

You didn't answer my question about whether or not you are using the KScript Editor so I'll just assume you are and post this example using KSE syntax. In order to run this code you will have to compile it in the KSE first. If this is a problem, let me know and I'll repost using only pure KSP syntax.

*on init*
``message('')
``*declare* ui_menu Category``_{ main menu }_
````add_menu_item(Category,'Guitars',0)
````add_menu_item(Category,'Pianos',1)
````add_menu_item(Category,'Basses',2)
````move_control(Category,1,1)
````read_persistent_var(Category)
``*declare* ui_menu Guitars```_{ sub menus }_
````add_menu_item(Guitars,'Acoustic Guitar',0)
````add_menu_item(Guitars,'Electric Guitar',1)
````add_menu_item(Guitars,'Nylon Guitar',2)
````move_control(Guitars,2,1)
``*declare* ui_menu Pianos
````add_menu_item(Pianos,'Acoustic Piano',3)
````add_menu_item(Pianos,'Electric Piano 1',4)
````add_menu_item(Pianos,'Electric Piano 2',5)
````move_control(Pianos,2,1)
``*declare* ui_menu Bass
````add_menu_item(Bass,'Acoustic Bass',6)
````add_menu_item(Bass,'Slap Bass',7)
````add_menu_item(Bass,'Finger Bass',8 )
````move_control(Bass,2,1)
``*declare* SubMenuID[3]
````SubMenuID[0] := get_ui_id(Guitars)
````SubMenuID[1] := get_ui_id(Pianos)
````SubMenuID[2] := get_ui_id(Bass)
``*declare* *const* Acoustic_Guitar := 0``_{ Actual Physical Group Indices }_
``*declare* *const* Electric_Guitar := 1
``*declare* *const* Nylon_Guitar := 2
``*declare* *const* Acoustic_Piano := 3
``*declare* *const* Electric_Piano_1 := 4
``*declare* *const* Electric_Piano_2 := 5
``*declare* *const* Acoustic_Bass := 6
``*declare* *const* Slap_Bass := 7
``*declare* *const* Finger_Bass := 8
``*declare* GroupMap[9] := (Acoustic_Guitar,Electric_Guitar,Nylon_Guitar, ...
``````````````````````````Acoustic_Piano,Electric_Piano_1,Electric_Piano_2, ...
``````````````````````````Acoustic_Bass,Slap_Bass,Finger_Bass)
``*declare* mx``_{ mapping index }_
``show_active_submenu
``set_map_index
``make_persistent(Category)
``make_persistent(Guitars)
``make_persistent(Pianos)
``make_persistent(Bass)
*end on*

*on note*
``disallow_group(ALL_GROUPS)
``allow_group(GroupMap[mx])
*end on*

*on ui_control*(Category)
``show_active_submenu
``*call* set_map_index
*end on*

*on ui_control*(Guitars)
``*call* set_map_index
*end on*

*on ui_control*(Pianos)
``*call* set_map_index
*end on*

*on ui_control*(Bass)
``*call* set_map_index
*end on*

*function* set_map_index
``*select* Category
````*case* 0
``````mx := Guitars
````*case* 1
``````mx := Pianos
````*case* 2
``````mx := Bass
``*end select*
*end function*

*function* show_active_submenu
``*declare* n
``*for* n := 0 *to* 2
````*if* Category = n
``````set_control_par(SubMenuID[n],CONTROL_PAR_HIDE,HIDE_PART_NOTHING)
````*else*
``````set_control_par(SubMenuID[n],CONTROL_PAR_HIDE,HIDE_WHOLE_CONTROL)
````*end if*
``*end for* 
*end function*

Rejoice,

Bob


----------



## Big Bob (Jan 31, 2012)

I forgot to mention that if you want to avoid the select-case construct, you could just let each sub-menu indices be at their natural 0..2 (in our example) indices and then incorporate your offset array idea.

For example, for the current illustration:


```
declare SubOfst[3] := (0,3,6)
```

Then, you could set the map index with:

```
mx := get_control_par(SubMenuID[Category],CONTROL_PAR_VALUE)+SubOfst[Category]
```
Using this additional array would also avoid the necessity of all the set_map_index calls in the ui callbacks.

Rejoice,

Bob


----------



## jcnoel (Jan 31, 2012)

Hi MK282 and Bob,

Thanks for your reponses.

First : Sorry Bob, but I don't have the KScript Editor !
I tried to transcribe your script in KSP syntax, but it doesn't work, because I don't know how to do for "mx" (mapping index ), "show_active_submenu", "set_map_index", and others ! :? 

So I used the script from MK 282 ( thank you too  )
It works well. But I have a little problem.

First of all, I need in fact, not 1 " menu category" ( with his sub-categories = groups ), but ...
2 "menus category" with sub-categories for each "menu category".

Because, I would like to mix both 2 differents sounds ( = 2 groups ) .

example: I choose " guitar" in "menu category *1*", and next "Electric Guitar" in his sub-category.
Then, I choose "Piano" in "menu category *2*", and next "Electric Piano" in his sub-category.

And I can play with the 2 sounds ( Guitar and Piano) both. o/~ 

So I adapted the script of MK 282 like this :


{***************** SCRIPT WITH 2 MENUS ****************}

on init 
make_perfview 
set_ui_height_px(135)

declare const $NUM_CATEGORIES := 4

declare $i

declare $cat1
declare $selected1

declare $cat2
declare $selected2

declare ui_menu $Category1
add_menu_item($Category1,"Category 1",-1)
add_menu_item($Category1,"Guitar",0) 
add_menu_item($Category1,"Piano",1) 
add_menu_item($Category1,"Bass",2)

declare ui_menu $Category2
add_menu_item($Category2,"Category 2",-1)
add_menu_item($Category2,"Guitar",0) 
add_menu_item($Category2,"Piano",1) 
add_menu_item($Category2,"Bass",2)

declare ui_menu $Guitar1
add_menu_item($Guitar1,group_name(0),0) 
add_menu_item($Guitar1,group_name(1),1) 
add_menu_item($Guitar1,group_name(2),2) 

declare ui_menu $Piano1
add_menu_item($Piano1,group_name(3),3) 
add_menu_item($Piano1,group_name(4),4)

declare ui_menu $Bass1
add_menu_item($Bass1,group_name(5),5) 
add_menu_item($Bass1,group_name(6),6) 
add_menu_item($Bass1,group_name(7),7) 
add_menu_item($Bass1,group_name(8 ),8 ) 
add_menu_item($Bass1,group_name(9),9) 

declare ui_menu $Guitar2
add_menu_item($Guitar2,group_name(10),10) 
add_menu_item($Guitar2,group_name(11),11) 
add_menu_item($Guitar2,group_name(12),12) 

declare ui_menu $Piano2
add_menu_item($Piano2,group_name(13),13) 
add_menu_item($Piano2,group_name(14),14)

declare ui_menu $Bass2
add_menu_item($Bass2,group_name(15),15) 
add_menu_item($Bass2,group_name(16),16) 
add_menu_item($Bass2,group_name(17),17) 
add_menu_item($Bass2,group_name(18 ),18 ) 
add_menu_item($Bass2,group_name(19),19) 

declare %ID1[$NUM_CATEGORIES] 
%ID1[0] := get_ui_id($Guitar1) 
%ID1[1] := get_ui_id($Piano1) 
%ID1[2] := get_ui_id($Bass1) 

declare %ID2[$NUM_CATEGORIES] 
%ID2[0] := get_ui_id($Guitar2) 
%ID2[1] := get_ui_id($Piano2) 
%ID2[2] := get_ui_id($Bass2) 

move_control_px($Category1,250,2) 
move_control_px($Guitar1,250,23) 
move_control_px($Piano1,250,23) 
move_control_px($Bass1,250,23) 

move_control_px($Category2,250,65) 
move_control_px($Guitar2,250,86) 
move_control_px($Piano2,250,86) 
move_control_px($Bass2,250,86) 

make_persistent($Category1) 
make_persistent($Guitar1) 
make_persistent($Piano1) 
make_persistent($Bass1)

make_persistent($Category2) 
make_persistent($Guitar2) 
make_persistent($Piano2) 
make_persistent($Bass2) 

make_persistent($selected1) 
make_persistent($selected2) 

read_persistent_var($Category1) 
read_persistent_var($Category2) 

$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 

$i := 0
while ($i < $NUM_CATEGORIES) 
if ($i = $Category2) 
set_control_par(%ID2[$i],$CONTROL_PAR_HIDE,$HIDE_PART_NOTHING) 
else 
set_control_par(%ID2[$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 := $Guitar1
case 1 
$selected1 := $Piano1 
case 2 
$selected1 := $Bass1
end select 
end on 

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

select ($cat2)
case 0 
$selected2 := $Guitar2
case 1 
$selected2 := $Piano2 
case 2 
$selected2 := $Bass2
end select 
end on 

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

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

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

on ui_control ($Guitar2) 
$selected2 := $Guitar2 
end on 

on ui_control ($Piano2) 
$selected2 := $Piano2
end on 

on ui_control ($Bass2) 
$selected2 := $Bass2 
end on 

on note 

disallow_group($ALL_GROUPS) 

allow_group($selected1)
allow_group($selected2) 
end on

{***************** END OF THE SCRIPT *******************}

You can see that I added 1 line in each "menu category" :

declare ui_menu $Category1
*add_menu_item($Category1,"Category 1",-1)*
add_menu_item($Category1,"Guitar",0) 
add_menu_item($Category1,"Piano",1) 
add_menu_item($Category1,"Bass",2)

and

declare ui_menu $Category2
*add_menu_item($Category2,"Category 2",-1)*
add_menu_item($Category2,"Guitar",0) 
add_menu_item($Category2,"Piano",1) 
add_menu_item($Category2,"Bass",2)

When I select the line "category" ( -1 ) in one " menu category" ( category1 or category2 ), the corresponding sub-category disappear. That's OK !
But, I always hear the sound that I previuosly selected ! :| 
( that is my problem )

For example, I would like to mute the sound of the menu "category 1" if I select the line "category" ( -1 ), and just hear the sound of the second category.

And also, if I select the line "category" of the menu "category 2" ( -1 ), I mute the sound correspondong at this category, to hear only the sound of the first category.

And then, if I select the line "category" both on the two categories, that mute evidently all the sounds !

In fact, except this "little problem", the script works well.

Also, MK282, all my sounds ( my groups ) are exactly sorted in the way I want them to show up in the individual category menus. There's no problem for that !  

And you, Bob, if you have also an another idea for my wish or a script, I'm OK to try it ! :D 

At any rate, thanks a lot for you two, MK282 and Bob for your help, and the time you take for me !!! :D :D :D 

Rejoice

J.Claude


----------



## Big Bob (Jan 31, 2012)

Hi jc,

I'm glad you more or less got things working with MK's code. But, I'm afraid that right now I can't really devote any more time to this. Maybe MK will be able to continue helping you.



> First : Sorry Bob, but I don't have the KScript Editor !



For heaven's sake, why don't you download the thing? It's free you know :lol: Seriously, the KScript Editor is a wonderful tool that no scripter should be without. 

Anyway, I hope you get everything sorted out.

Rejoice,

Bob


----------



## jcnoel (Feb 1, 2012)

Hi Bob and MK282,

Now, all is OK !

In fact, I resolved my problem by creating a last group, named "MUTE", but without sound _( This group has no waves files )_ !

I transform finally the script like this :



> on init
> make_perfview
> 
> declare const $NUM_CATEGORIES := 4
> ...



Perhaps, it's not really correct, but this script works now like I want ! :D 
( When I select the line "Category 1" or "Category 2", this mute the corresponding sound )

At any rate, *thanks a lot for you two, MK282 and Bob for your help*, and the time you take for me !!! :D 


J.Claude


----------



## mk282 (Feb 1, 2012)

There you go! 

Perhaps the script could be somewhat further optimized in some ways, but if it works for you, that's what counts the most!


----------



## Big Bob (Feb 1, 2012)

Congratulations o-[][]-o


----------

