Page 1 of 2

Midiout delay?

Posted: 17 Dec 2011 00:36
by kraftf
How can a midiout message be delayed in a script?
I guess the time function has to be used. Can someone please help me out this?

Re: Midiout delay?

Posted: 17 Dec 2011 23:10
by mbncp
Haven't play with that yet, but basically you need an OnFrame script, which is called about 60 times per second, but depends of the complexity of the project.
Then some variables (expression) to store the time you want the midi out and one to store the midi out message.

It can become a little tricky if you excpect more than one message to be delayed and at different time.

Re: Midiout delay?

Posted: 18 Dec 2011 02:22
by kraftf
I just want to delay the noteoff message that is attached to the noteon in a script.
In other words I want to define the hold/decay parameter of the note on. Still I can't see how I can use the frame function. It would have been a lot easier if there was a function to stall the script for a specific amount of time.
Maybe I should give a look at the sequencer examples. They surely use time functions.

Re: Midiout delay?

Posted: 18 Dec 2011 06:21
by armatronix
You'll have to figure out the syntax, but you should be able to do something like this:

on a noteon event
...send a noteon
...oldTime = time
...trigger = true
if trigger == true and time-oldTime >= hold
...send a noteoff
...trigger = false

You probably can also do it with a multiball using its adsr.

Hope this helps.

Re: Midiout delay?

Posted: 18 Dec 2011 14:37
by Macciza
Hi
Wouldn't it be better to use the time function which would allow you to set i more accurately?
MM

Re: Midiout delay?

Posted: 18 Dec 2011 19:07
by kraftf
Thanks very nuch for the suggestions.
I'll try them and let you know about the results.

Re: Midiout delay?

Posted: 19 Dec 2011 02:35
by kraftf
Well I didn't actually try your suggestions.
I would like to decribe my situation a little bit more.
I am having a for loop sending out midiout sysex events in a script.
It's a button which scans a multislider's vector values and sends 16 different sysex messages. What I am asking is if it is possible to dealy the actual for loop. Instead of sending instantly all the 16 messages to pause for an amount of time inside the for loop.
Is it possible to di this with the time function.
Any ideas?
I am attatching this multislider.
Another problem I have is that I cannot send simultaneously more than fader because one variable inside the sysex message that corresponds to the midi channel gets stuck to the prevailing fader that moves.
I know I can setup 16 different messages and assign expicitly all the items of the vector but I don't want to do that.

Re: Midiout delay?

Posted: 19 Dec 2011 09:39
by mbncp
AFAIK there is no sleep function in Lemur.
The only option I see as I stated before is to use an OnFrame script. You can use it together with the time function.
So instead of having your for loop, create a variable and set it to 16 when you need to send your sysex.
Decrease this value by one each time until it reaches 0.

Actually instaed of using the on expression trigger it's better to do everything in the on frame script taking care yourself of what has changed.


OnFrame

if( (time- prevtime) < delay) return;

d = A -x;
i = firstof(d);
if(i < sizeof(x))
{
//send your sysex for i;
A = x;
prevtime = time; // reset the timer
}

Re: Midiout delay?

Posted: 24 Dec 2011 07:03
by kraftf
Thanks man for the script.
I am getting into the time scripting idea slowly.
The script works overy well for delaying a message.
However it relys on the timing of Lemur.
To get more specific I am trying to build some pads that send continuus midi notes delayed according to a bpm setting and note value. Like mpc has the note repeat function.
Regarding timing and the delay method that you've kindly suggested it works fine but the problem is that I can't trigger the notes the time that I press the pad. THe notes get triggered according to the internal timimg of Lemur.
How could possibly trgger for eg a sequence of 16th midi notes from pad as long as the pad is being held. I guess I have to find out how the sequencer tempates work. I tried but I couldn't make it.
Any help would be highly appreciated.

Re: Midiout delay?

Posted: 24 Dec 2011 09:23
by mbncp
The idea is the same, if you have a tempo of 100 bpm this means that a beat is played every 0.6 sec (60/100) and as a 1/16 is a quarter of a beat your delay is then 0.15 sec.

The other option is to sync to an external midi clock, in this case you need to watch incoming midi clock values. I made a small template that shows how it works somewhere in this forum. As there are 24 midi ticks per beat, trigger a note every 6 ticks for 1/16 th. Note that this method is not very good due to midi jitter, normally a sequencer will use it's internal clock and adjust smoothly to the incomming midi clocks.

To trigger notes only when you press a button, in the on frame script check the state of your button, if it's value is one then send the note(s), otherwise just leave the procedure. But don't forget to send note off or you may have hanging notes.