MIDI-Remote: 500 ms delay between two commands

How do I program a delay between two key commands in my script, each of which I have set to a custom variable?

...varCustom1.setProcessValue(context, 1)
// here I need a short delay = ca. 500 ms
...varCustom2.setProcessValue(context, 1)

In the API there is something like this:
makeRepeating (delaySeconds : number, rateHz : number) : Repeating

But what exactly does my code above need to look like?


Please avoid using this for this purpose. This is a very useful option when we want continuously change to a parameter or a command execution mainly with buttons. For example, I’m using this for triggering the bar ± command with buttons and it works great.

Now, to your question. As you most probably found out already, there is no “sleep” functionality embedded in the API. So we need to workaround this a bit.

Here’s a snippet based on my Komplete Kontrol MK2 script where I needed to implement double-clicking:

var pseudoTimer=surface.makeCustomProcessVariable("pseudoTimer")
var pseudoTimerPosition=0
var delayMS=500

//Here we trigger the timer, this can be done for example inside the mOnProcessValueChange of our first custom var
var initTime = new Date().getTime()            

            var currentTime=new Date().getTime()
                //we retrigger here  
            else {
                 //trigger here whichever custom var you want



Note that most probably this function will not be of the best accuracy, but I guess it’s ok.

Thanks for your kind help.
This looks good.
I have been looking for something like that.