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