diff --git a/source/native-plugins/midi-base.hpp b/source/native-plugins/midi-base.hpp index d61da22f4..0497cee9a 100644 --- a/source/native-plugins/midi-base.hpp +++ b/source/native-plugins/midi-base.hpp @@ -231,7 +231,7 @@ public: play(static_cast(timePosFrame), static_cast(frames)); } - void play(long double timePosFrame, const double frames) + void play(long double timePosFrame, const double frames, const double offset = 0.0) { if (! fMutex.tryLock()) return; @@ -244,12 +244,14 @@ public: const RawMidiEvent* const rawMidiEvent(it.getValue(nullptr)); CARLA_SAFE_ASSERT_CONTINUE(rawMidiEvent != nullptr); - if (timePosFrame > rawMidiEvent->time) - continue; - if (timePosFrame + frames <= rawMidiEvent->time) + if (rawMidiEvent->time < timePosFrame) continue; + if (static_cast(rawMidiEvent->time) > timePosFrame + frames) + break; - kPlayer->writeMidiEvent(fMidiPort, static_cast(rawMidiEvent->time)-timePosFrame, rawMidiEvent); + kPlayer->writeMidiEvent(fMidiPort, + static_cast(rawMidiEvent->time) - timePosFrame + offset, + rawMidiEvent); } fMutex.unlock(); diff --git a/source/native-plugins/midi-pattern.cpp b/source/native-plugins/midi-pattern.cpp index 715eeb3c1..bd37868d4 100644 --- a/source/native-plugins/midi-pattern.cpp +++ b/source/native-plugins/midi-pattern.cpp @@ -263,8 +263,9 @@ protected: } else { - fMidiOut.play(loopedPlayPos, fMaxTicks-loopedPlayPos); - fMidiOut.play(0.0, loopedEndPos); + const double diff = fMaxTicks - loopedPlayPos; + fMidiOut.play(loopedPlayPos, diff); + fMidiOut.play(0.0, loopedEndPos, diff); } } } @@ -353,7 +354,8 @@ protected: midiEvent.size = event->size; #ifdef DEBUG - carla_stdout("Playing at %f :: %03X:%03i:%03i", + carla_stdout("Playing at %f|%u :: %03X:%03i:%03i", + midiEvent.time, static_cast(midiEvent.time)*fTicksPerFrame, midiEvent.data[0], midiEvent.data[1], midiEvent.data[2]); #endif