# Making a switch turn off a group.



## sneakyalien (Sep 16, 2010)

Hi everyone,I am experimenting with Kontakt 4 and think its a great bit of software.I am trying to get my head around scripting as it interests me.
I was wondering if it is possible to set up a switch in a performance view that when pressed will swich a group on and another group off.
I have set up the following :-

declare ui_switch $8_foot_switch
set_control_par_str(get_ui_id($8_foot_switch),$CONTROL_PAR_TEXT,"")
set_control_par_str(get_ui_id($8_foot_switch),$CONTROL_PAR_PICTURE,"pv_vintage_drums_led")
move_control_px($8_foot_switch,($GRID_X * 1) - 63, ($GRID_Y * 1) + 204)

is it possible to say do the following 
if ($8_foot_switch = 1)
allow_groups(1)
disallow_groups(0)


Thanks for any help guys.
Peace to you all.
Steve.


----------



## EvilDragon (Sep 16, 2010)

allow_group and disallow_group are only possible to use in "on note" callback, which means that the change of group on/off setting will only be heard upon pressing a new note, not instantly. Is that ok with you?


----------



## sneakyalien (Sep 16, 2010)

Hi Evil Dragon,thanks for the reply.
Yes that would be fine with me but I'm not too familiar on the program structure of what you suggested.

Regards,
Steve.


----------



## sneakyalien (Sep 16, 2010)

forgot to ask-Is it possible to turn a group on and off with a switch without using allow_groups/disallow_groups?


----------



## EvilDragon (Sep 16, 2010)

Nope. You can only decrease/increase group volume with buttons, not completely deactivate them. They would still drain polyphony even if they aren't heard.

The code for your case would be something like:


```
on init
    declare ui_switch $Footswitch
end on

on note
    disallow_group($ALL_GROUPS)
    allow_group($Footswitch)
end on
```
This is a MASSIVE simplification - works only if you have two groups :D For (dis)allowing more groups, you are bound to introduce a counter variable, and do it with while loops. Let's say you have 8 groups, and you want to switch between first 4 and second 4, first 4 when switch is off, second 4 when switch is on:


```
on init
    declare ui_switch $Footswitch
    declare $count
end on

on note
    disallow_group($ALL_GROUPS)
    
    $count := 0 + (4 * $Footswitch)
    while ($count < 4 + (4 * $Footswitch))
        allow_group($count)
        inc($count)
    end while
end on
```

Bear in mind that in Kontakt group 1 has an index of 0 actually!


----------



## sneakyalien (Sep 16, 2010)

Hi Evil Dragon,thanks alot for that just keyed your code in and I can see how I'm going to get what I want to work now.
Thanks very much for your time in helping me man.
Best rgards,
Steve.


----------



## sneakyalien (Sep 16, 2010)

Hi EvilDragon,
been thinking about your suggestion of volume drops activated by a switch and think this may be a better solution to my problem.
I am basically trying to recreate an old string machine in Kontakt and the string machine in question has two sets of sounds 1 being 8 foot strings and the other being 4 foot strings there is also a square wave string.
What I wanted to do was have a switch for each 8 and 4 foot sawtooth string and be able to activate each one as required so I could have the two of them playing if both switches were on.
I would also like to then press the square wave switch which would bring in the square wave samples of the 8 and 4 foot sawtooth wave strings.
Would this devour polyphony?
Thanks for any help or ideas you may have.
Steve.


----------



## EvilDragon (Sep 16, 2010)

So, essentially, you have 4 groups, right? 8" saw, 4" saw, 8" pulse and 4" pulse? And you'd need 3 buttons, because the Pulse switch turns on the pulse strings of active footages only?

Basically you could have a button and a knob per group, buttons would do the actual allow/disallow part, and knobs would set the volumes, so you'd have it more flexible.


----------



## EvilDragon (Sep 16, 2010)

Here's a bit more advanced script for you. Gives you possibility to control pan and volume of each group. Groups should be sorted: 8" Saw, 4" Saw, 8" Pulse, 4" Pulse.

Enjoy!


```
on init
    make_perfview
    set_ui_height_px(113)

    declare ui_switch $8Saw
    declare ui_switch $4Saw
    declare ui_switch $8Pulse
    declare ui_switch $4Pulse

    declare ui_slider $8SVol(0,631000)
    declare ui_slider $4SVol(0,631000)ò-\0\0\0æ¹Ì-\0\0\0æ¹Í-\0\0\0æ¹Î-\0\0\0æ¹Ï-\0\0\0æ¹Ð-\0\0\0æ¹Ñ-\0\0\0æ¹Ò-\0\0\0æ¹Ó-\0\0\0æ¹Ô-\0\0\0æ¹Õ-\0\0\0æ¹Ö-\0\0\0æ¹×-\0\0\0æ¹Ø-\0\0\0æ¹Ù-\0\0\0æ¹Ú-\0\0\0æ¹Û-\0\0\0æ¹Ü-\0\0\0æ¹Ý-\0\0\0æ¹Þ-\0\0\0æ¹ß-\0\0\0æ¹à-\0\0\0æ¹á-\0\0\0æ¹â-\0\0\0æ¹ã-\0\0\0æ¹ä-\0\0\0æ¹å-\0\0\0æ¹æ-\0\0\0æ¹ç-\0\0\0æ¹è-\0\0\0æ¹é-\0\0\0æ¹ê-\0\0\0æ¹ë-\0\0\0æ¹ì-\0\0\0æ¹í-\0\0\0æ¹î-\0\0\0æ¹ï-\0\0\0æ¹ð-\0\0\0æ¹ñ-\0\0\0æ¹ò-\0\0\0æ¹ó-\0\0\0æ¹ô-\0\0\0æ¹õ-\0\0\0æ¹ö-\0\0\0æ¹÷-\0\0\0æ¹ø-\0\0\0æ¹ù-\0\0\0æ¹ú-\0\0\0æ¹û-\0\0\0æ¹ü-\0\0\0æ¹ý-\0\0\0æ¹þ-\0\0\0æ¹ÿ-\0\0\0æº\0-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº	-\0\0\0æº
-\0\0\0æº-\0\0\0æº-\0\0\0æº
-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº-\0\0\0æº -\0\0\0æº!-\0\0\0æº"-\0\0\0æº#-\0\0\0æº$-\0\0\0æº%-\0\0\0æº&-\0\0\0æº'-\0\0\0æº(-\0\0\0æº)-\0\0\0æº*-\0\0\0æº+-\0\0\0æº,-\0\0\0æº--\0\0\0æº.-\0\0\0æº/-\0\0\0æº0-\0\0\0æº1-\0\0\0æº2-\0\0\0æº3-\0\0\0æº4-\0\0\0æº5-\0\0\0æº6-\0\0\0æº7-\0\0\0æº8-\0\0\0æº9-\0\0\0æº:-\0\0\0æº;\0\0\0\0\0\0\0\0\0\0\0\0\0\0ƒæ\0\0\0–-\0\0\0æº­\0\0\0—/\0\0\0æ»\0\0\0˜/\0\0\0æ»\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íu\0\0\0æÒ\0\0\0Îx\0\0\0æÒG\0\0\0Ïz\0\0\0æÒÎ\0\0\0Ð|\0\0\0æÓ9\0\0\0Ñ€\0\0\0æÓš\0\0\0Ò‚\0\0\0æÔ\0\0\0Ó‚\0\0\0æÔ|\0\0\0Ôƒ\0\0\0æÔí\0\0\0Õ„\0\0\0æÕ^\0\0\0Ö‡\0\0\0æÕÏ\0\0\0×‰\0\0\0æÖ@\0\0\0Ø\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0ò-\0\0\0æº=-\0\0\0æº>-\0\0\0æº?-\0\0\0æº@-\0\0\0æºA-\0\0\0æºB-\0\0\0æºC-\0\0\0æºD-\0\0\0æºE-\0\0\0æºF-\0\0\0æºG-\0\0\0æºH-\0\0\0æºI-\0\0\0æºJ-\0\0\0æºK-\0\0\0æºL-\0\0\0æºM-\0\0\0æºN-\0\0\0æºO-\0\0\0æºP-\0\0\0æºQ-\0\0\0æºR-\0\0\0æºS-\0\0\0æºT-\0\0\0æºU-\0\0\0æºV-\0\0\0æºW-\0\0\0æºX-\0\0\0æºY-\0\0\0æºZ-\0\0\0æº[-\0\0\0æº\-\0\0\0æº]-\0\0\0æº^-\0\0\0æº_-\0\0\0æº`-\0\0\0æºa-\0\0\0æºb-\0\0\0æºc-\0\0\0æºd-\0\0\0æºe-\0\0\0æºf-\0\0\0æºg-\0\0\0æºh-\0\0\0æºi-\0\0\0æºj-\0\0\0æºk-\0\0\0æºl-\0\0\0æºm-\0\0\0æºn-\0\0\0æºo-\0\0\0æºp-\0\0\0æºq-\0\0\0æºr-\0\0\0æºs-\0\0\0æºt-\0\0\0æºu-\0\0\0æºv-\0\0\0æºw-\0\0\0æºx-\0\0\0æºy-\0\0\0æºz-\0\0\0æº{-\0\0\0æº|-\0\0\0æº}-\0\0\0æº~-\0\0\0æº-\0\0\0æº€-\0\0\0æº-\0\0\0æº‚-\0\0\0æºƒ-\0\0\0æº„-\0\0\0æº…-\0\0\0æº†-\0\0\0æº‡-\0\0\0æºˆ-\0\0\0æº‰-\0\0\0æºŠ-\0\0\0æº‹-\0\0\0æºŒ-\0\0\0æº-\0\0\0æºŽ-\0\0\0æº-\0\0\0æº-\0\0\0æº‘-\0\0\0æº’-\0\0\0æº“-\0\0\0æº”-\0\0\0æº•-\0\0\0æº–-\0\0\0æº—-\0\0\0æº˜-\0\0\0æº™-\0\0\0æºš-\0\0\0æº›-\0\0\0æºœ-\0\0\0æº-\0\0\0æºž-\0\0\0æºŸ-\0\0\0æº -\0\0\0æº¡-\0\0\0æº¢-\0\0\0æº£-\0\0\0æº¤-\0\0\0æº¥-\0\0\0æº¦-\0\0\0æº§-\0\0\0æº¨-\0\0\0æº©-\0\0\0æºª-\0\0\0æº«-\0\0\0æº¬\0\0\0\0\0\0\0\0\0\0\0\0\0\0ò-\0\0\0æº®-\0\0\0æº¯-\0\0\0æº°-\0\0\0æº±-\0\0\0æº²-\0\0\0æº³-\0\0\0æº´-\0\0\0æºµ-\0\0\0æº¶-\0\0\0æº·-\0\0\0æº¸-\0\0\0æº¹-\0\0\0æºº-\0\0\0æº»-\0\0\0æº¼-\0\0\0æº½-\0\0\0æº¾-\0\0\0æº¿-\0\0\0æºÀ-\0\0\0æºÁ-\0\0\0æºÂ-\0\0\0æºÃ-\0\0\0æºÄ-\0\0\0æºÅ-\0\0\0æºÆ-\0\0\0æºÇ-\0\0\0æºÈ-\0\0\0æºÉ-\0\0\0æºÊ-\0\0\0æºË-\0\0\0æºÌ-\0\0\0æºÍ-\0\0\0æºÎ-\0\0\0æºÏ-\0\0\0æºÐ-\0\0\0æºÑ-\0\0\0æºÒ-\0\0\0æºÓ-\0\0\0æºÔ-\0\0\0æºÕ-\0\0\0æºÖ.\0\0\0æº×.\0\0\0æºØ.\0\0\0æºÙ.\0\0\0æºÚ.\0\0\0æºÛ.\0\0\0æºÜ.\0\0\0æºÝ.\0\0\0æºÞ.\0\0\0æºß.\0\0\0æºà.\0\0\0æºá.\0\0\0æºâ.\0\0\0æºã.\0\0\0æºä.\0\0\0æºå.\0\0\0æºæ.\0\0\0æºç.\0\0\0æºè.\0\0\0æºé.\0\0\0æºê.\0\0\0æºë.\0\0\0æºì.\0\0\0æºí.\0\0\0æºî.\0\0\0æºï.\0\0\0æºð.\0\0\0æºñ.\0\0\0æºò.\0\0\0æºó.\0\0\0æºô.\0\0\0æºõ.\0\0\0æºö.\0\0\0æº÷.\0\0\0æºø.\0\0\0æºù.\0\0\0æºú.\0\0\0æºû.\0\0\0æºü.\0\0\0æºý.\0\0\0æºþ.\0\0\0æºÿ.\0\0\0æ»\0.\0\0\0æ».\0\0\0æ».\0\0\0æ».\0\0\0æ».\0\0\0æ».\0\0\0æ».\0\0\0æ».\0\0\0æ».\0\0\0æ»	.\0\0\0æ»
.\0\0\0æ».\0\0\0æ».\0\0\0æ»
.\0\0\0æ».\0\0\0æ».\0\0\0æ».\0\0\0æ».\0\0\0æ»/\0\0\0æ»/\0\0\0æ»/\0\0\0æ»/\0\0\0æ»/\0\0\0æ»/\0\0\0æ»/\0\0\0æ»/\0\0\0æ»/\0\0\0æ»/\0\0\0æ»/\0\0\0æ»\0\0\0\0\0\0\0\0\0\0\0\0\0\040;$4PVol)
    set_engine_par($ENGINE_PAR_VOLUME,$4PVol,3,-1,-1)
    set_text($Volume,"Volume: " & get_engine_par_disp($ENGINE_PAR_VOLUME,3,-1,-1) & " dB")
    $time := $ENGINE_UPTIME
    wait(2000000)
    if ($ENGINE_UPTIME = $time + 2000)
        set_text($Volume,"Volume")
    else
        exit
    end if
end on

on ui_control($8SPan)
    set_engine_par($ENGINE_PAR_PAN,$8SPan,0,-1,-1)
    set_text($Pan,"Pan: " & get_engine_par_disp($ENGINE_PAR_PAN,0,-1,-1))
    $time := $ENGINE_UPTIME
    wait(2000000)
    if ($ENGINE_UPTIME = $time + 2000)
        set_text($Pan,"Pan")
    else
        exit
    end if
end on

on ui_control($4SPan)
    set_engine_par($ENGINE_PAR_PAN,$4SPan,1,-1,-1)
    set_text($Pan,"Pan: " & get_engine_par_disp($ENGINE_PAR_PAN,1,-1,-1))
    $time := $ENGINE_UPTIME
    wait(2000000)
    if ($ENGINE_UPTIME = $time + 2000)
        set_text($Pan,"Pan")
    else
        exit
    end if
end on

on ui_control($8PPan)
    set_engine_par($ENGINE_PAR_PAN,$8PPan,2,-1,-1)
    set_text($Pan,"Pan: " & get_engine_par_disp($ENGINE_PAR_PAN,2,-1,-1))
    $time := $ENGINE_UPTIME
    wait(2000000)
    if ($ENGINE_UPTIME = $time + 2000)
        set_text($Pan,"Pan")
    else
        exit
    end if
end on

on ui_control($4PPan)
    set_engine_par($ENGINE_PAR_PAN,$4PPan,3,-1,-1)
    set_text($Pan,"Pan: " & get_engine_par_disp($ENGINE_PAR_PAN,3,-1,-1))
    $time := $ENGINE_UPTIME
    wait(2000000)
    if ($ENGINE_UPTIME = $time + 2000)
        set_text($Pan,"Pan")
    else
        exit
    end if
end on

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


----------



## sneakyalien (Sep 17, 2010)

Wow,man you are an excellent coder.I will experiment with your code and try an work out how it works.
It looks impressive .
Thanks a lot for all the time you put in.
Best regards,
Steve.


----------



## sneakyalien (Sep 17, 2010)

Hi Evil Dragon,just tried your script and it works perfectly.I definitley owe you some beers buddy 
The string synth is starting to sound just like the real thing except for the way in which the sounds release when a new chord is played-On the original machine the first chord will be cut off abrubtly to play the next chord because the original synth uses divide down organ technology and is paraphonic so it does not have a proper enevelope generator for each note.
I do not know if Kontakt has a way of simulating paraphonic polyphonic synthesis but I think it would be a great update for NI to implement.
I love Kontakt I think its amazing and is real fun to use.
Thanks again for all your help,
All the best,
Steve.


----------



## snapshot (Sep 17, 2010)

im pretty sure it is doable , its like voice stealing solution . could be a little tricky but im sure it can be done with some logical functions and conditions . but its worth of work ? it was a limitation of that times , i mean it was a big compromise to have at least some polyphony . Its all bout the way you want to perform/play ? 

greets
K


----------



## EvilDragon (Sep 17, 2010)

I don't have any ideas about how to emulate paraphonic behavior. :(


----------



## sneakyalien (Sep 29, 2010)

Hi all,
been thinking about paraphonic emulation and I was playing with a string machine to figure out what I think actually happens.
I think Paraphonic emulation could be emulated if there is a way to end abruptly any notes that are in their release phase of ahdsr only if other note(s) are played.
Also if for instance you are playing a chord with the left hand and a melody with the right the notes playing the chord would still play but the notes in the right hand would also play but their release phase would be cut short if any other new notes where played.I think that's right,I'm probaly not doing a good job at explaining my thoughts.
Is it possible to query if a note is in its release phase of ahdsr?
I know paraphonic is a step backwards in terms of true polyphony but paraphonic synths really owe alot of their character to not being able to allow each note to have its own release stage in an envelope.

It's got me thinking,I was walking around my local supermarket in a zombie state,I was even laying in bed thinking about it till about 3 in the morning-Its quite adictive all this coding and samples isn't it?
Best regards,
Steve.


----------

