1 /* This file is part of Evoral.
2 * Copyright (C) 2008 David Robillard <http://drobilla.net>
3 * Copyright (C) 2000-2008 Paul Davis
5 * Evoral is free software; you can redistribute it and/or modify it under the
6 * terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option) any later
10 * Evoral is distributed in the hope that it will be useful, but WITHOUT ANY
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "evoral/Note.hpp"
27 #include "evoral/Beats.hpp"
31 template<typename Time>
32 Note<Time>::Note(uint8_t chan, Time t, Time l, uint8_t n, uint8_t v)
34 : _on_event (0xDE, t, 3, NULL, true)
35 , _off_event (0xAD, t + l, 3, NULL, true)
39 _on_event.buffer()[0] = MIDI_CMD_NOTE_ON + chan;
40 _on_event.buffer()[1] = n;
41 _on_event.buffer()[2] = v;
43 _off_event.buffer()[0] = MIDI_CMD_NOTE_OFF + chan;
44 _off_event.buffer()[1] = n;
45 _off_event.buffer()[2] = 0x40;
48 assert(length() == l);
50 assert(velocity() == v);
51 assert(_on_event.channel() == _off_event.channel());
52 assert(channel() == chan);
56 template<typename Time>
57 Note<Time>::Note(const Note<Time>& copy)
58 : _on_event(copy._on_event, true)
59 , _off_event(copy._off_event, true)
63 assert(_on_event.buffer());
64 assert(_off_event.buffer());
66 assert(copy._on_event.size == 3);
67 _on_event.buffer = _on_event_buffer;
68 memcpy(_on_event_buffer, copy._on_event_buffer, 3);
70 assert(copy._off_event.size == 3);
71 _off_event.buffer = _off_event_buffer;
72 memcpy(_off_event_buffer, copy._off_event_buffer, 3);
75 assert(time() == copy.time());
76 assert(end_time() == copy.end_time());
77 assert(length() == copy.length());
78 assert(note() == copy.note());
79 assert(velocity() == copy.velocity());
80 assert(_on_event.channel() == _off_event.channel());
81 assert(channel() == copy.channel());
84 template<typename Time>
89 template<typename Time> void
90 Note<Time>::set_id (event_id_t id)
92 _on_event.set_id (id);
93 _off_event.set_id (id);
96 template<typename Time>
98 Note<Time>::operator=(const Note<Time>& other)
100 _on_event = other._on_event;
101 _off_event = other._off_event;
103 assert(time() == other.time());
104 assert(end_time() == other.end_time());
105 assert(length() == other.length());
106 assert(note() == other.note());
107 assert(velocity() == other.velocity());
108 assert(_on_event.channel() == _off_event.channel());
109 assert(channel() == other.channel());
114 template class Note<Evoral::Beats>;
116 } // namespace Evoral