From e6cb593b755645b2d0ae0acd41fd85b41fc7fc7d Mon Sep 17 00:00:00 2001 From: Sebastien Andary Date: Sat, 29 Jan 2022 15:34:07 +0100 Subject: [PATCH] Allow to disable the workaround "unconsumed messages getting stuck in the future". Because this workaround is causing MIDI events drops at low block size settings. --- include/settings.hpp | 1 + src/app/MenuBar.cpp | 3 +++ src/midi.cpp | 13 ++++++++----- src/settings.cpp | 7 +++++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/include/settings.hpp b/include/settings.hpp index 2b7c1a9b..c53f48ca 100644 --- a/include/settings.hpp +++ b/include/settings.hpp @@ -61,6 +61,7 @@ extern float knobLinearSensitivity; extern float knobScrollSensitivity; extern float sampleRate; extern int threadCount; +extern bool disableDawTimeWarpWorkaround; extern bool tooltips; extern bool cpuMeter; extern bool lockModules; diff --git a/src/app/MenuBar.cpp b/src/app/MenuBar.cpp index 8f9ade8c..fd779d19 100644 --- a/src/app/MenuBar.cpp +++ b/src/app/MenuBar.cpp @@ -548,6 +548,9 @@ struct EngineButton : MenuButton { )); } })); + menu->addChild(createCheckMenuItem("Disable DAW time warp workaround", "", + [=]() { return settings::disableDawTimeWarpWorkaround; }, + [=]() { settings::disableDawTimeWarpWorkaround ^= true; })); } }; diff --git a/src/midi.cpp b/src/midi.cpp index 79c9cc0d..f4832c05 100644 --- a/src/midi.cpp +++ b/src/midi.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -339,11 +340,13 @@ bool InputQueue::tryPop(Message* messageOut, int64_t maxFrame) { return true; } - // If next MIDI message is too far in the future, clear the queue. - // This solves the issue of unconsumed messages getting stuck in the future when a DAW rewinds the engine frame. - int futureFrames = 2 * APP->engine->getBlockFrames(); - if (msg.getFrame() - maxFrame > futureFrames) { - internal->queue.clear(); + if (!rack::settings::disableDawTimeWarpWorkaround) { + // If next MIDI message is too far in the future, clear the queue. + // This solves the issue of unconsumed messages getting stuck in the future when a DAW rewinds the engine frame. + int futureFrames = 2 * APP->engine->getBlockFrames(); + if (msg.getFrame() - maxFrame > futureFrames) { + internal->queue.clear(); + } } return false; } diff --git a/src/settings.cpp b/src/settings.cpp index 1fb91691..1a16b87a 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -36,6 +36,7 @@ float knobLinearSensitivity = 0.001f; float knobScrollSensitivity = 0.001f; float sampleRate = 0; int threadCount = 1; +bool disableDawTimeWarpWorkaround = false; bool tooltips = true; bool cpuMeter = false; bool lockModules = false; @@ -137,6 +138,8 @@ json_t* toJson() { json_object_set_new(rootJ, "threadCount", json_integer(threadCount)); + json_object_set_new(rootJ, "disableDawTimeWarpWorkaround", json_boolean(disableDawTimeWarpWorkaround)); + json_object_set_new(rootJ, "tooltips", json_boolean(tooltips)); json_object_set_new(rootJ, "cpuMeter", json_boolean(cpuMeter)); @@ -305,6 +308,10 @@ void fromJson(json_t* rootJ) { if (threadCountJ) threadCount = json_integer_value(threadCountJ); + json_t* disableDawTimeWarpWorkaroundJ = json_object_get(rootJ, "disableDawTimeWarpWorkaround"); + if (disableDawTimeWarpWorkaroundJ) + disableDawTimeWarpWorkaround = json_boolean_value(disableDawTimeWarpWorkaroundJ); + json_t* tooltipsJ = json_object_get(rootJ, "tooltips"); if (tooltipsJ) tooltips = json_boolean_value(tooltipsJ);