What's new

UI control button for release groups, disallow_groups not working

KrisY

Noob in frenzy loop
This thread will also be called:

Workaround for the release group "disallow_group" bug with "ignore_event"?

Issue:

I want to control the usage of certain Release Groups (groups that use release trigger as start) at certain UI-changes. I got a UI with buttons that switches on-off groups. The sustain sample groups, that are triggered on "Note On" are fine with the "allow_groups" or "disallow_groups" command. But since Kontakt does not work with these commands on release groups, or in the "on release", I need help.

I found my saviour - the "ignore_event($EVENT_ID)" statement!

But then I had to do it with if / else statements too. Cause it is not just one button for one single group. There are of course more combinations. Like some buttons are supposed to turn off say, groups 1, 2, 4 and 6. The next button switches on and off groups 1, 2, 3 and 7. And so forth. So unless I can do that there will be lots of voices where there need not be any sound, or excessive polyphony.

So, how to say that the ignore_event($EVENT_ID) statement should only apply for certain groups?

like:

Code:
on release

    ignore_event($EVENT_ID)
    but not for groups ... ...
    
    or maybe just for events produced by groups ... ...

end on

And that´s where his KSP came to a halt... :/

Thanks for any help.
 
When you're triggering a note from a certain group, you should add some variables like $group_1_active, $group_2_active etc... to describe which group is active and which ones are not.

For example, when you trigger a note from the first group, you will have something like this (with $TRUE:=1 and $FALSE:=0 being constants which you'll declare during the "on init" callback) :


$group_1_active:=$TRUE
$group_2_active:=$FALSE
$group_3_active:=$FALSE
$group_4_active:=$FALSE

and then during you "on release" callback something like this (here the script ignores the release for the first and fourth group):

Code:
on release


if ($group_1_active=1 or $group_4_active=1)
    ignore_event($EVENT_ID)
end if
  
 

end on


It doesn't look very clean but I tried to explain it in a simple way.
 

ScoringFilm

Active Member
Here's one I wrote quite some time ago that can be altered to your needs.

Code:
on init
 SET_CONDITION(NO_SYS_SCRIPT_RLS_TRIG)
 declare $normal_group {normal groups}
 declare $release_group {release groups}
 declare $parent_id
 declare $rel_voice
 declare ui_button $Note_On
 $Note_On := 1
 make_persistent($Note_On)
 declare ui_button $Release_On
 $Release_On := 0
 make_persistent($Release_On) 
end on

on note
 $parent_id := $EVENT_ID 
 disallow_group($ALL_GROUPS)
 $normal_group := 0
 while ($normal_group <= $NUM_GROUPS-1)
  if (_get_engine_par($ENGINE_PAR_RELEASE_TRIGGER, $normal_group, -1, -1) = 0)
   if ($Note_On = 1)
    allow_group($normal_group)
   end if
  end if
  inc($normal_group)
 end while 
 _reset_rls_trig_counter($EVENT_NOTE) 
end on

on release 
 note_off ($EVENT_ID)
 disallow_group($ALL_GROUPS)
 $release_group := 0
 if ($EVENT_ID = $parent_id)
  while ($release_group <= $NUM_GROUPS-1)
   if (_get_engine_par($ENGINE_PAR_RELEASE_TRIGGER, $release_group, -1, -1) # 0)
    if ($Release_On = 1)
     allow_group($release_group)
    end if
   end if
   inc($release_group)
  end while
  $rel_voice := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,0)
 end if
 allow_group($ALL_GROUPS)
end on
 
Last edited:
OP
K

KrisY

Noob in frenzy loop
When you're triggering a note from a certain group, you should add some variables like $group_1_active, $group_2_active etc... to describe which group is active and which ones are not.

For example, when you trigger a note from the first group, you will have something like this (with $TRUE:=1 and $FALSE:=0 being constants which you'll declare during the "on init" callback) :


$group_1_active:=$TRUE
$group_2_active:=$FALSE
$group_3_active:=$FALSE
$group_4_active:=$FALSE

and then during you "on release" callback something like this (here the script ignores the release for the first and fourth group):

Code:
on release


if ($group_1_active=1 or $group_4_active=1)
    ignore_event($EVENT_ID)
end if
 
 

end on


It doesn't look very clean but I tried to explain it in a simple way.

Okay, thanks a lot for that tip, this is the kind of code i´m looking for. Mainly how to put the code into a variable, kind of new to some statements in KSP. And a code newbie to start with.

Thanks a lot. Will have a look at this approach.
 
OP
K

KrisY

Noob in frenzy loop
Here's one I wrote quite some time ago that can be altered to your needs.

Code:
on init
 SET_CONDITION(NO_SYS_SCRIPT_RLS_TRIG)
 declare $normal_group {normal groups}
 declare $release_group {release groups}
 declare $parent_id
 declare $rel_voice
 declare ui_button $Note_On
 $Note_On := 1
 make_persistent($Note_On)
 declare ui_button $Release_On
 $Release_On := 0
 make_persistent($Release_On)
end on

on note
 $parent_id := $EVENT_ID
 disallow_group($ALL_GROUPS)
 $normal_group := 0
 while ($normal_group <= $NUM_GROUPS-1)
  if (_get_engine_par($ENGINE_PAR_RELEASE_TRIGGER, $normal_group, -1, -1) = 0)
   if ($Note_On = 1)
    allow_group($normal_group)
   end if
  end if
  inc($normal_group)
 end while
 _reset_rls_trig_counter($EVENT_NOTE)
end on

on release
 note_off ($EVENT_ID)
 disallow_group($ALL_GROUPS)
 $release_group := 0
 if ($EVENT_ID = $parent_id)
  while ($release_group <= $NUM_GROUPS-1)
   if (_get_engine_par($ENGINE_PAR_RELEASE_TRIGGER, $release_group, -1, -1) # 0)
    if ($Release_On = 1)
     allow_group($release_group)
    end if
   end if
   inc($release_group)
  end while
  $rel_voice := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,0)
 end if
 allow_group($ALL_GROUPS)
end on
Wow! Nice, This is a lot of work in there. Thanks, very generous. One question about the disallow_group($ALL_GROUPS) and the allow_group($ALL_GROUPS) statements in the on release call. Is this code: "SET_CONDITION(NO_SYS_SCRIPT_RLS_TRIG)" the reason this statement work at all? Is that why you made this script? I had, as I mentioned, no luck with these using the native release functionality of kontakt.

I could use this script, but I have the need for about 150 release groups, because of an issue with my key instrument having many lengths of samples in different octaves. While there are ways to use arrays to specify note or key lengths this is way beyond my skills. Need at this moment to just put together the function of allowing and disallowing certain groups based on if a button is clicked or not. But I have to use the native release functionality of contact. And so the ignore_event is the only statement I know to use. Is there a way to use the ignore_event with perhaps an "find_group" statement?

Thanks for the help.
 

ScoringFilm

Active Member
Is this code: "SET_CONDITION(NO_SYS_SCRIPT_RLS_TRIG)" the reason this statement work at all?
Indeed, this tells Kontakt not to trigger release groups on key up as you are going to do it manually by script.

_reset_rls_trig_counter($EVENT_NOTE) is also essential

You could use "find_group" or a loop which goes through your groups and selects the ones you want. An array which contains the number of each set of groups would most probably be the easiest and most efficient way.

J
 
OP
K

KrisY

Noob in frenzy loop
You could use "find_group" or a loop which goes through your groups and selects the ones you want. An array which contains the number of each set of groups would most probably be the easiest and most efficient way.
Okay. So this will only work if the native release note up function is disabled? I can´t trigger groups in any way if I do not use the "SET_CONDITION(NO_SYS_SCRIPT_RLS_TRIG)" statement?

Could I use find_group in a case/while loop with the ignore_events ? How do I reset the ignore_events? Is there perhaps a counter action? Like play_note ?
 

ScoringFilm

Active Member
Okay. So this will only work if the native release note up function is disabled? I can´t trigger groups in any way if I do not use the "SET_CONDITION(NO_SYS_SCRIPT_RLS_TRIG)" statement?
If you do not use the "SET_CONDITION(NO_SYS_SCRIPT_RLS_TRIG)" statement, Kontakt will play your release groups automatically on key up. You can still trigger any groups you want without this.

Could I use find_group in a case/while loop with the ignore_events ?
Yes

How do I reset the ignore_events? Is there perhaps a counter action? Like play_note ?
ignore_event is used to manually (script) what action Kontakt should take on each particular event. To reset in my script I used:

allow_group($ALL_GROUPS)
_reset_rls_trig_counter($EVENT_NOTE)

Without seeing an example of your script it is very difficult to advise as your descriptions are a bit vague! Best way to learn is trial and error; exactly how I learnt!
 
Last edited:
OP
K

KrisY

Noob in frenzy loop
Here is the parts of my script that handle this:

Code:
on init

    make_perfview
    set_script_title("Instrument Name")
    message("")


    declare ui_button $relMuteButton
    set_text($relMuteButton,"Release On/Off Switch")
    $relMuteButton := 1
    make_persistent ($relMuteButton)


end on


{ui control: release MUTE Button}

on ui_control($relMuteButton) {just turning on a volume -inf on a bus effect}
    set_engine_par($ENGINE_PAR_SEND_EFFECT_BYPASS,$relMuteButton,-1,6,$NI_BUS_OFFSET + 1)

end on


on release

    if ($relMuteButton = 0)
    {here is where a while loop could choose the groups to find groups and allow samples from some groups }
        ignore_event($EVENT_ID)
    end if

    {the reason for the need for this, on top of the above bus-effect volume adjustment, is just that the groups do not switch of internally.}


end on {on release}
 
OP
K

KrisY

Noob in frenzy loop
There may also be a way to just limit the amount of voices of the groups in question.
 

ScoringFilm

Active Member
KrisY, my script above will definitely do what you want. Just setup the groups you want to mute.

Code:
on init
 SET_CONDITION(NO_SYS_SCRIPT_RLS_TRIG)
 declare $release_group {release groups}
 declare $parent_id
 declare $rel_voice
 declare ui_button $Release_On
 $Release_On := 0
 make_persistent($Release_On)
end on

on note
 $parent_id := $EVENT_ID

{do your note on stuff}

 _reset_rls_trig_counter($EVENT_NOTE)
end on

on release
 note_off ($EVENT_ID)
 disallow_group($ALL_GROUPS)
 $release_group := 0
 if ($EVENT_ID = $parent_id)

{setup up your release groups here}

  while ($release_group <= $NUM_GROUPS-1)
   if (_get_engine_par($ENGINE_PAR_RELEASE_TRIGGER, $release_group, -1, -1) # 0)
   if ($Release_On = 1)
    allow_group($release_group)
   end if
   end if
   inc($release_group)
  end while

  $rel_voice := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,0)
 end if
 allow_group($ALL_GROUPS)
end on
 
OP
K

KrisY

Noob in frenzy loop
Thanks a lot for your script and time! However, I have a lot of groups and they all have to use tables to set the volume adjustments, as samples are of very different length across the keyboard. This is definitely beyond my own skills at the time. Also, using your script, which is a slam dunk to use as is, I´d need to do some extensive coding to compensate for my sample´s length differences.

I have therefore decided, to use group start options to shut the groups on and off. The groups will be controlled with controller CC 119 instead. This way I can control any group with this and split up my groups to use the internal group modulator "release trigger counter" in their unique way, to suit the length of my samples.

Perhaps at a later time I´ll have a look at your script again and see if I could fit it together. For now it´s anyway useful for me to put into another script I´m working on. The while loop seems to work in there with minimal changes. Thanks!
 

Fredeke

Active Member
Here's one I wrote quite some time ago that can be altered to your needs.

Code:
on init
 SET_CONDITION(NO_SYS_SCRIPT_RLS_TRIG)
 declare $normal_group {normal groups}
 declare $release_group {release groups}
 declare $parent_id
 declare $rel_voice
 declare ui_button $Note_On
 $Note_On := 1
 make_persistent($Note_On)
 declare ui_button $Release_On
 $Release_On := 0
 make_persistent($Release_On)
end on

on note
 $parent_id := $EVENT_ID
 disallow_group($ALL_GROUPS)
 $normal_group := 0
 while ($normal_group <= $NUM_GROUPS-1)
  if (_get_engine_par($ENGINE_PAR_RELEASE_TRIGGER, $normal_group, -1, -1) = 0)
   if ($Note_On = 1)
    allow_group($normal_group)
   end if
  end if
  inc($normal_group)
 end while
 _reset_rls_trig_counter($EVENT_NOTE)
end on

on release
 note_off ($EVENT_ID)
 disallow_group($ALL_GROUPS)
 $release_group := 0
 if ($EVENT_ID = $parent_id)
  while ($release_group <= $NUM_GROUPS-1)
   if (_get_engine_par($ENGINE_PAR_RELEASE_TRIGGER, $release_group, -1, -1) # 0)
    if ($Release_On = 1)
     allow_group($release_group)
    end if
   end if
   inc($release_group)
  end while
  $rel_voice := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,0)
 end if
 allow_group($ALL_GROUPS)
end on
This may be a newbie question but... Why are some commands prefixed with an underscore?
(like _get_engine_par or _reset_rls_trig_counter)
 

d.healey

Music Monkey
This may be a newbie question but... Why are some commands prefixed with an underscore?
(like _get_engine_par or _reset_rls_trig_counter)
This is to do with old versions of Kontakt. If it has an underscore then the command is from something like Kontakt 2 or 3.
 

ScoringFilm

Active Member
@Fredeke this was indeed written for older Kontakt versions where the underscore was required. It is no longer used in current versions of KSP on Kontakt. You can just delete that underscore, although it will still work with it in place.
 
Top Bottom