# Workaround script for the K2 release samples bug



## Thonex (Sep 3, 2006)

WOw Nils... THanks for all this.

THese are the kinds of scripts that give me head-aches... keeping track of notes and their states....

Just one question (if I even understand the script's mechanics by looking at it)... wouldn't it be possible to make use of the _get_engine_par($ENGINE_PAR_RELEASE,<group>,<slot>,<generic>) command instead of having a release knob in the gui?

Cheers,

T


----------



## kotori (Sep 3, 2006)

Thonex @ Sun Sep 03 said:


> WOw Nils... THanks for all this.
> 
> THese are the kinds of scripts that give me head-aches... keeping track of notes and their states....


It's not really that difficult in this case, I just pass the $rls_on from 'on note' to 'on release' by using a polyphonic variable. The tricky part is ignoring the release of script generated notes (the $parent_id variable is used for this purpose).



Thonex @ Sun Sep 03 said:


> Just one question (if I even understand the script's mechanics by looking at it)... wouldn't it be possible to make use of the _get_engine_par($ENGINE_PAR_RELEASE,<group>,<slot>,<generic>) command instead of having a release knob in the gui?


$ENGINE_PAR_RELEASE controls the AHDSR envelope. The release decay knob on the other hand is supposed to emulate an external modulator - release-trigger-counter. It would be possible to get that using _get_engine_par($ENGINE_PAR_EXTMOD_INTENSITY,<group>,<slot>,<generic>) but I don't know of any way to determine the slot parameter.

Cheers,
Nils


----------



## Thonex (Sep 3, 2006)

Ah yes... which slot...

It would be cool if K2 would allow you to "declare" $ENGINE_Parameters that you would used in a script... therefore allowing K2 to "seek out" these params dutring the init and have their "location and slot" ready to go upon a call back.

T


----------



## Mahal (Oct 12, 2006)

Well, if I get it right, the release groups have to be the last groups of the instrument in order to make "while ($i <= $first_rls_group-1)" work.

Is there a faster way than copy & paste to a new instrument to reorder groups?

Greetings
Marc


----------



## kotori (Oct 13, 2006)

Mahal @ Thu Oct 12 said:


> Well, if I get it right, the release groups have to be the last groups of the instrument in order to make "while ($i <= $first_rls_group-1)" work.
> 
> Is there a faster way than copy & paste to a new instrument to reorder groups?
> 
> ...



Hi Marc,
Yes you're right that the release groups have to be the last groups. This is just to simplify the categorization - one could extend the script to make it possible for the user to setup a list of release groups. Which instrument are you interested in using the script on?

Btw. No, I don't think there's any other way than copy & paste to reorder groups within Kontakt. 

Cheers,
Nils


----------



## Mahal (Oct 13, 2006)

kotori @ Fri 13 Oct said:


> Which instrument are you interested in using the script on?


Most important at the moment: SampleTekk Black Grand and Scarbee CEP.

BTW: NI support told me that the next update is to come at the end of october.

Greetings
Marc


----------



## kotori (Oct 14, 2006)

Mahal @ Sat Oct 14 said:


> kotori @ Fri 13 Oct said:
> 
> 
> > Which instrument are you interested in using the script on?
> ...



Hi again Marc,
I just tested the above script with Black Grand and it seems to work. Due to some buggy plextor DVD drivers (arrg!) I haven't been able to install CEP yet, but if its release trigger groups are not mixed up with other groups but placed at the end like in Black Grand I think it should work.
It's good to know that NI will fix this, it's a quite serious problem. Thanks for the update.

Cheers,
Nils


----------



## Mahal (Oct 14, 2006)

Hi Nils,

thanks for your help :smile: 

You should really try the CEP, it's great! The only thing that I don't like too much is that all samples start with approximately 5 ms of silence. That increases the overall latency noticeably. But the sound is wonderful!

Concerning the script: CEP has to groups for instrument noise that follow the release groups of the ordinary samples. I think I'll create an instrument with releases only and apply your script there.

Greetings and thanks again
Marc


----------



## Mahal (Oct 14, 2006)

Hi again!

I'm sorry, but I couldn't get your script to work.

Here's a simpler version that works well with the CEP:


```
{*************************************************
Release Mask
Copyright (c) 2006 Marc Halbruegge

This script is free software; you can redistribute it
and/or modify it under the terms of version 2.1 of the
GNU Lesser General Public License as published by the
Free Software Foundation.

This script is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU Lesser General Public License
for more details.
*************************************************}

on init
    declare %lastEventId[128]
end on

on note
    %lastEventId[$EVENT_NOTE] := $EVENT_ID
end on

on release
    if (%lastEventId[$EVENT_NOTE] # $EVENT_ID)
        ignore_event($EVENT_ID)
        fade_out($EVENT_ID,0,1)
    end if
end on
```

Greetings
Marc


----------



## Andy B (Oct 19, 2006)

I'm having trouble with your script Nils. When I disable the release trigger button it seems to mute the output. In other words, the group is lighting up orange on release but I'm not getting any sound....?

It's the last group and I have it selected in the drop down menu part of the script.... any ideas?

Thanks,

Andy.

p.s. Latest version of K2 on Windows XP


----------



## Mr.Scarbee (Nov 23, 2006)

Hi Mahal,

Yes the K2 bug is annoying and unfortunately it still seems to be in K2.2 release.

I put your script in slot 2 and it seemed to work! Now you just hear last notes release sound.

However I can not release an update containing your script as I would violate the GNU Lesser General Public License agreement, so my users will have to wait for NI to fix problem. :cry: 


cheers


----------



## Mr.Scarbee (Nov 23, 2006)

Hi Mahal,

The 5ms contains the "soul" and warmth of the sound. If you cut this away you get a hard more piano-kind of sound... :wink:


----------



## Mr.Scarbee (Nov 23, 2006)

disregard


----------



## Mahal (Nov 23, 2006)

Mr.Scarbee @ Thu 23 Nov said:


> However I can not release an update containing your script as I would violate the GNU Lesser General Public License agreement, so my users will have to wait for NI to fix problem.


Nope. You may use it, distribute it, make money from it, package it with other stuff, and so on. 

The only thing you have to do: If you change the script, you have to keep it in the free software domain, that means: you have to supply the code and the LGPL license.

Greetings
Marc


----------



## kotori (Jan 8, 2007)

Here's an updated version of this script which automatically figures out which groups are release triggers. The advice above to deactivate release triggers does no longer apply. Simply load this script and you're ready to go.


```
{ Script by Nils L to fix the K2 sustain bug which causes release samples
  to be played for sustained notes.
}
on init
  SET_CONDITION(NO_SYS_SCRIPT_RLS_TRIG)
  declare $i
  declare polyphonic $rls_on
  declare polyphonic $parent_id    
  declare ui_label $label1(4,1)
  declare ui_label $label2(4,4)
  set_text($label1, "Kontakt 2 release trigger bug fix script written by Nils Liberg")
  set_text($label2, "This script fixes the Kontakt 2 bug which causes release triggers to be triggered for sustained notes (eg. pressing C3 ten times while holding the sustain pedal will produce ten releases layered on top of each other).")
  message("")
end on

on note
  $parent_id := $EVENT_ID
  if (%CC[64] >= 64)
    $rls_on := 0
  else
    $rls_on := 1
  end if
  disallow_group($ALL_GROUPS)
  $i := 0
  while ($i <= $NUM_GROUPS-1)
    if (_get_engine_par($ENGINE_PAR_RELEASE_TRIGGER, $i, -1, -1) = 0)  { if not release trigger grp }   
      allow_group($i)
    end if
    inc($i)
  end while
  _reset_rls_trig_counter($EVENT_NOTE)
end on

on release  
  if ($EVENT_ID = $parent_id and $rls_on = 1 and %CC[64] < 64)   
    disallow_group($ALL_GROUPS)
    $i := 0
    while ($i <= $NUM_GROUPS-1)
      if (_get_engine_par($ENGINE_PAR_RELEASE_TRIGGER, $i, -1, -1) = 1) { if release trigger grp }     
        allow_group($i)
      end if
      inc($i)
    end while
    play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)   
  end if
end on
```


----------



## jazzphoton (Jan 12, 2007)

Maybe I'm missing something, but release is far too short with kotori's script on Scarbee's CEP, compared to original K2 nki. For example the release of a staccato bass note : with original scarbee's nki, we get a full round and long release, but with kotori's script, there's almost nothing, even if I turn decay knob.


----------



## kotori (Jan 13, 2007)

jazzphoton @ Fri Jan 12 said:


> Maybe I'm missing something, but release is far too short with kotori's script on Scarbee's CEP, compared to original K2 nki. For example the release of a staccato bass note : with original scarbee's nki, we get a full round and long release, but with kotori's script, there's almost nothing, even if I turn decay knob.



Hi,
You're absolutely right. Thanks for pointing this out. I edited the script above (not the first post). The explicit release volume decay should no longer be needed. If this works out (and my tests indicate that it does), the script should now use the release decay of whatever instrument you load it on. Please let me know if this solves the problem for you.

Cheers,
Nils


----------



## jazzphoton (Jan 13, 2007)

Yes, it works now. But there is still some bugs. I explain :
- play a note, release it : OK
- play a note, press sustain pedal down, release note, release sustain pedal : you get one release sample at note releasing and one release sample at pedal releasing.
- press sustain pedal down, play a note, release sustain pedal, release the note : no release sample
- press sustain pedal down, play a note, release the note, release sustain pedal : no release sample too

cheers,
Xavier Bidault


----------



## kotori (Jan 13, 2007)

Hi Xavier
Thanks for that report. I fixed (I hope) the script above so that case two will work. The thought is that one shall get a release sample on pedal release in this case. Or do you think it would be more logical to inhibit the release sample in this case? Please load the script in any other script slot than the first one.

Cheers,
Nils


----------



## jazzphoton (Jan 13, 2007)

Yes, case 2 works now. And no, release samples have not to be inhibited. Sustain pedal acts as if the key wasn't released. But when sustain pedal comes up, the note is dampered and the release sample has to play, more or less loud, according to note length.

And it would be great if you could find something for cases 3 & 4.

Best,
Xavier


----------



## kotori (Jan 13, 2007)

jazzphoton @ Sat Jan 13 said:


> Yes, case 2 works now. And no, release samples have not to be inhibited.


Great!



> Sustain pedal acts as if the key wasn't released. But when sustain pedal comes up, the note is dampered and the release sample has to play, more or less loud, according to note length.


My script should use whatever release counter modulation has been setup for the instrument (I hope).



> And it would be great if you could find something for cases 3 & 4.


Ah, so you want the release sample to sound exactly once in each case then?
My idea was that it would be desirable in only the two first cases because release triggers would then always pair up with a pedal-up sample. Wouldn't pedal down samples need another type of release sample? Maybe I should provide an option to choose between these two behaviours. What do you think?

Cheers,
Nils


----------



## jazzphoton (Jan 13, 2007)

> Wouldn't pedal down samples need another type of release sample? Maybe I should provide an option to choose between these two behaviours. What do you think?


Other release samples would may be better, but I think current ones are enough for a correct behaviour. So, you could add a button as you say.


----------



## kotori (Jan 14, 2007)

jazzphoton @ Sat Jan 13 said:


> Other release samples would may be better, but I think current ones are enough for a correct behaviour. So, you could add a button as you say.



Hmm... say you press the pedal, press C3 ten times and then release the pedal. Now, do you want to hear the release sample corresponding to the first C3, the latest C3 or the C3 that had the highest velocity? If you want to hear the latest I think Marc Halbruegge's script in http://www.northernsounds.com/forum/showthread.php?t=48582 (this thread) at NS does exactly what you want. If you want to hear the one with the highest velocity, I think it would be easiest to adapt his script to do it.

So I think I'll consider leaving my script as it is now. It would be interesting to hear other people's opinion about this as well. What do you prefer - release samples for pedal-down notes or no release samples?

_Edit: I noticed that Marc's script cut-off the release envelope part of all notes but the last one. Any opinions about whether this is good or bad?_

Cheers,
Nils


----------



## Mahal (Feb 10, 2007)

Hi!

I haven't been here for some time. Had to move because of a new job...



kotori @ Sun 14 Jan said:


> ... If you want to hear the latest I think Marc Halbruegge's script in http://www.northernsounds.com/forum/showthread.php?t=48582 (this thread) at NS does exactly what you want. If you want to hear the one with the highest velocity, I think it would be easiest to adapt his script to do it.


The script that you refer to is the same that's in THIS thread at vi 



> Edit: I noticed that Marc's script cut-off the release envelope part of all notes but the last one. Any opinions about whether this is good or bad?


That's exactly what I wanted to have. Typically, the release group of a patch is set to "note mono" to disable the accumulation of release samples. But in the actual versions of Kontakt 2, this doesn't work (it worked before). 
I wrote the script as a workaround for that bug.

Greetings
Marc


----------



## kotori (Feb 10, 2007)

Mahal @ Sat Feb 10 said:


> > Edit: I noticed that Marc's script cut-off the release envelope part of all notes but the last one. Any opinions about whether this is good or bad?
> 
> 
> That's exactly what I wanted to have. Typically, the release group of a patch is set to "note mono" to disable the accumulation of release samples.


Hi Marc,
Thanks for the reply. However, I'm not sure if we're talking about the same thing. I was refering to the release envelope of the main sample (not the release sample), whereas you seems to refer to release samples...
Could you please clarify.

Nils


----------



## Mahal (Feb 10, 2007)

kotori @ Sat 10 Feb said:


> Thanks for the reply. However, I'm not sure if we're talking about the same thing. I was refering to the release envelope of the main sample (not the release sample)


Oops - I didn't get that. My fault.

I just tried to reproduce the behavior that you described, but failed to achieve this. Could you specify which version of Kontakt you're using and which patch you used?

Greetings
Marc


----------



## kotori (Feb 10, 2007)

Mahal @ Sat Feb 10 said:


> kotori @ Sat 10 Feb said:
> 
> 
> > Oops - I didn't get that. My fault.
> ...


First of all I should say that I don't know whether this constitutes a real problem or not. The fade_out is a very clever solution to easily disable the release but it also discards the release phase of the affected notes. Please note that the last note corresponding to a certain pitch is not affected, only the notes for which you silence the release. If you want to hear the effect set up a very long release phase, mute release groups and play a note repeatedly while pressing the pedal. As you release it you will notice that all voices quickly "implode" to just one voice. Maybe this is exactly what's desirable - so I would like to hear other people's opinion about this.
I use the latest version of Kontakt, but I don't think it matters - the script will probably behave the same in all Kontakt 2 version.

Cheers,
Nils


----------



## Mahal (Feb 12, 2007)

... still making up my mind


----------

