Hi all!
I need to generate quarter notes, eighth notes, sixteenth notes, etc. in my midi plugin. I made a simply algorithm for this and it works perfectly in the Reaper DAW, but for some reason there are inaccuracies in the Ableton, maybe someone knows what could be the matter?
i’d not use timeInSamples for this, but ppq, cause it’s about musical time intervals rather than time itself. ppq - floor(ppq) will always give you a number between 0 and 1 that describes where in a certain beat you are so you can connect this information with a phasor, which could trigger the addEvent whenever it flips back to 0. you can multiply ppq with some value to change the speed of the phasor. the increment value of the phasor is calculated in a similiar way as you already do, too
Thank you, but how will I be able to do it with sample accuracy? I can only detect PPQ once per buffer… Maybe I didn’t quite understand your idea correctly?
that’s why i suggested syncing up your ppq and bpm data with a phasor. a phasor, as you might know, is a dsp object that just ramps from 0 to 1 continuously. they are often used in oscillators to define where to read from the wavetable and stuff like that. so you’d just have to write the math that uses ppq, bpm and your rate parameter value to get the correct phase and increment value for the phasor and then it works. everytime the phasor goes back from 1 to 0 you know you’re exactly on some beat.
the phase is defined by = ppq * .25 / rateSync with rateSync being some values like .5, 1, 2 etc, you know, whatever describes the change in speed compared to a quarter note. probably what your “rateInNotes” variable does too.
and the increment value for the phasor is = 1 / (barLength * rateSync) with barLength being quarterNoteLength * 4, with quarterNoteLength being sampleRate / beatsPerSec with beatsperSec being bpm / 60