Jump to content

How do I delay/sync a midi note played from a keyboard to the next 16th notes in Logic?

Go to solution Solved by jaffasplaffa,

Recommended Posts

Hello :)

I would like to play a midi note on my keyboard, which is then delayed and synced to next 1/16(16th note), so it plays exactly on next 16th note.

I found a script that does it for a quarter note(1/4), the script called "Delay Notes Until Next Beat", which uses "sendAtBeat". But yeah, as it hints, it only works for 1/4 notes, beats, not 16th notes. I did try to edit it a bit, with no luck.

Do anyone have a suggestion to how I can do the same as the "Delay Notes Until Next Beat" script, but instead "Delay Notes Until Next 16th notes"?

Thanks in advance!

Edited by jaffasplaffa
Link to comment
Share on other sites

  • jaffasplaffa changed the title to How do I delay/sync a midi note played from a keyboard to the next 16th notes in Logic?

You can tweak the script you are working it..  just remember that in Script a beat is a numeric value, 1 per beat..and its fractional.  So whatever that script is doing to round up to the next beat, you can round it to the nearest 0.25 beat value..will require you to work out the math.  an easy way off the top of my head would be to look at whatever math is in that script that calculates the next beat value to use.  Multiply it by 4, calculate the value and then divide by 4.  Maybe..   just thinking out loud..but anyway, have a look at it and see if you can figure that out.


  • Like 1
Link to comment
Share on other sites

Here is the script:


var NeedsTimingInfo = true;

function HandleMIDI(e) {
    var info = GetTimingInfo();
    if (e instanceof NoteOn)
    else if (e instanceof NoteOff)
        e.sendAtBeat(Math.ceil(info.blockStartBeat) + 1);

What I understand some of the script does:

It uses the sendAtBeat, which is described like this:
"Send the event at a specific beat in the host’s timeline".

The script takes an input note, then I understand that Math.ceil round any input to the closest HIGHER integer, which would be the next beat.

info.blockStartBeat is described like this:
"Indicates the beat position at the start of the process block".

So what does (Math.ceil(info.blockStartBeat)) exactly do in combination?

I am not really sure. I tried finding out what a process block is defined as, but didn’t really find an answer to that question.

I think I might need to get rid of Math.ceil, since it rounds to integer/beats?


Argh, haven't done any programming in a while, I need to reprogram my brain fro programming again, hehe 🤩


Edited by jaffasplaffa
Link to comment
Share on other sites

See this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil

Yes that rounds up to the next integer.  But that is why its rounding things to the next beat.  If you want rounded up to next 16th, then try as I said..take the blockStartBeat value, multiply it by 4.  Then round it up, then divide it by 4 again.  I'm just thinking out loud, you'll haver to work out any details...

Also I don't know why this script is using the blockStartBeat value..that doesn't make sense to me at all...  So I'm not sure where you got that code from, but anyway, what you are wanting to do is not necessarily trivial to do...  but its definitely possible so keep at it.


Link to comment
Share on other sites

The script is part of the presets for the scripter, so I just choose a preset that made sense to use as a starting point. The preset is called "Delay Notes Until Next Beat".

Yeah I have been trying with some math. Something like this:
        e.sendAtBeat((Math.ceil(info.blockStartBeat)) % 4) * 0.25;

It should do something like this:
1. Use modulo to force the counter to always only count the first 4 beats, 0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3, etc.
Which are quarter notes/beats.

2. Then multiply with 0.25 or divide with 4, so it counts:
0.00, 0.25, 0.50, 0.75, 0.00, 0.25, 0.50, 0.75, 0.00, 0.25, 0.50, 0.75, 0.00, 0.25, 0.50, 0.75.
Which would be 16th notes.

A bit naive, but I thought it might do the trick, cause then I thought it would use 16th notes as reference instead of the quarter notes

Link to comment
Share on other sites

  • Solution

Ahh I looked through all the scripter presets again and found one that works.

The preset is called "Real-time Quantizer". You can set any subdivision.


Thank for the suggestions @Dewdman42 . You were right, from looking at that script, it was definitely not a trivial thing to do. So I am glad I found a way that works out of the box :) 

Edited by jaffasplaffa
  • Like 1
Link to comment
Share on other sites


  • Create New...