# Kontakt Loop Function



## EVRE15 (May 2, 2014)

Hello,

I’m creating a Kontakt sample library and I’m trying to set a loop function where the attack of a note (a bowed string) will trigger a sustained loop of that same note.

I’m mapping the attack and loop as two separate audio files and placing them in the same key map. Is there a function in Kontakt that will allow me to trigger the loop after it plays the attack? In other words, is there a function in Kontakt that will allow me to trigger audio at a certain time so that both audio files do not play at the same time when pressing the mapped key?


Thank You,

Eva


----------



## RiffWraith (May 3, 2014)

Hi - I am not sure I understand your Q, but I think what you want is to utilize the 'release trigger' function. Unless, I am misunderstanding.

This is in the wrong area, btw - you'd get a lot more help if this were in the Kontakt forum. Maybe a mod can move it there?

Cheers.


----------



## Big Bob (May 3, 2014)

Hi Eva,

There are several ways to achieve this.

Essentially what you want to do is to delay the onset of the sustain samples. One way to do that is to simply edit the sustain samples by inserting some silence at their start. Then if you start the attack samples and the sustain samples both at the same time, the sustain samples won't be heard until their initial silent period has expired.

Another way is use scripting to trigger the sustain samples, either at the same time but with an offset delay or, by having the script provide the offset delay before triggering the sustain samples.

Without more info as to the specifics of what you are trying to do and whether or not you are into scripting, I don't know how to answer your question more precisely.

Rejoice,

Bob


----------



## EVRE15 (May 8, 2014)

Hi Big Bob, 

Thank you for your help. As a matter of fact, I do know how to script in Kontakt. What script line would I need to use to create an offset for the sustained loop? 

By the way, my initial method was to insert silence in the beginning of the sustain loop and overlap the attack and loop in Kontakt. However, I'm finding it extremely tedious to restore the loop points in Kontakt. I think I will have better luck triggering the sustained loop via a script. 

Thank you again for all your help. 


o-[][]-o


----------



## EVRE15 (May 8, 2014)

What do you mean? I'm in the wrong place? Where can I find this Kontakt forum?

Thank you!


----------



## Big Bob (May 8, 2014)

EVRE15 @ Thu May 08 said:


> Hi Big Bob,
> 
> Thank you for your help. As a matter of fact, I do know how to script in Kontakt. What script line would I need to use to create an offset for the sustained loop?
> 
> ...



Here's a simple illustration. I'll assume for simplicity that your attack samples are mapped to MIDI notes 60 to 71 and the sustain counterparts are mapped to MIDI notes 72 to 83. I'll also assume you are using Nils' editor and leave out the dollar signs, etc.


```
on note
   play_note(EVENT_NOTE+12,EVENT_VELOCITY,onset_delay,-1)
end on
```

onset_delay can be a constant if you want a fixed amount, known in advance. Or, you could make it a knob so you can tweak it. If different notes require different onset delays, you could store the delays in an array indexed by the note number, etc.

I should mention that if you are using DFD mode (as opposed to Sampler mode), you will need to make sure you accommodate the sample offset when you setup the zones.

Rejoice,

Bob

*Whoops! I think I may have misunderstood what you wanted to do. Sample start offset won't delay the start of the sample (which I think is what you want to do), it will just move the playback point into the waveform (this is almost the opposite of what I think you must want to do, sorry about that). Please disregard what I suggested above and let me think a bit about the best way you might go about doing what you asked for.*


----------



## mk282 (May 9, 2014)

You got a reply here: http://www.kvraudio.com/forum/viewtopic ... 2&t=410590


----------



## Big Bob (May 9, 2014)

Hi Eva,

After reading Mario's suggestion at the link above, it does seem like maybe that would be the best way to handle your problem. However, if you still want a scripted method, I'll outline one for you here.

Again, for simplicity, let's just assume that your sustain samples are mapped a fixed interval above your attack samples. Thus, the played note + NoteOffset will select the corresponding sustain sample. In my code snippet below, I've simply used NoteOffset = 12 (one octave) but this can be anything you wish. You can also of course put the samples in two different groups with some suitable group allow stuff.

I don't think there is any convenient way for a script to know when the attack sample ends so you will have to specify that in microseconds. And since it may be different for each pitch, you can put these times in an array indexed by pitch. For the code example below, I used an array named *AtkTime*. For simplicity, I made them all one-second so it will be easy to test.

The basic idea is to pause for a specified (and pitch-dependent) time when an attack note is played. So, the NCB begins with a *wait*. At the end of the *wait* period, the corresponding sustain sample is triggered. However, the actual coding is not quite that simple because there are a number of 'corner cases' that have to be provided for. For example, if the played note is shorter than the *AtkTime* you won't want to trigger the sustain sample. Also, you have to deal with the polyphonic NCB re-entrance when another note arrives during the wait period, etc, etc.

I think the following code snippet will more or less do what you want with reasonable safeguards for the corner cases. The way it works can be described as follows:

1. An attack note pitch is played, triggering the NCB.

2. A *wait* of *AtkTime[note]* is inserted.

3. When the *wait* expires, EP0 is examined. Any new event will have this value set to zero. But, if the key is released *before* the AtkTime expires, EP0 will be set to 1 in the RCB. So, if EP0 is still zero when the *wait* expires, the sustain sample is triggered but if EP0 is non-zero, the sustain sample is *not* played.

4. When the played key is released, EP0 is examined in the RCB and if it's still zero, it means that no sustain sample was ever triggered so EP0 is set to 1 to prevent a subsequent sustain sample trigger in the NCB when the wait expires. However, if EP0 is non-zero, it can be assumed to be the sustain note's id and it is used to terminate the sustain sample.

*on init*
``message('')
``*declare* *const* NoteOffset := 12
``*declare* AtkTime[128] := (1000000)
``*declare* id
*end* on

*on note*
``wait(AtkTime[EVENT_NOTE])
``*if* get_event_par(EVENT_ID,EVENT_PAR_0) = 0 _{ if key still down }_
````_{ start the sustain note after AtkTime, tag attack note with sustain id }_
````set_event_par(EVENT_ID,EVENT_PAR_0,play_note(EVENT_NOTE+NoteOffset,EVENT_VELOCITY,0,0))
``*end* *if*
*end* on

*on release*
``_{ played key lifted }_
``id := get_event_par(EVENT_ID,EVENT_PAR_0)``_{ sustain id }_
``*if* id = 0``_{ sustain was never started }_
````set_event_par(EVENT_ID,EVENT_PAR_0,1)````_{ cancel sustain start }_
``*else*
````note_off(id)``_{ terminate sustain }_``
``*end* *if*
*end* on


Rejoice,

Bob


----------

