summaryrefslogtreecommitdiff
path: root/libs/ardour/midi_buffer.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2009-09-25 05:08:23 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2009-09-25 05:08:23 +0000
commit756fc1839442ae236083c918ba7c7af30e5f8100 (patch)
treed69fc81c25827fa70b905c5ca26c7c7f51ec25bb /libs/ardour/midi_buffer.cc
parentddf532a655ea285287d9f0f0419c97cfa2fbb827 (diff)
implement MidiBuffer::merge_in_place() and use to support MIDI passthrough (control over this feature to be added. historical note: implemented and debugged during keith packard's excellent presentation on X at 25 during LPC2009
git-svn-id: svn://localhost/ardour2/branches/3.0@5686 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/midi_buffer.cc')
-rw-r--r--libs/ardour/midi_buffer.cc53
1 files changed, 51 insertions, 2 deletions
diff --git a/libs/ardour/midi_buffer.cc b/libs/ardour/midi_buffer.cc
index ae3071a53c..1e049eba72 100644
--- a/libs/ardour/midi_buffer.cc
+++ b/libs/ardour/midi_buffer.cc
@@ -260,8 +260,57 @@ MidiBuffer::merge_in_place(const MidiBuffer &other)
cerr << "MidiBuffer::merge failed (no space)" << endl;
return false;
}
-
- cerr << "FIXME: MIDI BUFFER IN-PLACE MERGE" << endl;
+
+ const_iterator them = other.begin();
+ iterator us = begin();
+
+ while (them != other.end()) {
+
+ Evoral::MIDIEvent<TimeType> ev_other (*them);
+ size_t sz = 0;
+ size_t src;
+
+ /* gather up total size of events that are earlier than
+ the event referenced by "us"
+ */
+
+ src = 0;
+
+ while (them != other.end() && ev_other.time() < (*us).time()) {
+ if (!src) {
+ src = them.offset;
+ }
+ sz += sizeof (TimeType) + ev_other.size();
+ ++them;
+ }
+
+ if (sz) {
+ /* move existing */
+ memmove (_data + us.offset + sz, _data + us.offset , _size - us.offset);
+ /* increase _size */
+ _size += sz;
+ /* insert new stuff */
+ memcpy (_data + us.offset, other._data + src, sz);
+ /* update iterator to our own events. this is a miserable hack */
+ us.offset += sz;
+ } else {
+
+ /* advance past our own events to get to the correct insertion
+ point for the next event(s) from "other"
+ */
+
+ while (us != end() && (*us).time() < ev_other.time()) {
+ ++us;
+ }
+ }
+
+ if (!(us != end())) {
+ /* just append the rest of other */
+ memcpy (_data + us.offset, other._data + them.offset, other._size - them.offset);
+ break;
+ }
+ }
+
return true;
}