2 Copyright (C) 2007 Paul Davis
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.
21 #ifndef __ardour_midi_model_h__
22 #define __ardour_midi_model_h__
24 #include <boost/utility.hpp>
25 #include <ardour/types.h>
26 #include <ardour/midi_buffer.h>
30 /** This is a slightly higher level (than MidiBuffer) model of MIDI note data.
31 * Currently it only represents note data, which is represented as complete
32 * note events (ie with a start time and a duration) rather than separate
33 * note on and off events (controller data is not here since it's represented
34 * as an AutomationList)
36 class MidiModel : public boost::noncopyable {
39 Note(double s=0, double d=0, uint8_t n=0, uint8_t v=0)
40 : start(s), duration(d), note(n), velocity(v) {}
48 MidiModel(size_t size=0);
50 void clear() { _notes.clear(); }
53 void end_write(bool delete_stuck=false);
55 /** Resizes vector if necessary (NOT realtime safe) */
56 void append(const MidiBuffer& data);
58 /** Resizes vector if necessary (NOT realtime safe) */
59 void append(double time, size_t size, Byte* in_buffer);
61 inline const Note& note_at(unsigned i) const { return _notes[i]; }
63 inline size_t n_notes() const { return _notes.size(); }
65 typedef std::vector<Note> Notes;
67 struct NoteTimeComparator {
68 inline bool operator() (const Note& a, const Note& b) const {
69 return a.start < b.start;
73 inline Notes& notes() { return _notes; }
74 inline const Notes& notes() const { return _notes; }
78 void append_note_on(double time, uint8_t note, uint8_t velocity);
79 void append_note_off(double time, uint8_t note);
85 } /* namespace ARDOUR */
87 #endif /* __ardour_midi_model_h__ */