in regards to the above discussion, the below code snipped shows the way I
calculate the insert position for MTC quarter messages in the MidiBuffer.
I have shorten it down a bit to make it more understandable e.g. I skipped
all of the time calculations to create the proper quarter messages in this
example. I will provide the “ready to use” class later one once the problem
I have with the below code is solved.
The problem is that with this way of calculating the insert position I occasionally
hit the buffersize of the Midibuffer which triggers an assertion in juce_VST_Wrapper line 570.
In my humble understanding that should never happen but it does. I guess it has
something to do with rounding problems so I played arround with roundToInt
or roundDoubleToInt or at least the normal round function for the integer
but without success. the only way I could get it to work is to use a quite nasty
Overall, with the hack it works quite well and Cubase sticks to Ableton like a charme but
I don’t like this hack!
Could someone have a look what could cause the problem?
void JK_MidiSync::generateMidiSync(AudioPlayHead::CurrentPositionInfo &lastPosInfo,
const int pluginSendsSync,
const int bufferSize, //Size of the AudioSampleBuffer, provided by processBlock, in this case it is 80
const double sampleRate) //provided by processBlock, in this case it is 44100.0
if (lastPosInfo.isPlaying || lastPosInfo.isRecording)
const double frameRate = 24.0;
const double ppqPerSample = 1.0 / (sampleRate / (lastPosInfo.bpm / 60.0));
const double bufferSizeInPPQ = (double)(bufferSize) * ppqPerSample;
const int quarterMsgDistanceInSamples = roundToInt(sampleRate / (4.0 * frameRate));
//Run through the Midi buffer to inject timecode messages on certain positions
for (double i = lastPosInfo.ppqPosition; i < lastPosInfo.ppqPosition + bufferSizeInPPQ; i += ppqPerSample)
if ((pluginSendsSync & 0x1) == 1)
//get the virtual position in samples and the sample position of the
//start of the processblock to calculate the inject position in the buffer
const int virtualSamplePos = (int)((i * 60.0 / lastPosInfo.bpm) * sampleRate);
const int currentSamplePos = (int)((lastPosInfo.ppqPosition * 60.0 / lastPosInfo.bpm) * sampleRate);
//Inject quarter messages
if (virtualSamplePos % quarterMsgDistanceInSamples == 0)
int insertPos = virtualSamplePos - currentSamplePos;
if (insertPos >= bufferSize)
insertPos = bufferSize - 1;
//do the inject in the MidiBuffer here...