Strip trailing whitespace and fix other whitespace errors (e.g. space/tab mixing...
[ardour.git] / libs / evoral / src / Note.cpp
1 /* This file is part of Evoral.
2  * Copyright (C) 2008 Dave 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 "evoral/Note.hpp"
22
23 namespace Evoral {
24
25 template<typename Time>
26 Note<Time>::Note(uint8_t chan, Time t, Time l, uint8_t n, uint8_t v)
27         // FIXME: types?
28         : _on_event(0xDE, t, 3, NULL, true)
29         , _off_event(0xAD, t + l, 3, NULL, true)
30 {
31         assert(chan < 16);
32
33         _on_event.buffer()[0] = MIDI_CMD_NOTE_ON + chan;
34         _on_event.buffer()[1] = n;
35         _on_event.buffer()[2] = v;
36
37         _off_event.buffer()[0] = MIDI_CMD_NOTE_OFF + chan;
38         _off_event.buffer()[1] = n;
39         _off_event.buffer()[2] = 0x40;
40
41         assert(time() == t);
42         assert(musical_time_equal (length(), l));
43         assert(note() == n);
44         assert(velocity() == v);
45         assert(_on_event.channel() == _off_event.channel());
46         assert(channel() == chan);
47 }
48
49
50 template<typename Time>
51 Note<Time>::Note(const Note<Time>& copy)
52         : _on_event(copy._on_event, true)
53         , _off_event(copy._off_event, true)
54 {
55         assert(_on_event.buffer());
56         assert(_off_event.buffer());
57         /*
58         assert(copy._on_event.size == 3);
59         _on_event.buffer = _on_event_buffer;
60         memcpy(_on_event_buffer, copy._on_event_buffer, 3);
61
62         assert(copy._off_event.size == 3);
63         _off_event.buffer = _off_event_buffer;
64         memcpy(_off_event_buffer, copy._off_event_buffer, 3);
65         */
66
67         assert(time() == copy.time());
68         assert(end_time() == copy.end_time());
69         assert(note() == copy.note());
70         assert(velocity() == copy.velocity());
71         assert(length() == copy.length());
72         assert(_on_event.channel() == _off_event.channel());
73         assert(channel() == copy.channel());
74 }
75
76 template<typename Time>
77 Note<Time>::~Note()
78 {
79 }
80
81 template<typename Time>
82 const Note<Time>&
83 Note<Time>::operator=(const Note<Time>& other)
84 {
85         _on_event = other._on_event;
86         _off_event = other._off_event;
87
88         assert(time() == other.time());
89         assert(end_time() == other.end_time());
90         assert(note() == other.note());
91         assert(velocity() == other.velocity());
92         assert(length() == other.length());
93         assert(_on_event.channel() == _off_event.channel());
94         assert(channel() == other.channel());
95
96         return *this;
97 }
98
99 template class Note<Evoral::MusicalTime>;
100
101 } // namespace Evoral
102