# Hello Friends I have a question,That related to while loop and disallow_group [I SOLVED]



## Aviram Dayan Production (Nov 12, 2016)

I did a test,for two switches control
And the problem in separately only One control work,
But both Do not work together,
also I try to Use Select And Case,It works partially, but still not back to the default
also I know That I can do , transfer to 3 steps - declare ui_slider $ID (0,2)
But it is interesting to me, what's going on ..what i am doing wrong?

Before, it is important to say in My product I have a lot keyswitches on
"Group Start option" That split Throughout the all groups from 0 until 260
tnx 

ksp:

```
on init

    declare $groups_off := 0 {from 0 until something}
    declare $groups_on := 4 {from 4 until something}

    declare ui_switch $Switch1
    move_control_px ($Switch1,80,0)
    set_control_par_str(get_ui_id($Switch1),$CONTROL_PAR_PICTURE,"Switch_Fire_2016")
    set_control_par_str(get_ui_id($Switch1),$CONTROL_PAR_TEXT,"")
    set_control_par(get_ui_id($Switch1),$CONTROL_PAR_WIDTH,20)
    set_control_par(get_ui_id($Switch1),$CONTROL_PAR_HEIGHT,20)
    set_control_par(get_ui_id($Switch1),$CONTROL_PAR_DEFAULT_VALUE,0)
    set_control_par_str(get_ui_id($Switch1),$CONTROL_PAR_HELP,"Switch1")
    $Switch1 := 0

    declare $groups_off2 := 8 {from 8 until something}
    declare $groups_on2 := 12 {from 12 until something}

    declare ui_switch $Switch2
    move_control_px ($Switch2,120,0)
    set_control_par_str(get_ui_id($Switch2),$CONTROL_PAR_PICTURE,"Switch_Fire_2016")
    set_control_par_str(get_ui_id($Switch2),$CONTROL_PAR_TEXT,"")
    set_control_par(get_ui_id($Switch2),$CONTROL_PAR_WIDTH,20)
    set_control_par(get_ui_id($Switch2),$CONTROL_PAR_HEIGHT,20)
    set_control_par(get_ui_id($Switch2),$CONTROL_PAR_DEFAULT_VALUE,0)
    set_control_par_str(get_ui_id($Switch2),$CONTROL_PAR_HELP,"Switch2")
    $Switch2 := 0

end on


on note

if ($Switch1 = 0)
disallow_group($ALL_GROUPS)
$groups_off := 0
while ($groups_off < 4)
    allow_group($groups_off)
inc($groups_off)
end while
end if

if ($Switch1 = 1)
disallow_group($ALL_GROUPS)
$groups_on := 4
while ($groups_on < 8)
    allow_group($groups_on)
inc($groups_on)
end while
end if

if ($Switch2 = 0)
disallow_group($ALL_GROUPS)
$groups_off2 := 8
while ($groups_off2 < 12)
    allow_group($groups_off2)
inc($groups_off2)
end while
end if

if ($Switch2 = 1)
disallow_group($ALL_GROUPS)
$groups_on2 := 12
while ($groups_on2 < 16)
    allow_group($groups_on2)
inc($groups_on2)
end while
end if
end on


on ui_control ($Switch1)
if ($Switch1 = 0)
$groups_off := 1
end if
if ($Switch1 = 1)
$groups_on := 1
end if
end on

on ui_control ($Switch2)
if ($Switch2 = 0)
$groups_off2 := 1
end if
if ($Switch2 = 1)
$groups_on2 := 1
end if
end on
```


----------



## Stiltzkin (Nov 12, 2016)

Hi,

You can simplify this a bit, especially the on note section:


```
on init
    declare const $total_groups := 4 { the number of groups to enable, typically the total number of mic positions in an instrument }
    declare $i := 0 { general counter }
    declare $switch_group1 { This will store the group, based on how switches are set }
    declare $switch_group2 { This will store the group, based on how switches are set }
end on

on note

    disallow_group($ALL_GROUPS) { No need to have this written in each if statement if it's always happening }

    $i := 0 { reset counter }
    while($i < $total_groups) { perform this loop until we reach the total number of groups/mic positions }
        allow_group($i + $switch_group1)
        allow_group($i + $switch_group2)
        inc(i)
    end while

end on

on ui_control ($Switch1)
    if ($Switch1 = 0)
        $switch_group1 := 0
    else {if it's 1}
        $switch_group1 := 4
    end if
end on

on ui_control ($Switch2)
    if ($Switch2 = 0)
        $switch_group2 := 8
    else { if it's 1}
        $switch_group2 := 12
    end if
end on
```

Just wrote this on a quick notepad since I'm not at a computer with kontakt, but that should do basically what you need, which if I'm not mistaken is allow a set of groups, starting from a set group based on the state of the switches.

I wasn't completely sure if that's what you were looking to achieve, but by the code you provided that's what it looks like it was going for!

If you only wanted ONE set of groups to enable based on the setting of each different switch, you'd just need to add the appropriate if statements in to the on ui_controls and only have one line of allow_groups in the on note. Hope this helps


----------



## Aviram Dayan Production (Nov 13, 2016)

Stiltzkin said:


> Hi,
> 
> You can simplify this a bit, especially the on note section:
> 
> ...



Hey bro thanks for the reply, maybe you did not understand me right
Through your code, If one of the switches on "1",The group That will be active, only over 4 (4) ,I understand how it works,
*but only in general I need something else,*
in general for me ,I need That Default groups,Will be from 0 until 168 or above (simple default through "Group Start option")
Before one of Control Will be on "1"
Anyway
I pass to this way like this, it works with 3 steps,
with slider Control Together with CASE and Select
ksp:


```
on init

    declare $G1 := 0 {from 0 Default}
    declare $groups_off := 232 {from 232}
    declare $groups_on := 236 {from 236}

    declare ui_slider $Slider1 (0,2)
    move_control_px ($Slider1,80,0)
    make_persistent ($Slider1)
    read_persistent_var ($Slider1)
    set_control_par_str(get_ui_id($Slider1),$CONTROL_PAR_PICTURE,"G")
    set_control_par(get_ui_id($Slider1),$CONTROL_PAR_WIDTH,20)
    set_control_par(get_ui_id($Slider1),$CONTROL_PAR_HEIGHT,20)
    set_control_par(get_ui_id($Slider1),$CONTROL_PAR_MOUSE_BEHAVIOUR,5000)
    set_control_par(get_ui_id($Slider1),$CONTROL_PAR_DEFAULT_VALUE,0)
    set_control_par_str(get_ui_id($Slider1),$CONTROL_PAR_HELP,"G")
    $Slider1 := 0
end on


on note
select ($Slider1)
case 0
if ($Slider1 = 0)
disallow_group($ALL_GROUPS)
$G1 := 0
while ($G1 < 168)
    allow_group($G1)
inc($G1)
end while
end if


case 1
if ($Slider1 = 1)
disallow_group($ALL_GROUPS)
$groups_off := 232
while ($groups_off < 236)
    allow_group($groups_off)
inc($groups_off)
end while
end if


case 2
if ($Slider1 = 2)
disallow_group($ALL_GROUPS)
$groups_on := 236
while ($groups_on < 240)
    allow_group($groups_on)
inc($groups_on)
end while
end if
end select
end on
```

like this "alone" on one Tab It works great,
But I have a clash in the second Tab (Or the same tab,Anyway there is a clash With two codes together)

the question now, I created menu (on the second Tab)
That makes solo and mute,For any groups That related to Articulation Working through ("Group Start option")

and the second Tab on the "on note" i have this code:

```
disallow_group($ALL_GROUPS)
if ($solo >= 0)
if (($solo >= 0) and ($solo < $NUM_GROUPS))
if (%groups[$solo] = 1)
allow_group($solo)
end if
end if
else
$n := 0
while ($n < $NUM_GROUPS)
if (%groups[$n] = 1)
allow_group($n)
end if
inc($n)
end while
end if
```

How do I make it work together?
tnx to all.


----------



## Stiltzkin (Nov 13, 2016)

Aviram Dayan Production said:


> I need That Default groups,Will be from 0 until 168 or above
> Before one of Control Will be on "1"




```
on init
    declare const $total_groups := 168 { Or replace with however many groups you want enabled by default }
    declare $i {counter}
end on

on note
    disallow_groups($ALL_GROUPS)

    if($switch1 = 0 and $switch2 = 0 and $switch3 = 0) { if all switches are off (add as many switches as you need) }
        $i := 0
        while($i < $total_groups)
            allow_group($i)
            inc($i)
        end while
    else
        {whatever terms you need to put if any of the switches are on here}
    end if
end on
```

I'm not sure if there's a language barrier here, but if you just need a baseline set of groups enabled when all switches are off, that there will do it. Then in the "else" section you'd add specifics for each switch.


----------



## Aviram Dayan Production (Nov 13, 2016)

Stiltzkin said:


> ```
> on init
> declare const $total_groups := 168 { Or replace with however many groups you want enabled by default }
> declare $i {counter}
> ...



Probably it is not clear yet..The question before, Not relevant for my product (this is just a test with switches)

I edited the question (in post 3) And i changed the way to one slider
Take a look at the detailed of the question there,please.
I need to know how I make it work together.


----------



## Stiltzkin (Nov 13, 2016)

Ok based on the new code there, there's a whole lot of code you can get around by simplifying all of this in to two arrays as follows:



```
on init
    declare %slider_groups[3] := (0, 232, 236) { Stores the start group values}
    declare %slider_groups_end[3] := (168, 236, 240) { Stores the end groups }
    declare $i { counter }
    declare ui_slider $Slider1 (0, 2) { Slider to set the groups to enable }
end on

on note
    disallow_group($ALL_GROUPS) { No need to have the same thing written 3 times since it happens in all cases }
    $i := %slider_groups[$slider1] { Set the starting group based on the array }
    while ($i < %slider_groups_end[$slider1]) { this loop will activate all the groups between the two cells in the array that you need }
        allow_group($i)
        inc($i)
    end while
end on
```

However the second part of the question - do you mean you have 2 on notes in separate tabs? Because that's what it sounded like you meant? But it's still not clear exactly what you want to happen from an instrument standpoint. If you could sort of explain step by step what you want to happen, I can do my best to help!


----------



## Aviram Dayan Production (Nov 14, 2016)

Hey bro Sorry for the delay, It's amazing how this way, short
This way works great,I need to make more from this way ..
But the problem still exists, If it is active Together with the menu on the *second tab*
in this part


```
disallow_group($ALL_GROUPS)
if ($solo >= 0)
if (($solo >= 0) and ($solo < $NUM_GROUPS))
if (%groups[$solo] = 1)
allow_group($solo)
end if
end if
else
$n := 0
while ($n < $NUM_GROUPS)
if (%groups[$n] = 1)
allow_group($n)
end if
inc($n)
end while
end if
```


I'll send you maybe the all code That related to menu (Maybe it will be easier to understand, What I did there) 
-I removes All the variables and calls-
full menu ksp:


----------



## Stiltzkin (Nov 15, 2016)

Aviram Dayan Production said:


> Hey bro Sorry for the delay, It's amazing how this way, short
> This way works great,I need to make more from this way ..
> But the problem still exists, If it is active Together with the menu on the *second tab*
> in this part
> ...



What is the intent of this code, what do you want it to do?


----------



## Aviram Dayan Production (Nov 15, 2016)

Stiltzkin said:


> What is the intent of this code, what do you want it to do?



again In general,I have Articulation that connected To "Group Start option"
(That I already sent you the full ksp code of the menu,in post 7)
And the menu existing In the second tab,He makes solo and mute For all existing groups

And the slider
If the slider 0 - The activity groups will be 0 to 168 that would be groups That related to "Group Start option"
If the slider 1 - a new set of groups enter (after the 168 or above ) *Regardless to "Group Start option"*
If the slider 2 - etc.. (new set of groups enter)

The problem:
If both are active (the slider and menu)
and the slider equal to 0 he activates the groups above 168
and not "until" 168 ,If each Working individually, everything is fine.

Understand?
So there is a problem in the menu.
(Or should Manually route the articulation,But I do not believe I can't At the moment, too much work)


----------



## Stiltzkin (Nov 16, 2016)

Unfortunately I still don't fully understand what you're trying to achieve, which makes it hard to sort of say what is needed - maybe I'm just not awake yet!


----------



## Aviram Dayan Production (Nov 16, 2016)

Stiltzkin said:


> Unfortunately I still don't fully understand what you're trying to achieve, which makes it hard to sort of say what is needed - maybe I'm just not awake yet!


Strange, I explained the problem Excellent
Did you see the ksp menu? again..


----------



## Aviram Dayan Production (Nov 23, 2016)

someone..


----------



## Lindon (Nov 24, 2016)

clearly this statement is incorrect? "I explained the problem Excellent"


----------



## Aviram Dayan Production (Nov 24, 2016)

Lindon said:


> clearly this statement is incorrect? "I explained the problem Excellent"



Hello Lindon, maybe I have not explained well , I'd love to know what you did not understand?
again the problem in the > Menu (Inside there allow and disallow function)
If there is another Control,On another tab or the same tab, no matter what,The related To allow and disallow,
the solo and mute from the menu stops working, again very possible the problem In the menu.


----------



## Lindon (Nov 24, 2016)

- define the layout of your instrument, number of groups, how they are collected into sounds, how they are routed.

- define your UI

- define what you wish to see happen when a ui element is engaged

I assume you are trying to allow/disallow one or more groups, but you dont give us context of how many groups you have or how they are arranged in your instrument. What are you attempting to get done with this allow/disallow? Make a group (or set of groups)muted?

What do you mean when you say "tab" do you mean another KSP slot?

If so you really really dont want to be having UI widgets in two different places affect the load state of the same groups, unless you can communicate the state change in some way, by using pgs variables.


----------



## Aviram Dayan Production (Nov 24, 2016)

Lindon said:


> - define the layout of your instrument, number of groups, how they are collected into sounds, how they are routed.
> 
> - define your UI
> 
> ...



Hello Lindon,and yes another slot, I think I will try to use function calls to purge_group And while loop For solo and mute..
This is probably the only option,tnx Lindon and very tnx to *Stiltzkin** .*
*Edit:*
i solved
.


----------

