f2d369d825ecf0061e0660a9ef2832556d1b7a29
[ardour.git] / libs / evoral / src / Note.cpp
1 /* This file is part of Evoral.
2  * Copyright (C) 2008 David Robillard <http://drobilla.net>
3  * Copyright (C) 2000-2008 Paul Davis
4  *
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
8  * version.
9  *
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.
13  *
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
17  */
18
19 #include <cassert>
20 #include <iostream>
21 #include <limits>
22 #include <glib.h>
23 #ifndef COMPILER_MSVC
24 #include "evoral/Note.hpp"
25 #endif
26
27 #include "evoral/Beats.hpp"
28
29 namespace Evoral {
30
31 template<typename Time>
32 Note<Time>::Note(uint8_t chan, Time t, Time l, uint8_t n, uint8_t v)
33         : _on_event (MIDI_EVENT, t, 3, NULL, true)
34         , _off_event (MIDI_EVENT, t + l, 3, NULL, true)
35 {
36         assert(chan < 16);
37
38         _on_event.buffer()[0] = MIDI_CMD_NOTE_ON + chan;
39         _on_event.buffer()[1] = n;
40         _on_event.buffer()[2] = v;
41
42         _off_event.buffer()[0] = MIDI_CMD_NOTE_OFF + chan;
43         _off_event.buffer()[1] = n;
44         _off_event.buffer()[2] = 0x40;
45
46         assert(time() == t);
47         assert(length() == l);
48         assert(note() == n);
49         assert(velocity() == v);
50         assert(_on_event.channel() == _off_event.channel());
51         assert(channel() == chan);
52 }
53
54
55 template<typename Time>
56 Note<Time>::Note(const Note<Time>& copy)
57         : _on_event(copy._on_event, true)
58         , _off_event(copy._off_event, true)
59 {
60         set_id (copy.id());
61
62         assert(_on_event.buffer());
63         assert(_off_event.buffer());
64         /*
65           assert(copy._on_event.size == 3);
66           _on_event.buffer = _on_event_buffer;
67           memcpy(_on_event_buffer, copy._on_event_buffer, 3);
68
69           assert(copy._off_event.size == 3);
70           _off_event.buffer = _off_event_buffer;
71           memcpy(_off_event_buffer, copy._off_event_buffer, 3);
72         */
73
74         assert(time() == copy.time());
75         assert(end_time() == copy.end_time());
76         assert(length() == copy.length());
77         assert(note() == copy.note());
78         assert(velocity() == copy.velocity());
79         assert(_on_event.channel() == _off_event.channel());
80         assert(channel() == copy.channel());
81 }
82
83 template<typename Time>
84 Note<Time>::~Note()
85 {
86 }
87
88 template<typename Time> void
89 Note<Time>::set_id (event_id_t id)
90 {
91         _on_event.set_id (id);
92         _off_event.set_id (id);
93 }
94
95 template class Note<Evoral::Beats>;
96
97 } // namespace Evoral
98