# Mute Groups with on/off per group



## David Amateau (Jun 4, 2018)

I've seen similar questions asked but not exactly executed how I want.

So, let's say I have 5 groups. I want to be able to trigger all 5 groups at once or only one or any combination of groups together. I'd like to do this by adding a button or knob to control them with as an on/off switch. I'm at a loss when it comes to scripting but from what I've seen it shouldn't be too difficult. I'd assume you just script each group to a on/off knob but I don't really know how to go about doing it. If someone could help me out I would greatly appreciate it. Thanks


----------



## EvilDragon (Jun 5, 2018)

It's pretty simple, yeah.


```
on init
    declare ui_switch $1
    declare ui_switch $2
    declare ui_switch $3
    declare ui_switch $4
    declare ui_switch $5

    $1 := 1
    $2 := 1
    $3 := 1
    $4 := 1
    $5 := 1

    make_persistent($1)
    make_persistent($2)
    make_persistent($3)
    make_persistent($4)
    make_persistent($5)

    message("")
end on

on note
    disallow_group($ALL_GROUPS)
    allow_group(0, $1)
    allow_group(1, $2)
    allow_group(2, $3)
    allow_group(3, $4)
    allow_group(4, $5)
end on
```


----------



## David Amateau (Jun 5, 2018)

Thank you for the help. I'm getting an error message on line 20
[allow_group(0, $1)] expression expected. And would this be to combine groups? I'd preferably just like each button to serve to unmute or mute a single group so I could have all 5 groups playing at once or pick and choose. Sort of in an organ-esque style.

And again thanks (thanks as well as for all the comments of yours I have read, it seems like you are the internets personal guru for Kontakt.


----------



## Ecliptiq Audio (Jun 5, 2018)

Hi,

This should work. And yes, you can combine groups with this method.


```
on init
  declare ui_switch $1
  declare ui_switch $2
  declare ui_switch $3
  declare ui_switch $4
  declare ui_switch $5

  $1 := 1
  $2 := 1
  $3 := 1
  $4 := 1
  $5 := 1

  make_persistent($1)
  make_persistent($2)
  make_persistent($3)
  make_persistent($4)
  make_persistent($5)

  message("")
end on

on note
  disallow_group($ALL_GROUPS)
  if ($1=1)
  allow_group(0)
  end if
  if ($2=1)
  allow_group(1)
  end if
  if ($3=1)
  allow_group(2)
  end if
  if ($4=1)
  allow_group(3)
  end if
  if ($5=1)
  allow_group(4)
  end if
end on
```

Regards,
Peter


----------



## EvilDragon (Jun 5, 2018)

David Amateau said:


> [allow_group(0, $1)] expression expected. And would this be to combine groups? I'd preferably just like each button to serve to unmute or mute a single group so I could have all 5 groups playing at once or pick and choose. Sort of in an organ-esque style.



Whoops, I messed up the syntax for purge_group, my bad. Here's an even simpler way from the one that Peter suggests:


```
on init
  declare $i
  declare $MAX_GROUPS := 5

  declare ui_switch $1
  declare ui_switch $2
  declare ui_switch $3
  declare ui_switch $4
  declare ui_switch $5

  declare $first_ID
  $first_ID := get_ui_id($1)

  $1 := 1
  $2 := 1
  $3 := 1
  $4 := 1
  $5 := 1

  make_persistent($1)
  make_persistent($2)
  make_persistent($3)
  make_persistent($4)
  make_persistent($5)

  message("")
end on

on note
  $i := 0
  while ($i < $MAX_GROUPS)
    set_event_par_arr($EVENT_ID, $EVENT_PAR_ALLOW_GROUP, get_control_par($first_ID + $i, $CONTROL_PAR_VALUE), $i)
    inc($i)
  end while
end on
```


And yes, this is going to create a button for each of the 5 groups you have, so you can toggle them on/off at will. Just be aware that group allowing is applied only on newly played notes, meaning that with this method you cannot change which groups are active during a played note.


----------



## David Amateau (Jun 5, 2018)

Works like a charm. You both have my gratitude. Thank you!


----------

