From 0ff1cc19018c34dcc37ec1eb16e23d1c443e9e0d Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 21 Aug 2023 03:41:08 -0400 Subject: [PATCH] Add warning when an out-of-order message is sent to midi::InputQueue. --- src/midi.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/midi.cpp b/src/midi.cpp index 92a71617..96fc8629 100644 --- a/src/midi.cpp +++ b/src/midi.cpp @@ -307,8 +307,12 @@ void InputQueue::onMessage(const Message& message) { if (internal->queue.size() >= InputQueue_maxSize) return; // Message timestamp must be monotonically increasing, otherwise clear the queue. - if (!internal->queue.empty() && message.getFrame() < internal->queue.back().getFrame()) { - internal->queue.clear(); + if (!internal->queue.empty()) { + const Message& lastMessage = internal->queue.back(); + if (message.getFrame() < lastMessage.getFrame()) { + WARN("MIDI message at frame %lld added to InputQueue after later message at frame %lld", (long long) message.getFrame(), (long long) lastMessage.getFrame()); + internal->queue.clear(); + } } // Push to queue internal->queue.push_back(message);