summaryrefslogtreecommitdiffstats
path: root/src/libs/engine/MidiBuffer.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-09-30 17:36:38 +0000
committerDavid Robillard <d@drobilla.net>2007-09-30 17:36:38 +0000
commitc40ddfc0eebbcb3333d6cc9e3df7fb62ecb45941 (patch)
tree6e73d5d43284335031cee32f9225b698f315a59d /src/libs/engine/MidiBuffer.cpp
parent829075dff9fe5d0b3f243f9e40256563a5f8e09a (diff)
downloadingen-c40ddfc0eebbcb3333d6cc9e3df7fb62ecb45941.tar.gz
ingen-c40ddfc0eebbcb3333d6cc9e3df7fb62ecb45941.tar.bz2
ingen-c40ddfc0eebbcb3333d6cc9e3df7fb62ecb45941.zip
Better driver interface for input/output.
MIDI output (pass-through anyway, plugin->output is still screwy). Fix crash on failure to instantiate LV2 plugin. git-svn-id: http://svn.drobilla.net/lad/ingen@786 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/libs/engine/MidiBuffer.cpp')
-rw-r--r--src/libs/engine/MidiBuffer.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/libs/engine/MidiBuffer.cpp b/src/libs/engine/MidiBuffer.cpp
index 59da7646..618c7476 100644
--- a/src/libs/engine/MidiBuffer.cpp
+++ b/src/libs/engine/MidiBuffer.cpp
@@ -230,5 +230,57 @@ MidiBuffer::get_event(double* timestamp,
}
+/** Clear, and merge \a a and \a b into this buffer.
+ *
+ * FIXME: This is slow.
+ *
+ * \return true if complete merge was successful
+ */
+bool
+MidiBuffer::merge(const MidiBuffer& a, const MidiBuffer& b)
+{
+ // Die if a merge isn't necessary as it's expensive
+ assert(a.size() > 0 && b.size() > 0);
+
+ reset(_this_nframes);
+
+ a.rewind();
+ b.rewind();
+
+ double a_time;
+ uint32_t a_size;
+ unsigned char* a_data;
+
+ double b_time;
+ uint32_t b_size;
+ unsigned char* b_data;
+
+ a.get_event(&a_time, &a_size, &a_data);
+ b.get_event(&b_time, &b_size, &b_data);
+
+ while (true) {
+ if (a_data && (!b_data || (a_time < b_time))) {
+ append(a_time, a_size, a_data);
+ if (a.increment())
+ a.get_event(&a_time, &a_size, &a_data);
+ else
+ a_data = NULL;
+ } else if (b_data) {
+ append(b_time, b_size, b_data);
+ if (b.increment())
+ b.get_event(&b_time, &b_size, &b_data);
+ else
+ b_data = NULL;
+ } else {
+ break;
+ }
+ }
+
+ _latest_stamp = max(a_time, b_time);
+
+ return true;
+}
+
+
} // namespace Ingen