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_note_h__
22 #define __ardour_note_h__
25 #include <midi++/event.h>
32 * A note is (unfortunately) special and not just another MIDI::Event as it
33 * has a duration and two separate MIDI events (on and off).
37 Note(uint8_t chan=0, double time=0, double dur=0, uint8_t note=0, uint8_t vel=0x40);
38 Note(const Note& copy);
41 const Note& operator=(const Note& copy);
43 inline bool operator==(const Note& other)
44 { return time() == other.time() &&
45 note() == other.note() &&
46 duration() == other.duration() &&
47 velocity() == other.velocity() &&
48 channel() == other.channel();
51 inline double time() const { return _on_event.time(); }
52 inline double end_time() const { return _off_event.time(); }
53 inline uint8_t note() const { return _on_event.note(); }
54 inline uint8_t velocity() const { return _on_event.velocity(); }
55 inline double duration() const { return _off_event.time() - _on_event.time(); }
56 inline uint8_t channel() const {
57 assert(_on_event.channel() == _off_event.channel());
58 return _on_event.channel();
61 inline void set_time(double t) { _off_event.time() = t + duration(); _on_event.time() = t; }
62 inline void set_note(uint8_t n) { _on_event.buffer()[1] = n; _off_event.buffer()[1] = n; }
63 inline void set_velocity(uint8_t n) { _on_event.buffer()[2] = n; }
64 inline void set_duration(double d) { _off_event.time() = _on_event.time() + d; }
65 inline void set_channel(uint8_t c) { _on_event.set_channel(c); _off_event.set_channel(c); }
67 inline MIDI::Event& on_event() { return _on_event; }
68 inline MIDI::Event& off_event() { return _off_event; }
70 inline const MIDI::Event& on_event() const { return _on_event; }
71 inline const MIDI::Event& off_event() const { return _off_event; }
74 // Event buffers are self-contained
75 MIDI::Event _on_event;
76 MIDI::Event _off_event;
82 #endif /* __ardour_note_h__ */