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