From 2247c698d8f7dc5725f4d491e798c5147273ca1e Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 14 Jul 2016 18:51:08 +0200 Subject: Move free-wheel control into the main run method. --- drumgizmo/drumgizmoc.cc | 2 -- src/audiocacheeventhandler.cc | 20 +++----------------- src/audiocacheeventhandler.h | 3 ++- src/drumgizmo.cc | 10 ++++------ test/dgreftest/dgreftest.cc | 3 --- 5 files changed, 9 insertions(+), 29 deletions(-) diff --git a/drumgizmo/drumgizmoc.cc b/drumgizmo/drumgizmoc.cc index a00a623..1ba9516 100644 --- a/drumgizmo/drumgizmoc.cc +++ b/drumgizmo/drumgizmoc.cc @@ -408,8 +408,6 @@ int main(int argc, char* argv[]) { break; } - - gizmo.setFreeWheel(ie->isFreewheeling() && oe->isFreewheeling()); } ie->stop(); diff --git a/src/audiocacheeventhandler.cc b/src/audiocacheeventhandler.cc index a0261a5..a0327b5 100644 --- a/src/audiocacheeventhandler.cc +++ b/src/audiocacheeventhandler.cc @@ -96,26 +96,12 @@ void AudioCacheEventHandler::stop() void AudioCacheEventHandler::setThreaded(bool threaded) { - if(this->threaded == threaded) - { - return; - } - - if(threaded && !running) - { - start(); - } - else if(!threaded && running) - { - stop(); - } - - this->threaded = threaded; + this->threaded.store(threaded); } bool AudioCacheEventHandler::isThreaded() const { - return threaded; + return threaded.load(); } void AudioCacheEventHandler::lock() @@ -279,7 +265,7 @@ void AudioCacheEventHandler::thread_main() void AudioCacheEventHandler::pushEvent(CacheEvent& cache_event) { - if(!threaded) + if(!threaded.load()) { handleEvent(cache_event); return; diff --git a/src/audiocacheeventhandler.h b/src/audiocacheeventhandler.h index 4c0e9d9..7d4ed58 100644 --- a/src/audiocacheeventhandler.h +++ b/src/audiocacheeventhandler.h @@ -28,6 +28,7 @@ #include #include +#include #include "thread.h" #include "semaphore.h" @@ -102,7 +103,7 @@ protected: std::list eventqueue; - bool threaded{false}; + std::atomic threaded{false}; Semaphore sem; Semaphore sem_run; bool running{false}; diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index 14d47a1..b6d464f 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -56,7 +56,7 @@ DrumGizmo::DrumGizmo(Settings& settings, , kit() , input_processor(settings, kit, activeevents) , framesize(0) - , freewheel(false) + , freewheel(true) , events{} , settings(settings) { @@ -110,11 +110,8 @@ void DrumGizmo::setFreeWheel(bool freewheel) { // Freewheel = true means that we are bouncing and therefore running faster // than realtime. - if(freewheel != this->freewheel) - { - this->freewheel = freewheel; - audioCache.setAsyncMode(!freewheel); - } + this->freewheel = freewheel; + audioCache.setAsyncMode(!freewheel); } void DrumGizmo::setRandomSeed(unsigned int seed) @@ -125,6 +122,7 @@ void DrumGizmo::setRandomSeed(unsigned int seed) bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples) { setFrameSize(nsamples); + setFreeWheel(ie.isFreewheeling() && oe.isFreewheeling()); ie.pre(); oe.pre(nsamples); diff --git a/test/dgreftest/dgreftest.cc b/test/dgreftest/dgreftest.cc index 2413ae7..f9eef03 100644 --- a/test/dgreftest/dgreftest.cc +++ b/test/dgreftest/dgreftest.cc @@ -88,7 +88,6 @@ int main(int argc, char* argv[]) DrumGizmo drumgizmo(settings, *oe.get(), ie); drumgizmo.setRandomSeed(seed); - drumgizmo.setFreeWheel(true); // Run in-sync with disk-cache drumgizmo.setFrameSize(oe->getBufferSize()); // settings.enable_resampling.store(false); // Bypass resampler - BROKEN @@ -143,8 +142,6 @@ int main(int argc, char* argv[]) while(drumgizmo.run(pos, samples, nsamples) == true) { pos += nsamples; - - drumgizmo.setFreeWheel(ie.isFreewheeling() && oe->isFreewheeling()); } ie.stop(); -- cgit v1.2.3