diff options
author | David Robillard <d@drobilla.net> | 2008-09-22 16:28:02 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2008-09-22 16:28:02 +0000 |
commit | a2d2f738cb63dbf0fb89e0a00c424ce883fb7888 (patch) | |
tree | 8ff8b9067a8884566b023de2dabedc2b57b856ab /libs/evoral/evoral/Event.hpp | |
parent | ff2d51ddd8288ec967efab2cb8192f43c893909e (diff) |
Move event specific ringbuffer stuff to evoral.
Sane event type interface between evoral and libardour (no more shared magic numbers).
Cleanup Evoral::Sequence iterator, fix bugs, probably introduce new ones.
Move MIDI specific event functions to Evoral::MIDIEvent (is-a Evoral::Event).
git-svn-id: svn://localhost/ardour2/branches/3.0@3785 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/evoral/evoral/Event.hpp')
-rw-r--r-- | libs/evoral/evoral/Event.hpp | 103 |
1 files changed, 37 insertions, 66 deletions
diff --git a/libs/evoral/evoral/Event.hpp b/libs/evoral/evoral/Event.hpp index beffb01eb5..1dd081a5b9 100644 --- a/libs/evoral/evoral/Event.hpp +++ b/libs/evoral/evoral/Event.hpp @@ -24,52 +24,39 @@ #include <cstring> #include <sstream> #include <assert.h> -#include <evoral/midi_events.h> -#ifdef EVENT_WITH_XML - #include <pbd/xml++.h> -#endif +#include <evoral/types.hpp> + /** If this is not defined, all methods of MidiEvent are RT safe * but MidiEvent will never deep copy and (depending on the scenario) * may not be usable in STL containers, signals, etc. */ -#define EVENT_ALLOW_ALLOC 1 - -//#define EVENT_WITH_XML +#define EVORAL_EVENT_ALLOC 1 namespace Evoral { -/** Identical to jack_midi_event_t, but with double timestamp +/** An event (much like a type generic jack_midi_event_t) * * time is either a frame time (from/to Jack) or a beat time (internal * tempo time, used in MidiModel) depending on context. */ struct Event { -#ifdef EVENT_ALLOW_ALLOC - Event(double t=0, uint32_t s=0, uint8_t* b=NULL, bool owns_buffer=false); +#ifdef EVORAL_EVENT_ALLOC + Event(EventType type=0, EventTime t=0, uint32_t s=0, uint8_t* b=NULL, bool alloc=false); /** Copy \a copy. * - * If \a owns_buffer is true, the buffer will be copied and this method + * If \a alloc is true, the buffer will be copied and this method * is NOT REALTIME SAFE. Otherwise both events share a buffer and * memory management semantics are the caller's problem. */ - Event(const Event& copy, bool owns_buffer); - -#ifdef EVENT_WITH_XML - /** Event from XML ala http://www.midi.org/dtds/MIDIEvents10.dtd - */ - Event(const XMLNode& event); - - /** Event to XML ala http://www.midi.org/dtds/MIDIEvents10.dtd - */ - boost::shared_ptr<XMLNode> to_xml() const; -#endif + Event(const Event& copy, bool alloc); ~Event(); inline const Event& operator=(const Event& copy) { + _type = copy._type; _time = copy._time; if (_owns_buffer) { if (copy._buffer) { @@ -96,12 +83,13 @@ struct Event { _owns_buffer = false; } + _type = copy._type; _time = copy._time; _size = copy._size; _buffer = copy._buffer; } - inline void set(uint8_t* buf, size_t size, double t) { + inline void set(uint8_t* buf, uint32_t size, EventTime t) { if (_owns_buffer) { if (_size < size) { _buffer = (uint8_t*) ::realloc(_buffer, size); @@ -111,11 +99,14 @@ struct Event { _buffer = buf; } - _size = size; _time = t; + _size = size; } inline bool operator==(const Event& other) const { + if (_type != other._type) + return false; + if (_time != other._time) return false; @@ -125,7 +116,7 @@ struct Event { if (_buffer == other._buffer) return true; - for (size_t i=0; i < _size; ++i) + for (uint32_t i=0; i < _size; ++i) if (_buffer[i] != other._buffer[i]) return false; @@ -136,7 +127,7 @@ struct Event { inline bool owns_buffer() const { return _owns_buffer; } - inline void set_buffer(size_t size, uint8_t* buf, bool own) { + inline void set_buffer(uint32_t size, uint8_t* buf, bool own) { if (_owns_buffer) { free(_buffer); _buffer = NULL; @@ -146,7 +137,7 @@ struct Event { _owns_buffer = own; } - inline void realloc(size_t size) { + inline void realloc(uint32_t size) { if (_owns_buffer) { if (size > _size) _buffer = (uint8_t*) ::realloc(_buffer, size); @@ -157,57 +148,37 @@ struct Event { _size = size; } - + + inline void clear() { + _type = 0; + _time = 0; + _size = 0; + _buffer = NULL; + } #else inline void set_buffer(uint8_t* buf) { _buffer = buf; } -#endif // EVENT_ALLOW_ALLOC +#endif // EVORAL_EVENT_ALLOC - inline double time() const { return _time; } - inline double& time() { return _time; } + inline EventType event_type() const { return _type; } + inline void set_event_type(EventType t) { _type = t; } + inline EventTime time() const { return _time; } + inline EventTime& time() { return _time; } inline uint32_t size() const { return _size; } inline uint32_t& size() { return _size; } - inline uint8_t type() const { return (_buffer[0] & 0xF0); } - inline void set_type(uint8_t type) { _buffer[0] = (0x0F & _buffer[0]) - | (0xF0 & type); } - inline uint8_t channel() const { return (_buffer[0] & 0x0F); } - inline void set_channel(uint8_t channel) { _buffer[0] = (0xF0 & _buffer[0]) - | (0x0F & channel); } - inline bool is_note_on() const { return (type() == MIDI_CMD_NOTE_ON); } - inline bool is_note_off() const { return (type() == MIDI_CMD_NOTE_OFF); } - inline bool is_cc() const { return (type() == MIDI_CMD_CONTROL); } - inline bool is_pitch_bender() const { return (type() == MIDI_CMD_BENDER); } - inline bool is_pgm_change() const { return (type() == MIDI_CMD_PGM_CHANGE); } - inline bool is_note() const { return (is_note_on() || is_note_off()); } - inline bool is_aftertouch() const { return (type() == MIDI_CMD_NOTE_PRESSURE); } - inline bool is_channel_aftertouch() const { return (type() == MIDI_CMD_CHANNEL_PRESSURE); } - inline uint8_t note() const { return (_buffer[1]); } - inline uint8_t velocity() const { return (_buffer[2]); } - inline uint8_t cc_number() const { return (_buffer[1]); } - inline uint8_t cc_value() const { return (_buffer[2]); } - inline uint8_t pitch_bender_lsb() const { return (_buffer[1]); } - inline uint8_t pitch_bender_msb() const { return (_buffer[2]); } - inline uint16_t pitch_bender_value() const { return ( ((0x7F & _buffer[2]) << 7) - | (0x7F & _buffer[1]) ); } - inline uint8_t pgm_number() const { return (_buffer[1]); } - inline void set_pgm_number(uint8_t number){ _buffer[1] = number; } - inline uint8_t aftertouch() const { return (_buffer[1]); } - inline uint8_t channel_aftertouch() const { return (_buffer[1]); } - inline bool is_channel_event() const { return (0x80 <= type()) && (type() <= 0xE0); } - inline bool is_smf_meta_event() const { return _buffer[0] == 0xFF; } - inline bool is_sysex() const { return _buffer[0] == 0xF0 - || _buffer[0] == 0xF7; } + inline const uint8_t* buffer() const { return _buffer; } inline uint8_t*& buffer() { return _buffer; } -private: - double _time; /**< Sample index (or beat time) at which event is valid */ - uint32_t _size; /**< Number of uint8_ts of data in \a buffer */ - uint8_t* _buffer; /**< Raw MIDI data */ +protected: + EventType _type; /**< Type of event (application relative, NOT MIDI 'type') */ + EventTime _time; /**< Sample index (or beat time) at which event is valid */ + uint32_t _size; /**< Number of uint8_ts of data in \a buffer */ + uint8_t* _buffer; /**< Raw MIDI data */ -#ifdef EVENT_ALLOW_ALLOC +#ifdef EVORAL_EVENT_ALLOC bool _owns_buffer; /**< Whether buffer is locally allocated */ #endif }; |