Replace half-baked param metadata with descriptor.
[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 <iostream>
20 #include <limits>
21 #include <glib.h>
22 #ifndef COMPILER_MSVC
23 #include "evoral/Note.hpp"
24 #endif
25
26 namespace Evoral {
27
28 template<typename Time>
29 Note<Time>::Note(uint8_t chan, Time t, Time l, uint8_t n, uint8_t v)
30         // FIXME: types?
31         : _on_event (0xDE, t, 3, NULL, true)
32         , _off_event (0xAD, t + l, 3, NULL, true)
33 {
34         assert(chan < 16);
35
36         _on_event.buffer()[0] = MIDI_CMD_NOTE_ON + chan;
37         _on_event.buffer()[1] = n;
38         _on_event.buffer()[2] = v;
39
40         _off_event.buffer()[0] = MIDI_CMD_NOTE_OFF + chan;
41         _off_event.buffer()[1] = n;
42         _off_event.buffer()[2] = 0x40;
43
44         assert(time() == t);
45         assert(length() == l);
46         assert(note() == n);
47         assert(velocity() == v);
48         assert(_on_event.channel() == _off_event.channel());
49         assert(channel() == chan);
50 }
51
52
53 template<typename Time>
54 Note<Time>::Note(const Note<Time>& copy)
55         : _on_event(copy._on_event, true)
56         , _off_event(copy._off_event, true)
57 {
58         set_id (copy.id());
59
60         assert(_on_event.buffer());
61         assert(_off_event.buffer());
62         /*
63           assert(copy._on_event.size == 3);
64           _on_event.buffer = _on_event_buffer;
65           memcpy(_on_event_buffer, copy._on_event_buffer, 3);
66
67           assert(copy._off_event.size == 3);
68           _off_event.buffer = _off_event_buffer;
69           memcpy(_off_event_buffer, copy._off_event_buffer, 3);
70         */
71         
72         assert(time() == copy.time());
73         assert(end_time() == copy.end_time());
74         assert(length() == copy.length());
75         assert(note() == copy.note());
76         assert(velocity() == copy.velocity());
77         assert(_on_event.channel() == _off_event.channel());
78         assert(channel() == copy.channel());
79 }
80
81 template<typename Time>
82 Note<Time>::~Note()
83 {
84 }
85
86 template<typename Time> void
87 Note<Time>::set_id (event_id_t id)
88 {
89         _on_event.set_id (id);
90         _off_event.set_id (id);
91 }
92
93 template<typename Time>
94 const Note<Time>&
95 Note<Time>::operator=(const Note<Time>& other)
96 {
97         _on_event = other._on_event;
98         _off_event = other._off_event;
99
100         assert(time() == other.time());
101         assert(end_time() == other.end_time());
102         assert(length() == other.length());
103         assert(note() == other.note());
104         assert(velocity() == other.velocity());
105         assert(_on_event.channel() == _off_event.channel());
106         assert(channel() == other.channel());
107
108         return *this;
109 }
110
111 template class Note<Evoral::MusicalTime>;
112
113 } // namespace Evoral
114