I am new to Juce and tried to answer my question by reading other forum threads and other code, but i wasn’t able to fix the following problem:
I’m trying to expand the arpeggiator from the built-in plugin examples to be synced in e.g. quarter notes.
I am calculating the note length from the sampleRate and the AudioPlayHead::getCurrentPosition BPM.
I figured out, how to calculate the offset of a note in samples, and afaik this has to be passed to the MidiBuffer::addEvent() method.
I logged everything and all the numbers are correct, the AudioPlayHead::positionInfo timeInSamples minus my offset are always a multiple of the calculated note length. (In my case a quarter is 22050 Samples long, 120 bpm at 44100 Hz)
Still though, if i record the midi output of my plugin to a track in Ableton, the notes are placed slightly off the grid, not audible, but visible.
What am i getting wrong? Is there some kind of latency involved, that has to be taken into calculation?
Thanks in advance,
I also tried by getting into the code of LibreArp, an open-source Arppegiator made with Juce, but when you record the output of LibreArp to a Midi Track in Ableton, the notes are not exactly on also.