summaryrefslogtreecommitdiff
path: root/libs/ardour/midi_buffer.cc
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-10-20 01:50:15 +0000
committerDavid Robillard <d@drobilla.net>2009-10-20 01:50:15 +0000
commit55ba5c60b331e4bf36d2aaa024038e702ef1bc8d (patch)
treee7ffed838b004109e40a71305624b30b1d493f2e /libs/ardour/midi_buffer.cc
parent09990dd26dec0c878b96361c48d08637cf1d6117 (diff)
Implement out-of-place MidiBuffer::merge.
Completely untested. git-svn-id: svn://localhost/ardour2/branches/3.0@5817 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/midi_buffer.cc')
-rw-r--r--libs/ardour/midi_buffer.cc33
1 files changed, 29 insertions, 4 deletions
diff --git a/libs/ardour/midi_buffer.cc b/libs/ardour/midi_buffer.cc
index 1e41668889..2ff04d111f 100644
--- a/libs/ardour/midi_buffer.cc
+++ b/libs/ardour/midi_buffer.cc
@@ -324,14 +324,39 @@ MidiBuffer::merge(const MidiBuffer& a, const MidiBuffer& b)
_size = 0;
if (this == &a) {
- merge_in_place(b);
+ return merge_in_place(b);
+ } else if (this == &b) {
+ return merge_in_place(a);
}
- if (this == &b) {
- merge_in_place(a);
+ const_iterator ai = a.begin();
+ const_iterator bi = b.begin();
+
+ resize(a.size() + b.size());
+ while (ai != a.end() && bi != b.end()) {
+ if ((*ai).time() < (*bi).time()) {
+ memcpy(_data + _size, (*ai).buffer(), (*ai).size());
+ _size += (*ai).size();
+ ++ai;
+ } else {
+ memcpy(_data + _size, (*bi).buffer(), (*bi).size());
+ _size += (*bi).size();
+ ++bi;
+ }
+ }
+
+ while (ai != a.end()) {
+ memcpy(_data + _size, (*ai).buffer(), (*ai).size());
+ _size += (*ai).size();
+ ++ai;
+ }
+
+ while (bi != b.end()) {
+ memcpy(_data + _size, (*bi).buffer(), (*bi).size());
+ _size += (*bi).size();
+ ++bi;
}
- cerr << "FIXME: MIDI BUFFER MERGE" << endl;
return true;
}