2 Copyright (C) 2006 Paul Davis
3 Written by Dave Robillard, 2006
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <ardour/midi_model.h>
23 #include <ardour/types.h>
26 using namespace ARDOUR;
29 MidiModel::MidiModel(size_t size)
34 MidiModel::~MidiModel()
36 for (size_t i=0; i < _events.size(); ++i)
37 delete _events[i].buffer;
41 /** Append contents of \a buf to model. NOT realtime safe.
43 * Timestamps of events in \a buf are expected to be relative to
44 * the start of this model (t=0) and MUST be monotonically increasing
45 * and MUST be >= the latest event currently in the model.
47 * Events in buf are deep copied.
50 MidiModel::append(const MidiBuffer& buf)
52 for (size_t i=0; i < buf.size(); ++i) {
53 const MidiEvent& buf_event = buf[i];
54 assert(_events.empty() || buf_event.time >= _events.back().time);
56 _events.push_back(buf_event);
57 MidiEvent& my_event = _events.back();
58 assert(my_event.time == buf_event.time);
59 assert(my_event.size == buf_event.size);
61 my_event.buffer = new Byte[my_event.size];
62 memcpy(my_event.buffer, buf_event.buffer, my_event.size);
67 /** Append \a in_event to model. NOT realtime safe.
69 * Timestamps of events in \a buf are expected to be relative to
70 * the start of this model (t=0) and MUST be monotonically increasing
71 * and MUST be >= the latest event currently in the model.
74 MidiModel::append(double time, size_t size, Byte* in_buffer)
76 assert(_events.empty() || time >= _events.back().time);
78 //cerr << "Model event: time = " << time << endl;
80 Byte* my_buffer = new Byte[size];
81 memcpy(my_buffer, in_buffer, size);
82 _events.push_back(MidiEvent(time, size, my_buffer));