diff --git a/source/native-plugins/midi-base.hpp b/source/native-plugins/midi-base.hpp index 0497cee9a..2dd71a025 100644 --- a/source/native-plugins/midi-base.hpp +++ b/source/native-plugins/midi-base.hpp @@ -233,6 +233,8 @@ public: void play(long double timePosFrame, const double frames, const double offset = 0.0) { + long double ldtime; + if (! fMutex.tryLock()) return; @@ -244,14 +246,14 @@ public: const RawMidiEvent* const rawMidiEvent(it.getValue(nullptr)); CARLA_SAFE_ASSERT_CONTINUE(rawMidiEvent != nullptr); - if (rawMidiEvent->time < timePosFrame) + ldtime = static_cast(rawMidiEvent->time); + + if (ldtime < timePosFrame) continue; - if (static_cast(rawMidiEvent->time) > timePosFrame + frames) + if (ldtime > timePosFrame + frames) break; - kPlayer->writeMidiEvent(fMidiPort, - static_cast(rawMidiEvent->time) - timePosFrame + offset, - rawMidiEvent); + kPlayer->writeMidiEvent(fMidiPort, ldtime + offset - timePosFrame, rawMidiEvent); } fMutex.unlock();