diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2015-02-08 10:44:33 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2015-02-08 10:44:33 +0100 |
commit | 4e216965d026c7db0af5626d07657db3c5421351 (patch) | |
tree | 559413a10b346ddaf6af0c9579cd4d43667fb658 | |
parent | 711c3124bb939a8edfa8e483001307826d0c5d86 (diff) |
Delay TYPE_STOP event until the last active samples are done playing.
-rw-r--r-- | src/drumgizmo.cc | 19 | ||||
-rw-r--r-- | src/drumgizmo.h | 11 |
2 files changed, 22 insertions, 8 deletions
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index 6b48cda..7fded57 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -47,6 +47,7 @@ DrumGizmo::DrumGizmo(AudioOutputEngine *o, AudioInputEngine *i) : MessageReceiver(MSGRCV_ENGINE), loader(), oe(o), ie(i) { + is_stopping = false; } DrumGizmo::~DrumGizmo() @@ -255,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..403b43e 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); - + /** * @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; |