From 43d51948ccae71b8f0a1c1710e25cf36da8d7d7c Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 8 Sep 2006 06:23:25 +0000 Subject: Renamed communications classes for consistency. Removed engine dependency on OSC (mostly). git-svn-id: http://svn.drobilla.net/lad/ingen@120 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/engine/QueuedEventSource.cpp | 36 +++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src/libs/engine/QueuedEventSource.cpp') diff --git a/src/libs/engine/QueuedEventSource.cpp b/src/libs/engine/QueuedEventSource.cpp index 0ef11ac1..915b7811 100644 --- a/src/libs/engine/QueuedEventSource.cpp +++ b/src/libs/engine/QueuedEventSource.cpp @@ -16,6 +16,7 @@ #include "QueuedEventSource.h" #include "QueuedEvent.h" +#include "PostProcessor.h" #include #include using std::cout; using std::cerr; using std::endl; @@ -64,12 +65,43 @@ QueuedEventSource::push_queued(QueuedEvent* const ev) } +/** Process all events for a cycle. + * + * Executed events will be pushed to @a dest. + */ void -QueuedEventSource::push_stamped(Event* const ev) +QueuedEventSource::process(PostProcessor& dest, SampleCount nframes, FrameTime cycle_start, FrameTime cycle_end) { - _stamped_queue.push(ev); + Event* ev = NULL; + + /* Limit the maximum number of queued events to process per cycle. This + * makes the process callback (more) realtime-safe by preventing being + * choked by events coming in faster than they can be processed. + * FIXME: test this and figure out a good value */ + const unsigned int MAX_QUEUED_EVENTS = nframes / 100; + + unsigned int num_events_processed = 0; + + /* FIXME: Merge these next two loops into one */ + + while ((ev = pop_earliest_queued_before(cycle_end))) { + ev->execute(nframes, cycle_start, cycle_end); + dest.push(ev); + if (++num_events_processed > MAX_QUEUED_EVENTS) + break; + } + + while ((ev = pop_earliest_stamped_before(cycle_end))) { + ev->execute(nframes, cycle_start, cycle_end); + dest.push(ev); + ++num_events_processed; + } + + if (num_events_processed > 0) + dest.whip(); } + /** Pops the prepared event at the front of the prepare queue, if it exists. * * This method will only pop events that have been prepared, and are -- cgit v1.2.1