From 41a6b0ebb6f71032c5a8e69e6aa8c813657224d7 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 27 Jul 2015 19:36:28 +0200 Subject: Add free-wheel mode to LV2 and DrumGizmo class. --- src/cachemanager.cc | 9 ++++++++- src/cachemanager.h | 9 +++++++++ src/drumgizmo.cc | 11 +++++++++++ src/drumgizmo.h | 3 +++ 4 files changed, 31 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/cachemanager.cc b/src/cachemanager.cc index dc4b3e7..4cc1fa5 100644 --- a/src/cachemanager.cc +++ b/src/cachemanager.cc @@ -321,6 +321,14 @@ void CacheManager::setFrameSize(size_t framesize) this->framesize = framesize; } +void CacheManager::setAsyncMode(bool async) +{ + // TODO: Clean out read queue. + // TODO: Block until reader thread is idle, otherwise we might screw up the + // buffers...? + threaded = async; +} + void CacheManager::handleLoadNextEvent(cevent_t &e) { assert(files.find(e.afile->filename) != files.end()); @@ -355,7 +363,6 @@ void CacheManager::handleCloseEvent(cevent_t &e) } } - void CacheManager::handleEvent(cevent_t &e) { switch(e.cmd) { diff --git a/src/cachemanager.h b/src/cachemanager.h index 4fe813e..1660ecf 100644 --- a/src/cachemanager.h +++ b/src/cachemanager.h @@ -130,8 +130,17 @@ public: */ void close(cacheid_t id); + /** + * Set internal framesize used when iterating through cache buffers. + */ void setFrameSize(size_t framesize); + /** + * Control reader thread. + * Set to true to make reading happen threaded, false to do all reading sync. + */ + void setAsyncMode(bool async); + ///! Internal thread main method - needs to be public. void thread_main(); diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index 528b542..5348324 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -51,6 +51,7 @@ DrumGizmo::DrumGizmo(AudioOutputEngine *o, AudioInputEngine *i) , oe(o) , ie(i) , framesize(0) + , freewheel(false) { is_stopping = false; cacheManager.init(1000, true); // start thread @@ -189,6 +190,16 @@ void DrumGizmo::setFrameSize(size_t framesize) } } +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; + cacheManager.setAsyncMode(!freewheel); + } +} + bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples) { setFrameSize(nsamples); diff --git a/src/drumgizmo.h b/src/drumgizmo.h index 807e1e0..240ae9f 100644 --- a/src/drumgizmo.h +++ b/src/drumgizmo.h @@ -77,6 +77,8 @@ public: void setFrameSize(size_t framesize); + void setFreeWheel(bool freewheel); + private: DrumKitLoader loader; @@ -99,4 +101,5 @@ private: DrumKit kit; size_t framesize; + bool freewheel; }; -- cgit v1.2.3