diff options
author | David Robillard <d@drobilla.net> | 2011-10-19 18:11:31 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-10-19 18:11:31 +0000 |
commit | 18c2ee4a26f3991c7283744bd7e12cdae33a1297 (patch) | |
tree | ff480e67c8af5bcceadb0894986248fa403b8413 /libs/evoral/evoral | |
parent | a189d3e43bcde3e1b95db8b7d9345ca3e5b9dcaa (diff) |
Remove dubious Evoral::Event methods that exposed non-const references to members.
git-svn-id: svn://localhost/ardour2/branches/3.0@10239 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/evoral/evoral')
-rw-r--r-- | libs/evoral/evoral/Event.hpp | 85 | ||||
-rw-r--r-- | libs/evoral/evoral/Note.hpp | 55 |
2 files changed, 61 insertions, 79 deletions
diff --git a/libs/evoral/evoral/Event.hpp b/libs/evoral/evoral/Event.hpp index 3f27dcb227..d812922afc 100644 --- a/libs/evoral/evoral/Event.hpp +++ b/libs/evoral/evoral/Event.hpp @@ -19,11 +19,12 @@ #ifndef EVORAL_EVENT_HPP #define EVORAL_EVENT_HPP -#include <stdint.h> +#include <assert.h> #include <cstdlib> #include <cstring> #include <sstream> -#include <assert.h> +#include <stdint.h> + #include "evoral/types.hpp" /** If this is not defined, all methods of MidiEvent are RT safe @@ -36,7 +37,7 @@ namespace Evoral { event_id_t event_id_counter(); event_id_t next_event_id(); -void init_event_id_counter (event_id_t n); +void init_event_id_counter(event_id_t n); /** An event (much like a type generic jack_midi_event_t) * @@ -57,43 +58,9 @@ struct Event { ~Event(); - inline const 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; - } + const Event& operator=(const Event& copy); - inline void set(uint8_t* buf, uint32_t size, Time 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; - } + void set(uint8_t* buf, uint32_t size, Time t); inline bool operator==(const Event& other) const { if (_type != other._type) @@ -158,35 +125,31 @@ struct Event { #endif // EVORAL_EVENT_ALLOC - inline EventType event_type() const { return _type; } - inline void set_event_type(EventType t) { _type = t; } - inline Time time() const { return _nominal_time; } - inline Time& time() { return _nominal_time; } - inline Time original_time() const { return _original_time; } - inline Time& original_time() { return _original_time; } - inline uint32_t size() const { return _size; } - inline uint32_t& size() { return _size; } + inline EventType event_type() const { return _type; } + inline Time time() const { return _nominal_time; } + inline Time original_time() const { return _original_time; } + inline uint32_t size() const { return _size; } + inline const uint8_t* buffer() const { return _buf; } + inline uint8_t* buffer() { return _buf; } - inline const uint8_t* buffer() const { return _buf; } - inline uint8_t*& buffer() { return _buf; } + inline void set_event_type(EventType t) { _type = t; } - void set_time (Time); - void set_original_time (Time); + void set_time(Time); + void set_original_time(Time); - inline event_id_t id() const { return _id; } - inline void set_id (event_id_t n) { _id = n; } + inline event_id_t id() const { return _id; } + inline void set_id(event_id_t n) { _id = n; } protected: - EventType _type; /**< Type of event (application relative, NOT MIDI 'type') */ - Time _original_time; /**< Sample index (or beat time) at which event is valid */ - Time _nominal_time; /**< Quantized version of _time, used in preference */ - uint32_t _size; /**< Number of uint8_ts of data in \a buffer */ - uint8_t* _buf; /**< Raw MIDI data */ - + EventType _type; /**< Type of event (application relative, NOT MIDI 'type') */ + Time _original_time; /**< Sample index (or beat time) at which event is valid */ + Time _nominal_time; /**< Quantized version of _time, used in preference */ + uint32_t _size; /**< Number of uint8_ts of data in \a buffer */ + uint8_t* _buf; /**< Raw MIDI data */ + event_id_t _id; /** UUID for each event, should probably be 64bit or at least unsigned */ #ifdef EVORAL_EVENT_ALLOC - bool _owns_buf; /**< Whether buffer is locally allocated */ + bool _owns_buf; /**< Whether buffer is locally allocated */ #endif - event_id_t _id; /** UUID for each event, should probably be 64bit or at least unsigned */ }; } // namespace Evoral diff --git a/libs/evoral/evoral/Note.hpp b/libs/evoral/evoral/Note.hpp index 35b0b18f30..a400137f77 100644 --- a/libs/evoral/evoral/Note.hpp +++ b/libs/evoral/evoral/Note.hpp @@ -51,34 +51,53 @@ public: inline event_id_t id() const { return _on_event.id(); } void set_id (event_id_t); - inline Time time() const { return _on_event.time(); } - inline Time end_time() const { return _off_event.time(); } - inline uint8_t note() const { return _on_event.note(); } - inline uint8_t velocity() const { return _on_event.velocity(); } - inline uint8_t off_velocity() const { return _off_event.velocity(); } - inline Time length() const { return _off_event.time() - _on_event.time(); } - inline uint8_t channel() const { + inline Time time() const { return _on_event.time(); } + inline Time end_time() const { return _off_event.time(); } + inline uint8_t note() const { return _on_event.note(); } + inline uint8_t velocity() const { return _on_event.velocity(); } + inline uint8_t off_velocity() const { return _off_event.velocity(); } + inline Time length() const { return _off_event.time() - _on_event.time(); } + inline uint8_t channel() const { assert(_on_event.channel() == _off_event.channel()); - return _on_event.channel(); + return _on_event.channel(); } - private: - inline int clamp (int val, int low, int high) { return std::min (std::max (val, low), high); } +private: + inline int clamp(int val, int low, int high) { + return std::min (std::max (val, low), high); + } - public: - inline void set_time(Time t) { _off_event.time() = t + length(); _on_event.time() = t; } - inline void set_note(uint8_t n) { uint8_t nn = clamp (n, 0, 127); _on_event.buffer()[1] = nn; _off_event.buffer()[1] = nn; } - inline void set_velocity(uint8_t n) { _on_event.buffer()[2] = clamp (n, 0, 127); } - inline void set_off_velocity(uint8_t n) { _off_event.buffer()[2] = clamp (n, 0, 127); } - inline void set_length(Time l) { _off_event.time() = _on_event.time() + l; } - inline void set_channel(uint8_t c) { uint8_t cc = clamp (c, 0, 16); _on_event.set_channel(cc); _off_event.set_channel(cc); } +public: + inline void set_time(Time t) { + _off_event.set_time(t + length()); + _on_event.set_time(t); + } + inline void set_note(uint8_t n) { + const uint8_t nn = clamp(n, 0, 127); + _on_event.buffer()[1] = nn; + _off_event.buffer()[1] = nn; + } + inline void set_velocity(uint8_t n) { + _on_event.buffer()[2] = clamp(n, 0, 127); + } + inline void set_off_velocity(uint8_t n) { + _off_event.buffer()[2] = clamp(n, 0, 127); + } + inline void set_length(Time l) { + _off_event.set_time(_on_event.time() + l); + } + inline void set_channel(uint8_t c) { + const uint8_t cc = clamp(c, 0, 16); + _on_event.set_channel(cc); + _off_event.set_channel(cc); + } inline Event<Time>& on_event() { return _on_event; } inline const Event<Time>& on_event() const { return _on_event; } inline Event<Time>& off_event() { return _off_event; } inline const Event<Time>& off_event() const { return _off_event; } - private: +private: // Event buffers are self-contained MIDIEvent<Time> _on_event; MIDIEvent<Time> _off_event; |