While Loops on Release Callbacks (and CC64) Problem

Oneiroi Member Posts: 6 Member

So I have some polyphonic variables that modulate stuff (like tremolo and vibrato) and which speed is dependent upon a $counter variable in a while loop. Something like this :

on init
	declare polyphonic $counter
end on
on release
	while (1 > 0)
		$counter := $counter + 1
	end while
end on

The only problem is: if I play a note with the sustain pedal on, release the note and then release the sustain pedal, the counter will increase twice as fast, because Kontakt triggers 2 release callbacks with the same $EVENT_ID : one for the Note Off event and another for the sustain pedal release. Therefore, my tremolo and vibrato speed go twice as fast.

Is there any way I can get around this without having to change the CC64 parameters in the Instrument options? I want to still be able to use my sustain pedal for sustaining sounds and for other purposes as well.

Maybe something with the listener callback? I'm still unsure as to how I would do it though...



  • Gablux
    Gablux Member Posts: 71 Member

    first question is

    why are you using polyphonic variables for this?

    second question is

    why are you using a loop with 1 > 0 condition?

    it seems there are other ways to achieve what you ware trying to do, but you need to reformulate your question.

    maybe the approach you are using is not the best or even the right one.

  • Oneiroi
    Oneiroi Member Posts: 6 Member

    I'm using polyphonic variables because I want the tremolo and vibrato to be polyphonic.

    My script is huge and includes all sorts of effects, which is why I didn't include it here because it would take a long time to be able to figure what's going on, which is why I'm reducing the problem to its simplest form. I can always join the script if you want to take a look at it though...

    Btw, I'm not a programmer, so I might not have the best programming skill and work method, but so far the script has been working well except for this.

    Obviously the while loop condition was just for the example, in the script the while loop continues until the release time is met.

  • Gablux
    Gablux Member Posts: 71 Member

    What do you mean by the tremolo and vibrato to be polyphonic?

    If you are coding your own tremolo or vibrato, you don't need polyphonic variables for that, even if you apply different settings of either to each voice in Kontakt.

    Polyphonic variables are used for something else.

    No problem not being a programmer. It is common to get caught in much harder ways to do things than they need to be.

    About the while condition: always write exactly what your code is doing, even if you want to write "pseudo-code". There's no way other people will guess what you are trying to do.

    Onto the problem:

    If you want to create the tremolo effect, I believe you know that it is nothing but a volume modulation.

    You can apply that into the entire instrument (via main bus + scripting your own modulators), you can apply to the insert effect path (same way as the main bus), to the busses themselves, to the group level with the added help of pre-built LFOs and sequencer modulators to act on the group volume or into an insert output volume or you could even apply it to each specific event.

    Vibratos are a little more specific, since they involve pitch modulation. That could be achieved on the group level, modulating the tune engine parameter or it could be done modulating the events themselves.

    Each way has a different method to achieve your desired results.

  • EvilDragon
    EvilDragon Moderator Posts: 1,023 mod

    If you want polyphonic tremolo and vibrato, the easiest way is to use Kontakt's LFOs to do that.

  • Oneiroi
    Oneiroi Member Posts: 6 Member

    Thank you both for your replies and apologies for the delay.

    Yes, I'm aware that using Kontakt's modulation parameters might be easier, but the idea behind my script was to create one script that would incorporate all the different effects/modulations that I frequently use and have the set-up all ready simply by adding the script to the instrument (so I don't have to open my instruments and adjust all parameters every time I come up with an idea). Everything works fine with it, except for this one little bug, so I was hoping that something could be done to resolve it.

    Isn't there any line of code that can be written to not make the release pedal trigger the release callback twice and make the counter variable in the while loop increment twice as fast?

Back To Top