From 55ba5c60b331e4bf36d2aaa024038e702ef1bc8d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 20 Oct 2009 01:50:15 +0000 Subject: Implement out-of-place MidiBuffer::merge. Completely untested. git-svn-id: svn://localhost/ardour2/branches/3.0@5817 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/midi_buffer.cc | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'libs/ardour/midi_buffer.cc') 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; } -- cgit v1.2.3