Here are selected portions of my process method. Think of it as a midi echo.
Shouldn’t this keep time with the host? It doesn’t, it drifts.
It keeps time with itself though.
CurrentPositionInfo pos;
if (getCurrentPositionInfo (pos)){
SampelsPerStep = ((60 / pos.bpm) * getSampleRate()) / timeSig; //0.5 * 44100 / 2
}
SampleCount += input.getNumSamples(); //count number of samples from the input buffer
if(SampleCount >= SampelsPerStep){ //Play
outMidiBuffer.addEvent(MidiMessage::noteOn(1, 64, (uint8)velocity), SampleCount - SampelsPerStep);
SampleCount = 0;
}
inMidiBuffer.clear();
inMidiBuffer = outMidiBuffer;
EDIT:
To clarify my question: Is sample counting not a valid method of timeing, or am I doing it wrong?