summaryrefslogtreecommitdiff
path: root/src/drumgizmo.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2015-02-08 10:44:33 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2015-02-08 10:44:33 +0100
commit4e216965d026c7db0af5626d07657db3c5421351 (patch)
tree559413a10b346ddaf6af0c9579cd4d43667fb658 /src/drumgizmo.cc
parent711c3124bb939a8edfa8e483001307826d0c5d86 (diff)
Delay TYPE_STOP event until the last active samples are done playing.
Diffstat (limited to 'src/drumgizmo.cc')
-rw-r--r--src/drumgizmo.cc19
1 files changed, 18 insertions, 1 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;
+ }
}
}