From 8b2fb88f158dee9795923c31aadd4025310d6837 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 18 Sep 2015 17:34:12 +0200 Subject: [PATCH] fix ever increasing MIDI event IDs Iterating over a const Midi-Sequence calls Evoral::Sequence::set_event(), which in turn used Evoral::Event::operator=() which always created a new event-ID (create copy of the event). Issues fixed: - Saving *unmodified* MIDI produced new event-IDs on every save; files changed with every save. - greetings to Deva. - all [GUI] operations that use IDs to refer to notes e.g. undo. invalid undo-history. Also clarify assignment operator name. Prefer explicit assign() over =. --- libs/evoral/evoral/Event.hpp | 2 +- libs/evoral/src/Event.cpp | 27 +++++++++++++-------------- libs/evoral/src/Sequence.cpp | 8 ++++---- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/libs/evoral/evoral/Event.hpp b/libs/evoral/evoral/Event.hpp index ec92d575d0..2a6810a3b4 100644 --- a/libs/evoral/evoral/Event.hpp +++ b/libs/evoral/evoral/Event.hpp @@ -61,7 +61,7 @@ public: ~Event(); - const Event& operator=(const Event& copy); + void assign (const Event& other); void set(const uint8_t* buf, uint32_t size, Time t); diff --git a/libs/evoral/src/Event.cpp b/libs/evoral/src/Event.cpp index 45935ccf8d..680f488596 100644 --- a/libs/evoral/src/Event.cpp +++ b/libs/evoral/src/Event.cpp @@ -107,30 +107,29 @@ Event::~Event() { } template -const Event& -Event::operator=(const Event& copy) +void +Event::assign(const Event& other) { - _id = next_event_id (); - _type = copy._type; - _original_time = copy._original_time; - _nominal_time = copy._nominal_time; - _owns_buf = copy._owns_buf; + _id = other._id; + _type = other._type; + _original_time = other._original_time; + _nominal_time = other._nominal_time; + _owns_buf = other._owns_buf; if (_owns_buf) { - if (copy._buf) { - if (copy._size > _size) { - _buf = (uint8_t*)::realloc(_buf, copy._size); + if (other._buf) { + if (other._size > _size) { + _buf = (uint8_t*)::realloc(_buf, other._size); } - memcpy(_buf, copy._buf, copy._size); + memcpy(_buf, other._buf, other._size); } else { free(_buf); _buf = NULL; } } else { - _buf = copy._buf; + _buf = other._buf; } - _size = copy._size; - return *this; + _size = other._size; } template diff --git a/libs/evoral/src/Sequence.cpp b/libs/evoral/src/Sequence.cpp index e153cea9b4..526256bf5e 100644 --- a/libs/evoral/src/Sequence.cpp +++ b/libs/evoral/src/Sequence.cpp @@ -284,18 +284,18 @@ Sequence