1 /* This file is part of Evoral.
2 * Copyright (C) 2008 David Robillard <http://drobilla.net>
3 * Copyright (C) 2000-2008 Paul Davis
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
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.
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
21 #include "evoral/Event.hpp"
22 #include "evoral/Beats.hpp"
26 static event_id_t _event_id_counter = 0;
31 return g_atomic_int_get (&_event_id_counter);
35 init_event_id_counter(event_id_t n)
37 g_atomic_int_set (&_event_id_counter, n);
43 /* TODO: handle 31bit overflow , event_id_t is an int32_t,
44 * and libsmf only supports loading uint32_t vlq's, see smf_extract_vlq()
46 * event-IDs only have to be unique per .mid file.
47 * Previously (Ardour 4.2ish) Ardour re-generated those IDs when loading the
48 * file but that lead to .mid files being modified on every load/save.
50 * current user-record: is event-counter="276390506" (just abov 2^28)
52 return g_atomic_int_add (&_event_id_counter, 1);
55 #ifdef EVORAL_EVENT_ALLOC
57 template<typename Timestamp>
58 Event<Timestamp>::Event(EventType type, Timestamp time, uint32_t size, uint8_t* buf, bool alloc)
67 _buf = (uint8_t*)malloc(_size);
69 memcpy(_buf, buf, _size);
71 memset(_buf, 0, _size);
76 template<typename Timestamp>
77 Event<Timestamp>::Event(EventType type,
84 , _buf((uint8_t*)malloc(size))
88 memcpy(_buf, buf, _size);
91 template<typename Timestamp>
92 Event<Timestamp>::Event(const Event& copy, bool owns_buf)
97 , _id (next_event_id ())
101 _buf = (uint8_t*)malloc(_size);
103 memcpy(_buf, copy._buf, _size);
105 memset(_buf, 0, _size);
110 template<typename Timestamp>
111 Event<Timestamp>::~Event() {
117 template<typename Timestamp>
119 Event<Timestamp>::assign(const Event& other)
124 _owns_buf = other._owns_buf;
127 if (other._size > _size) {
128 _buf = (uint8_t*)::realloc(_buf, other._size);
130 memcpy(_buf, other._buf, other._size);
142 template<typename Timestamp>
144 Event<Timestamp>::set (const uint8_t* buf, uint32_t size, Timestamp t)
148 _buf = (uint8_t*) ::realloc(_buf, size);
150 memcpy (_buf, buf, size);
152 /* XXX this is really dangerous given the
153 const-ness of buf. The API should really
156 _buf = const_cast<uint8_t*> (buf);
163 #endif // EVORAL_EVENT_ALLOC
165 template class Event<Evoral::Beats>;
166 template class Event<double>;
167 template class Event<int64_t>;
169 } // namespace Evoral