diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/drumgizmo.cc | 23 | ||||
-rw-r--r-- | src/drumgizmo.h | 13 |
2 files changed, 24 insertions, 12 deletions
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index 5d7de70..2f2232c 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -49,6 +49,7 @@ DrumGizmo::DrumGizmo(AudioOutputEngine *o, AudioInputEngine *i) : MessageReceiver(MSGRCV_ENGINE), loader(), oe(o), ie(i) { + is_stopping = false; } DrumGizmo::~DrumGizmo() @@ -86,10 +87,8 @@ bool DrumGizmo::loadkit(std::string file) return true; } -bool DrumGizmo::init(bool preload) +bool DrumGizmo::init() { - (void)preload; - if(!ie->init(kit.instruments)) return false; if(!oe->init(kit.channels)) return false; @@ -257,7 +256,23 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples) } if(evs[e].type == TYPE_STOP) { - return false; + is_stopping = true; + } + + if(is_stopping) { + // Count the number of active events. + int num_active_events = 0; + Channels::iterator j = kit.channels.begin(); + while(j != kit.channels.end()) { + Channel &ch = *j; + num_active_events += activeevents[ch.num].size(); + j++; + } + + if(num_active_events == 0) { + // No more active events - now we can stop the engine. + return false; + } } } diff --git a/src/drumgizmo.h b/src/drumgizmo.h index 138e61c..f8d45f5 100644 --- a/src/drumgizmo.h +++ b/src/drumgizmo.h @@ -51,14 +51,13 @@ class DrumGizmo : public MessageReceiver { public: - DrumGizmo(AudioOutputEngine *outputengine, - AudioInputEngine *inputengine); + DrumGizmo(AudioOutputEngine *outputengine, AudioInputEngine *inputengine); virtual ~DrumGizmo(); bool loadkit(std::string kitfile); - bool init(bool preload = true); - + bool init(); + /** * @param endpos number of samples to process, -1 := never stop. */ @@ -68,8 +67,6 @@ public: void getSamples(int ch, int pos, sample_t *s, size_t sz); - bool isRunning() { return is_running; } - std::string configString(); bool setConfigString(std::string cfg); @@ -77,12 +74,12 @@ public: int samplerate(); void setSamplerate(int samplerate); - + private: DrumKitLoader loader; Mutex mutex; - bool is_running; + bool is_stopping; ///< Is set to true when a TYPE_STOP event has been seen. AudioOutputEngine *oe; AudioInputEngine *ie; |