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_event_h__
22 #define __ardour_midi_event_h__
27 /** Identical to jack_midi_event_t, but with double timestamp
29 * time is either a frame time (from/to Jack) or a beat time (internal
30 * tempo time, used in MidiModel) depending on context.
33 MidiEvent(bool owns_buffer=false, double t=0, size_t s=0, Byte* b=NULL)
34 : _owns_buffer(owns_buffer)
40 _buffer = (Byte*)malloc(_size);
42 memcpy(_buffer, b, _size);
44 memset(_buffer, 0, _size);
48 MidiEvent(const MidiEvent& copy, bool owns_buffer)
49 : _owns_buffer(owns_buffer)
52 , _buffer(copy._buffer)
55 _buffer = (Byte*)malloc(_size);
57 memcpy(_buffer, copy._buffer, _size);
59 memset(_buffer, 0, _size);
68 inline const MidiEvent& operator=(const MidiEvent& copy) {
71 _buffer = copy._buffer;
72 } else if (copy._buffer) {
73 if (!_buffer || _size < copy._size)
74 _buffer = (Byte*)realloc(_buffer, copy._size);
75 memcpy(_buffer, copy._buffer, copy._size);
84 inline bool owns_buffer() const { return _owns_buffer; }
85 inline double time() const { return _time; }
86 inline double& time() { return _time; }
87 inline size_t size() const { return _size; }
88 inline size_t& size() { return _size; }
89 inline uint8_t type() const { return (_buffer[0] & 0xF0); }
90 inline uint8_t note() const { return (_buffer[1]); }
91 inline uint8_t velocity() const { return (_buffer[2]); }
92 inline const Byte* buffer() const { return _buffer; }
93 inline Byte* buffer() { return _buffer; }
95 void set_buffer(Byte* buf) { assert(!_owns_buffer); _buffer = buf; }
98 bool _owns_buffer; /**< Whether buffer is locally allocated */
99 double _time; /**< Sample index (or beat time) at which event is valid */
100 size_t _size; /**< Number of bytes of data in \a buffer */
101 Byte* _buffer; /**< Raw MIDI data */
105 } // namespace ARDOUR
107 #endif /* __ardour_midi_event_h__ */