X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fevoral%2Fsrc%2FEvent.cpp;h=d0e0e8ac3a4ea9bd22c57a3c4f07d80b9a761aa3;hb=9befa88debe08349deb01ebc00b605721865eda4;hp=783634ff24e23f872a7b079cd8315c22946f2c5b;hpb=f3fc6195bc6136a31b08ffe8c260a64efe77f9dc;p=ardour.git diff --git a/libs/evoral/src/Event.cpp b/libs/evoral/src/Event.cpp index 783634ff24..d0e0e8ac3a 100644 --- a/libs/evoral/src/Event.cpp +++ b/libs/evoral/src/Event.cpp @@ -1,5 +1,5 @@ /* This file is part of Evoral. - * Copyright (C) 2008 Dave Robillard + * Copyright (C) 2008 David Robillard * Copyright (C) 2000-2008 Paul Davis * * Evoral is free software; you can redistribute it and/or modify it under the @@ -26,32 +26,32 @@ static event_id_t _event_id_counter = 0; event_id_t event_id_counter() { - return g_atomic_int_get (&_event_id_counter); + return g_atomic_int_get (&_event_id_counter); } void init_event_id_counter(event_id_t n) { - g_atomic_int_set (&_event_id_counter, n); + g_atomic_int_set (&_event_id_counter, n); } event_id_t next_event_id () { - return g_atomic_int_exchange_and_add (&_event_id_counter, 1); + return g_atomic_int_exchange_and_add (&_event_id_counter, 1); } #ifdef EVORAL_EVENT_ALLOC template Event::Event(EventType type, Timestamp time, uint32_t size, uint8_t* buf, bool alloc) - : _type(type) + : _type(type) , _original_time(time) , _nominal_time(time) , _size(size) , _buf(buf) + , _id(-1) , _owns_buf(alloc) - , _id (-1) { if (alloc) { _buf = (uint8_t*)malloc(_size); @@ -70,8 +70,8 @@ Event::Event(const Event& copy, bool owns_buf) , _nominal_time(copy._nominal_time) , _size(copy._size) , _buf(copy._buf) + , _id(copy.id()) , _owns_buf(owns_buf) - , _id (copy.id()) { if (owns_buf) { _buf = (uint8_t*)malloc(_size); @@ -90,6 +90,50 @@ Event::~Event() { } } +template +const Event& +Event::operator=(const Event& copy) +{ + _id = copy.id(); // XXX is this right? do we want ID copy semantics? + _type = copy._type; + _original_time = copy._original_time; + _nominal_time = copy._nominal_time; + if (_owns_buf) { + if (copy._buf) { + if (copy._size > _size) { + _buf = (uint8_t*)::realloc(_buf, copy._size); + } + memcpy(_buf, copy._buf, copy._size); + } else { + free(_buf); + _buf = NULL; + } + } else { + _buf = copy._buf; + } + + _size = copy._size; + return *this; +} + +template +void +Event::set(uint8_t* buf, uint32_t size, Timestamp t) +{ + if (_owns_buf) { + if (_size < size) { + _buf = (uint8_t*) ::realloc(_buf, size); + } + memcpy (_buf, buf, size); + } else { + _buf = buf; + } + + _original_time = t; + _nominal_time = t; + _size = size; +} + template void Event::set_time (Timestamp t)