add channel+pitch indexing for notes in a Sequence
[ardour.git] / libs / evoral / src / Event.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 "evoral/Event.hpp"
20
21 namespace Evoral {
22
23 #ifdef EVORAL_EVENT_ALLOC
24
25 template<typename Timestamp>
26 Event<Timestamp>::Event(EventType type, Timestamp time, uint32_t size, uint8_t* buf, bool alloc)
27         : _type(type)
28         , _original_time(time)
29         , _nominal_time(time)
30         , _size(size)
31         , _buf(buf)
32         , _owns_buf(alloc)
33 {
34         if (alloc) {
35                 _buf = (uint8_t*)malloc(_size);
36                 if (buf) {
37                         memcpy(_buf, buf, _size);
38                 } else {
39                         memset(_buf, 0, _size);
40                 }
41         }
42 }
43
44 template<typename Timestamp>
45 Event<Timestamp>::Event(const Event& copy, bool owns_buf)
46         : _type(copy._type)
47         , _original_time(copy._original_time)
48         , _nominal_time(copy._nominal_time)
49         , _size(copy._size)
50         , _buf(copy._buf)
51         , _owns_buf(owns_buf)
52 {
53         if (owns_buf) {
54                 _buf = (uint8_t*)malloc(_size);
55                 if (copy._buf) {
56                         memcpy(_buf, copy._buf, _size);
57                 } else {
58                         memset(_buf, 0, _size);
59                 }
60         }
61 }
62
63 template<typename Timestamp>
64 Event<Timestamp>::~Event() {
65         if (_owns_buf) {
66                 free(_buf);
67         }
68 }
69
70 #endif // EVORAL_EVENT_ALLOC
71
72 template class Event<Evoral::MusicalTime>;
73 template class Event<uint32_t>;
74
75 } // namespace Evoral
76