From 35c4e272e2335e7d3cc49cb310a413ade6631da8 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 26 Sep 2017 20:02:17 -0400 Subject: [PATCH] Added engine pausing/resuming (in sample rate choose menu) --- include/engine.hpp | 1 + src/app/Toolbar.cpp | 10 ++++++++++ src/engine.cpp | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/engine.hpp b/include/engine.hpp index a58572c4..ef5fb65b 100644 --- a/include/engine.hpp +++ b/include/engine.hpp @@ -55,6 +55,7 @@ void engineRemoveWire(Wire *wire); void engineSetParamSmooth(Module *module, int paramId, float value); extern float gSampleRate; +extern bool gPaused; } // namespace rack diff --git a/src/app/Toolbar.cpp b/src/app/Toolbar.cpp index 905a8f3b..e9cbd67d 100644 --- a/src/app/Toolbar.cpp +++ b/src/app/Toolbar.cpp @@ -57,6 +57,12 @@ struct FileChoice : ChoiceButton { }; +struct PauseItem : MenuItem { + void onAction() { + gPaused = !gPaused; + } +}; + struct SampleRateItem : MenuItem { float sampleRate; void onAction() { @@ -70,6 +76,10 @@ struct SampleRateChoice : ChoiceButton { menu->box.pos = getAbsolutePos().plus(Vec(0, box.size.y)); menu->box.size.x = box.size.x; + PauseItem *pauseItem = new PauseItem(); + pauseItem->text = gPaused ? "Resume Engine" : "Pause Engine"; + menu->pushChild(pauseItem); + float sampleRates[] = {44100, 48000, 88200, 96000, 176400, 192000}; int sampleRatesLen = sizeof(sampleRates) / sizeof(sampleRates[0]); for (int i = 0; i < sampleRatesLen; i++) { diff --git a/src/engine.cpp b/src/engine.cpp index 2f21c911..db2c5e0e 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -15,6 +15,7 @@ namespace rack { float gSampleRate; +bool gPaused = false; static bool running = false; @@ -85,7 +86,7 @@ static void engineRun() { while (running) { vipMutex.wait(); - { + if (!gPaused) { std::lock_guard lock(mutex); for (int i = 0; i < mutexSteps; i++) { engineStep();