diff options
author | Hans Baier <hansfbaier@googlemail.com> | 2009-02-10 22:06:56 +0000 |
---|---|---|
committer | Hans Baier <hansfbaier@googlemail.com> | 2009-02-10 22:06:56 +0000 |
commit | 494e7feec64f8b9de42a08ae8e43c7e9df019255 (patch) | |
tree | fa07dd59de53f82e8c36d5305b93c53c4069ced4 /libs/evoral | |
parent | 7666413e1837214f2350330ce1d257a499a9344f (diff) |
* Code readability: Template parameter <T> -> <Time>
git-svn-id: svn://localhost/ardour2/branches/3.0@4521 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/evoral')
-rw-r--r-- | libs/evoral/evoral/Event.hpp | 14 | ||||
-rw-r--r-- | libs/evoral/evoral/EventRingBuffer.hpp | 30 | ||||
-rw-r--r-- | libs/evoral/evoral/EventSink.hpp | 4 | ||||
-rw-r--r-- | libs/evoral/evoral/MIDIEvent.hpp | 12 | ||||
-rw-r--r-- | libs/evoral/evoral/Note.hpp | 28 | ||||
-rw-r--r-- | libs/evoral/evoral/RingBuffer.hpp | 40 | ||||
-rw-r--r-- | libs/evoral/evoral/SMF.hpp | 12 | ||||
-rw-r--r-- | libs/evoral/evoral/Sequence.hpp | 70 | ||||
-rw-r--r-- | libs/evoral/src/MIDIEvent.cpp | 10 | ||||
-rw-r--r-- | libs/evoral/src/Note.cpp | 18 | ||||
-rw-r--r-- | libs/evoral/src/SMF.cpp | 68 | ||||
-rw-r--r-- | libs/evoral/src/Sequence.cpp | 130 |
12 files changed, 218 insertions, 218 deletions
diff --git a/libs/evoral/evoral/Event.hpp b/libs/evoral/evoral/Event.hpp index 0726a21ef5..86a2f146bb 100644 --- a/libs/evoral/evoral/Event.hpp +++ b/libs/evoral/evoral/Event.hpp @@ -38,12 +38,12 @@ namespace Evoral { /** An event (much like a type generic jack_midi_event_t) * - * Template parameter Timestamp is the type of the time stamp used for this event. + * Template parameter Time is the type of the time stamp used for this event. */ -template<typename Timestamp> +template<typename Time> struct Event { #ifdef EVORAL_EVENT_ALLOC - Event(EventType type=0, Timestamp timestamp=0, uint32_t size=0, uint8_t* buffer=NULL, bool alloc=false); + Event(EventType type=0, Time timestamp=0, uint32_t size=0, uint8_t* buffer=NULL, bool alloc=false); /** Copy \a copy. * @@ -89,7 +89,7 @@ struct Event { _buf = copy._buf; } - inline void set(uint8_t* buf, uint32_t size, Timestamp t) { + inline void set(uint8_t* buf, uint32_t size, Time t) { if (_owns_buf) { if (_size < size) { _buf = (uint8_t*) ::realloc(_buf, size); @@ -164,8 +164,8 @@ struct Event { inline EventType event_type() const { return _type; } inline void set_event_type(EventType t) { _type = t; } - inline Timestamp time() const { return _time; } - inline Timestamp& time() { return _time; } + inline Time time() const { return _time; } + inline Time& time() { return _time; } inline uint32_t size() const { return _size; } inline uint32_t& size() { return _size; } @@ -174,7 +174,7 @@ struct Event { protected: EventType _type; /**< Type of event (application relative, NOT MIDI 'type') */ - Timestamp _time; /**< Sample index (or beat time) at which event is valid */ + Time _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* _buf; /**< Raw MIDI data */ diff --git a/libs/evoral/evoral/EventRingBuffer.hpp b/libs/evoral/evoral/EventRingBuffer.hpp index 92d366387f..1ff1a8fe15 100644 --- a/libs/evoral/evoral/EventRingBuffer.hpp +++ b/libs/evoral/evoral/EventRingBuffer.hpp @@ -34,8 +34,8 @@ namespace Evoral { * This packs a timestamp, size, and size bytes of data flat into the buffer. * Useful for MIDI events, OSC messages, etc. */ -template<typename T> -class EventRingBuffer : public Evoral::RingBuffer<uint8_t>, public Evoral::EventSink<T> { +template<typename Time> +class EventRingBuffer : public Evoral::RingBuffer<uint8_t>, public Evoral::EventSink<Time> { public: /** @param capacity Ringbuffer capacity in bytes. @@ -45,27 +45,27 @@ public: size_t capacity() const { return _size; } - bool peek_time(T* time); + bool peek_time(Time* time); - uint32_t write(T time, EventType type, uint32_t size, const uint8_t* buf); - bool read (T* time, EventType* type, uint32_t* size, uint8_t* buf); + uint32_t write(Time time, EventType type, uint32_t size, const uint8_t* buf); + bool read (Time* time, EventType* type, uint32_t* size, uint8_t* buf); }; -template<typename T> +template<typename Time> inline bool -EventRingBuffer<T>::peek_time(T* time) +EventRingBuffer<Time>::peek_time(Time* time) { - bool success = RingBuffer<uint8_t>::full_peek(sizeof(T), (uint8_t*)time); + bool success = RingBuffer<uint8_t>::full_peek(sizeof(Time), (uint8_t*)time); return success; } -template<typename T> +template<typename Time> inline bool -EventRingBuffer<T>::read(T* time, EventType* type, uint32_t* size, uint8_t* buf) +EventRingBuffer<Time>::read(Time* time, EventType* type, uint32_t* size, uint8_t* buf) { - bool success = RingBuffer<uint8_t>::full_read(sizeof(T), (uint8_t*)time); + bool success = RingBuffer<uint8_t>::full_read(sizeof(Time), (uint8_t*)time); if (success) success = RingBuffer<uint8_t>::full_read(sizeof(EventType), (uint8_t*)type); if (success) @@ -77,14 +77,14 @@ EventRingBuffer<T>::read(T* time, EventType* type, uint32_t* size, uint8_t* buf) } -template<typename T> +template<typename Time> inline uint32_t -EventRingBuffer<T>::write(T time, EventType type, uint32_t size, const uint8_t* buf) +EventRingBuffer<Time>::write(Time time, EventType type, uint32_t size, const uint8_t* buf) { - if (write_space() < (sizeof(T) + sizeof(EventType) + sizeof(uint32_t) + size)) { + if (write_space() < (sizeof(Time) + sizeof(EventType) + sizeof(uint32_t) + size)) { return 0; } else { - RingBuffer<uint8_t>::write(sizeof(T), (uint8_t*)&time); + RingBuffer<uint8_t>::write(sizeof(Time), (uint8_t*)&time); RingBuffer<uint8_t>::write(sizeof(EventType), (uint8_t*)&type); RingBuffer<uint8_t>::write(sizeof(uint32_t), (uint8_t*)&size); RingBuffer<uint8_t>::write(size, buf); diff --git a/libs/evoral/evoral/EventSink.hpp b/libs/evoral/evoral/EventSink.hpp index c3a28df754..2fd2e7591a 100644 --- a/libs/evoral/evoral/EventSink.hpp +++ b/libs/evoral/evoral/EventSink.hpp @@ -26,11 +26,11 @@ namespace Evoral { /** Pure virtual base for anything you can write events to. */ -template<typename T> +template<typename Time> class EventSink { public: virtual ~EventSink() {} - virtual uint32_t write(T time, EventType type, uint32_t size, const uint8_t* buf) = 0; + virtual uint32_t write(Time time, EventType type, uint32_t size, const uint8_t* buf) = 0; }; diff --git a/libs/evoral/evoral/MIDIEvent.hpp b/libs/evoral/evoral/MIDIEvent.hpp index 761bfefb24..d6751db0a8 100644 --- a/libs/evoral/evoral/MIDIEvent.hpp +++ b/libs/evoral/evoral/MIDIEvent.hpp @@ -34,14 +34,14 @@ namespace Evoral { * but the application must make sure the event actually contains * valid MIDI data for these functions to make sense. */ -template<typename Timestamp> -struct MIDIEvent : public Event<Timestamp> { - MIDIEvent(EventType type=0, Timestamp timestamp=0, uint32_t size=0, uint8_t* buffer=NULL, bool alloc=false) - : Event<Timestamp>(type, timestamp, size, buffer, alloc) +template<typename Time> +struct MIDIEvent : public Event<Time> { + MIDIEvent(EventType type=0, Time timestamp=0, uint32_t size=0, uint8_t* buffer=NULL, bool alloc=false) + : Event<Time>(type, timestamp, size, buffer, alloc) {} - MIDIEvent(const Event<Timestamp>& copy, bool alloc) - : Event<Timestamp>(copy, alloc) + MIDIEvent(const Event<Time>& copy, bool alloc) + : Event<Time>(copy, alloc) {} #ifdef EVORAL_MIDI_XML diff --git a/libs/evoral/evoral/Note.hpp b/libs/evoral/evoral/Note.hpp index 51d68fe45c..d9d4b070ff 100644 --- a/libs/evoral/evoral/Note.hpp +++ b/libs/evoral/evoral/Note.hpp @@ -29,16 +29,16 @@ namespace Evoral { * * Currently a note is defined as (on event, length, off event). */ -template<typename T> +template<typename Time> class Note { public: - Note(uint8_t chan=0, T time=0, EventLength len=0, uint8_t note=0, uint8_t vel=0x40); - Note(const Note<T>& copy); + Note(uint8_t chan=0, Time time=0, EventLength len=0, uint8_t note=0, uint8_t vel=0x40); + Note(const Note<Time>& copy); ~Note(); - const Note<T>& operator=(const Note<T>& copy); + const Note<Time>& operator=(const Note<Time>& copy); - inline bool operator==(const Note<T>& other) { + inline bool operator==(const Note<Time>& other) { return time() == other.time() && note() == other.note() && length() == other.length() && @@ -46,8 +46,8 @@ public: channel() == other.channel(); } - inline T time() const { return _on_event.time(); } - inline T end_time() const { return _off_event.time(); } + 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 EventLength length() const { return _off_event.time() - _on_event.time(); } @@ -56,21 +56,21 @@ public: return _on_event.channel(); } - inline void set_time(T t) { _off_event.time() = t + length(); _on_event.time() = t; } + inline void set_time(Time t) { _off_event.time() = t + length(); _on_event.time() = t; } inline void set_note(uint8_t n) { _on_event.buffer()[1] = n; _off_event.buffer()[1] = n; } inline void set_velocity(uint8_t n) { _on_event.buffer()[2] = n; } inline void set_length(EventLength l) { _off_event.time() = _on_event.time() + l; } inline void set_channel(uint8_t c) { _on_event.set_channel(c); _off_event.set_channel(c); } - inline Event<T>& on_event() { return _on_event; } - inline const Event<T>& on_event() const { return _on_event; } - inline Event<T>& off_event() { return _off_event; } - inline const Event<T>& off_event() const { return _off_event; } + 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: // Event buffers are self-contained - MIDIEvent<T> _on_event; - MIDIEvent<T> _off_event; + MIDIEvent<Time> _on_event; + MIDIEvent<Time> _off_event; }; diff --git a/libs/evoral/evoral/RingBuffer.hpp b/libs/evoral/evoral/RingBuffer.hpp index 0d92043174..3e47042679 100644 --- a/libs/evoral/evoral/RingBuffer.hpp +++ b/libs/evoral/evoral/RingBuffer.hpp @@ -29,7 +29,7 @@ namespace Evoral { * Read/Write realtime safe. * Single-reader Single-writer thread safe. */ -template <typename T> +template <typename Time> class RingBuffer { public: @@ -37,7 +37,7 @@ public: */ RingBuffer(size_t size) : _size(size) - , _buf(new T[size]) + , _buf(new Time[size]) { reset(); assert(read_space() == 0); @@ -96,7 +96,7 @@ public: * read-pointer---^ * </pre> */ - size_t peek(size_t size, T* dst); + size_t peek(size_t size, Time* dst); /** Peek at the ringbuffer (read w/o advancing read pointer). * @return how much has been peeked (wraps around if read exceeds @@ -106,32 +106,32 @@ public: * read-pointer---^ * </pre> */ - bool full_peek(size_t size, T* dst); + bool full_peek(size_t size, Time* dst); /** Read from the ringbuffer. (advances read pointer) * @return how much has been read (read cannot exceed the end * of the buffer): */ - size_t read(size_t size, T* dst); + size_t read(size_t size, Time* dst); /** Read from the ringbuffer. (advances read pointer) * @return how much has been peeked (wraps around if read exceeds * the end of the buffer): */ - bool full_read(size_t size, T* dst); + bool full_read(size_t size, Time* dst); /** Advance read pointer by size */ bool skip(size_t size); - void write(size_t size, const T* src); + void write(size_t size, const Time* src); protected: mutable int _write_ptr; mutable int _read_ptr; size_t _size; ///< Size (capacity) in bytes - T* _buf; ///< size, event, size, event... + Time* _buf; ///< size, event, size, event... }; @@ -141,9 +141,9 @@ protected: * Caller must check return value and call again if necessary, or use the * full_peek method which does this automatically. */ -template<typename T> +template<typename Time> size_t -RingBuffer<T>::peek(size_t size, T* dst) +RingBuffer<Time>::peek(size_t size, Time* dst) { const size_t priv_read_ptr = g_atomic_int_get(&_read_ptr); @@ -157,9 +157,9 @@ RingBuffer<T>::peek(size_t size, T* dst) } -template<typename T> +template<typename Time> bool -RingBuffer<T>::full_peek(size_t size, T* dst) +RingBuffer<Time>::full_peek(size_t size, Time* dst) { if (read_space() < size) { return false; @@ -181,9 +181,9 @@ RingBuffer<T>::full_peek(size_t size, T* dst) * Caller must check return value and call again if necessary, or use the * full_read method which does this automatically. */ -template<typename T> +template<typename Time> size_t -RingBuffer<T>::read(size_t size, T* dst) +RingBuffer<Time>::read(size_t size, Time* dst) { const size_t priv_read_ptr = g_atomic_int_get(&_read_ptr); @@ -199,9 +199,9 @@ RingBuffer<T>::read(size_t size, T* dst) } -template<typename T> +template<typename Time> bool -RingBuffer<T>::full_read(size_t size, T* dst) +RingBuffer<Time>::full_read(size_t size, Time* dst) { if (read_space() < size) { return false; @@ -217,9 +217,9 @@ RingBuffer<T>::full_read(size_t size, T* dst) } -template<typename T> +template<typename Time> bool -RingBuffer<T>::skip(size_t size) +RingBuffer<Time>::skip(size_t size) { if (read_space() < size) { std::cerr << "WARNING: Attempt to skip past end of MIDI ring buffer" << std::endl; @@ -233,9 +233,9 @@ RingBuffer<T>::skip(size_t size) } -template<typename T> +template<typename Time> inline void -RingBuffer<T>::write(size_t size, const T* src) +RingBuffer<Time>::write(size_t size, const Time* src) { const size_t priv_write_ptr = g_atomic_int_get(&_write_ptr); diff --git a/libs/evoral/evoral/SMF.hpp b/libs/evoral/evoral/SMF.hpp index 2d6ec4e5d9..a7a2abf4bf 100644 --- a/libs/evoral/evoral/SMF.hpp +++ b/libs/evoral/evoral/SMF.hpp @@ -24,13 +24,13 @@ namespace Evoral { -template<typename T> class Event; -template<typename T> class EventRingBuffer; +template<typename Time> class Event; +template<typename Time> class EventRingBuffer; /** Standard Midi File (Type 0) */ -template<typename T> +template<typename Time> class SMF { public: SMF(); @@ -42,10 +42,10 @@ public: bool is_empty() const { return _empty; } bool eof() const { return feof(_fd); } - T last_event_time() const { return _last_ev_time; } + Time last_event_time() const { return _last_ev_time; } void begin_write(FrameTime start_time); - void append_event_unlocked(uint32_t delta_t, const Event<T>& ev); + void append_event_unlocked(uint32_t delta_t, const Event<Time>& ev); void end_write(); void flush(); @@ -73,7 +73,7 @@ private: static const uint16_t _ppqn = 19200; FILE* _fd; - T _last_ev_time; ///< last frame time written, relative to source start + Time _last_ev_time; ///< last frame time written, relative to source start uint32_t _track_size; uint32_t _header_size; ///< size of SMF header, including MTrk chunk header bool _empty; ///< true iff file contains(non-empty) events diff --git a/libs/evoral/evoral/Sequence.hpp b/libs/evoral/evoral/Sequence.hpp index d78c69df57..c972df3b29 100644 --- a/libs/evoral/evoral/Sequence.hpp +++ b/libs/evoral/evoral/Sequence.hpp @@ -35,9 +35,9 @@ namespace Evoral { class TypeMap; -template<typename T> class EventSink; -template<typename T> class Note; -template<typename T> class Event; +template<typename Time> class EventSink; +template<typename Time> class Note; +template<typename Time> class Event; /** An iterator over (the x axis of) a 2-d double coordinate space. */ @@ -58,7 +58,7 @@ public: /** This is a higher level view of events, with separate representations for * notes (instead of just unassociated note on/off events) and controller data. * Controller data is represented as a list of time-stamped float values. */ -template<typename T> +template<typename Time> class Sequence : virtual public ControlSet { public: Sequence(const TypeMap& type_map, size_t size=0); @@ -80,54 +80,54 @@ public: bool writing() const { return _writing; } void end_write(bool delete_stuck=false); - size_t read(EventSink<T>& dst, + size_t read(EventSink<Time>& dst, timestamp_t start, timedur_t length, timestamp_t stamp_offset) const; /** Resizes vector if necessary (NOT realtime safe) */ - void append(const Event<T>& ev); + void append(const Event<Time>& ev); - inline const boost::shared_ptr< const Note<T> > note_at(unsigned i) const { return _notes[i]; } - inline const boost::shared_ptr< Note<T> > note_at(unsigned i) { return _notes[i]; } + inline const boost::shared_ptr< const Note<Time> > note_at(unsigned i) const { return _notes[i]; } + inline const boost::shared_ptr< Note<Time> > note_at(unsigned i) { return _notes[i]; } inline size_t n_notes() const { return _notes.size(); } inline bool empty() const { return _notes.size() == 0 && ControlSet::empty(); } - inline static bool note_time_comparator(const boost::shared_ptr< const Note<T> >& a, - const boost::shared_ptr< const Note<T> >& b) { + inline static bool note_time_comparator(const boost::shared_ptr< const Note<Time> >& a, + const boost::shared_ptr< const Note<Time> >& b) { return a->time() < b->time(); } struct LaterNoteEndComparator { - typedef const Note<T>* value_type; - inline bool operator()(const boost::shared_ptr< const Note<T> > a, - const boost::shared_ptr< const Note<T> > b) const { + typedef const Note<Time>* value_type; + inline bool operator()(const boost::shared_ptr< const Note<Time> > a, + const boost::shared_ptr< const Note<Time> > b) const { return a->end_time() > b->end_time(); } }; - typedef std::vector< boost::shared_ptr< Note<T> > > Notes; + typedef std::vector< boost::shared_ptr< Note<Time> > > Notes; inline Notes& notes() { return _notes; } inline const Notes& notes() const { return _notes; } // useful for storing SysEx / Meta events - typedef std::vector< boost::shared_ptr< Event<T> > > SysExes; + typedef std::vector< boost::shared_ptr< Event<Time> > > SysExes; inline SysExes& sysexes() { return _sysexes; } inline const SysExes& sysexes() const { return _sysexes; } /** Read iterator */ class const_iterator { public: - const_iterator(const Sequence<T>& seq, T t); + const_iterator(const Sequence<Time>& seq, Time t); ~const_iterator(); inline bool valid() const { return !_is_end && _event; } inline bool locked() const { return _locked; } - const Event<T>& operator*() const { return *_event; } - const boost::shared_ptr< Event<T> > operator->() const { return _event; } - const boost::shared_ptr< Event<T> > get_event_pointer() { return _event; } + const Event<Time>& operator*() const { return *_event; } + const boost::shared_ptr< Event<Time> > operator->() const { return _event; } + const boost::shared_ptr< Event<Time> > get_event_pointer() { return _event; } const const_iterator& operator++(); // prefix only bool operator==(const const_iterator& other) const; @@ -136,15 +136,15 @@ public: const_iterator& operator=(const const_iterator& other); private: - friend class Sequence<T>; + friend class Sequence<Time>; enum MIDIMessageType { NIL, NOTE_ON, NOTE_OFF, CONTROL, SYSEX }; - const Sequence<T>* _seq; - boost::shared_ptr< Event<T> > _event; + const Sequence<Time>* _seq; + boost::shared_ptr< Event<Time> > _event; - typedef std::priority_queue< boost::shared_ptr< Note<T> >, - std::deque< boost::shared_ptr< Note<T> > >, + typedef std::priority_queue< boost::shared_ptr< Note<Time> >, + std::deque< boost::shared_ptr< Note<Time> > >, LaterNoteEndComparator > ActiveNotes; @@ -160,13 +160,13 @@ public: ControlIterators::iterator _control_iter; }; - const_iterator begin(T t=0) const { return const_iterator(*this, t); } + const_iterator begin(Time t=0) const { return const_iterator(*this, t); } const const_iterator& end() const { return _end_iter; } - void read_seek(T t) { _read_iter = begin(t); } - T read_time() const { return _read_iter.valid() ? _read_iter->time() : 0.0; } + void read_seek(Time t) { _read_iter = begin(t); } + Time read_time() const { return _read_iter.valid() ? _read_iter->time() : 0.0; } - bool control_to_midi_event(boost::shared_ptr< Event<T> >& ev, + bool control_to_midi_event(boost::shared_ptr< Event<Time> >& ev, const ControlIterator& iter) const; bool edited() const { return _edited; } @@ -176,8 +176,8 @@ public: bool is_sorted() const; #endif - void add_note_unlocked(const boost::shared_ptr< Note<T> > note); - void remove_note_unlocked(const boost::shared_ptr< const Note<T> > note); + void add_note_unlocked(const boost::shared_ptr< Note<Time> > note); + void remove_note_unlocked(const boost::shared_ptr< const Note<Time> > note); uint8_t lowest_note() const { return _lowest_note; } uint8_t highest_note() const { return _highest_note; } @@ -189,10 +189,10 @@ protected: private: friend class const_iterator; - void append_note_on_unlocked(uint8_t chan, T time, uint8_t note, uint8_t velocity); - void append_note_off_unlocked(uint8_t chan, T time, uint8_t note); - void append_control_unlocked(const Parameter& param, T time, double value); - void append_sysex_unlocked(const MIDIEvent<T>& ev); + void append_note_on_unlocked(uint8_t chan, Time time, uint8_t note, uint8_t velocity); + void append_note_off_unlocked(uint8_t chan, Time time, uint8_t note); + void append_control_unlocked(const Parameter& param, Time time, double value); + void append_sysex_unlocked(const MIDIEvent<Time>& ev); mutable Glib::RWLock _lock; @@ -217,7 +217,7 @@ private: uint8_t _highest_note; typedef std::priority_queue< - boost::shared_ptr< Note<T> >, std::deque< boost::shared_ptr< Note<T> > >, + boost::shared_ptr< Note<Time> >, std::deque< boost::shared_ptr< Note<Time> > >, LaterNoteEndComparator> ActiveNotes; }; diff --git a/libs/evoral/src/MIDIEvent.cpp b/libs/evoral/src/MIDIEvent.cpp index cc0b00ec0d..1df271370a 100644 --- a/libs/evoral/src/MIDIEvent.cpp +++ b/libs/evoral/src/MIDIEvent.cpp @@ -28,9 +28,9 @@ namespace Evoral { #ifdef EVORAL_MIDI_XML -template<typename Timestamp> -MIDIEvent<Timestamp>::MIDIEvent(const XMLNode& event) - : Event<Timestamp>() +template<typename Time> +MIDIEvent<Time>::MIDIEvent(const XMLNode& event) + : Event<Time>() { string name = event.name(); @@ -51,9 +51,9 @@ MIDIEvent<Timestamp>::MIDIEvent(const XMLNode& event) } -template<typename Timestamp> +template<typename Time> boost::shared_ptr<XMLNode> -MIDIEvent<Timestamp>::to_xml() const +MIDIEvent<Time>::to_xml() const { XMLNode *result = 0; diff --git a/libs/evoral/src/Note.cpp b/libs/evoral/src/Note.cpp index 7ba6bd5d6b..794fe33c48 100644 --- a/libs/evoral/src/Note.cpp +++ b/libs/evoral/src/Note.cpp @@ -21,8 +21,8 @@ namespace Evoral { -template<typename T> -Note<T>::Note(uint8_t chan, T t, EventLength l, uint8_t n, uint8_t v) +template<typename Time> +Note<Time>::Note(uint8_t chan, Time t, EventLength l, uint8_t n, uint8_t v) // FIXME: types? : _on_event(0xDE, t, 3, NULL, true) , _off_event(0xAD, t + l, 3, NULL, true) @@ -46,8 +46,8 @@ Note<T>::Note(uint8_t chan, T t, EventLength l, uint8_t n, uint8_t v) } -template<typename T> -Note<T>::Note(const Note<T>& copy) +template<typename Time> +Note<Time>::Note(const Note<Time>& copy) : _on_event(copy._on_event, true) , _off_event(copy._off_event, true) { @@ -73,15 +73,15 @@ Note<T>::Note(const Note<T>& copy) } -template<typename T> -Note<T>::~Note() +template<typename Time> +Note<Time>::~Note() { } -template<typename T> -const Note<T>& -Note<T>::operator=(const Note<T>& copy) +template<typename Time> +const Note<Time>& +Note<Time>::operator=(const Note<Time>& copy) { _on_event = copy._on_event; _off_event = copy._off_event; diff --git a/libs/evoral/src/SMF.cpp b/libs/evoral/src/SMF.cpp index f2cafe6864..421bbf35da 100644 --- a/libs/evoral/src/SMF.cpp +++ b/libs/evoral/src/SMF.cpp @@ -32,8 +32,8 @@ using namespace std; namespace Evoral { -template<typename T> -SMF<T>::SMF() +template<typename Time> +SMF<Time>::SMF() : _fd(0) , _last_ev_time(0) , _track_size(4) // 4 bytes for the ever-present EOT event @@ -42,8 +42,8 @@ SMF<T>::SMF() { } -template<typename T> -SMF<T>::~SMF() +template<typename Time> +SMF<Time>::~SMF() { } @@ -55,9 +55,9 @@ SMF<T>::~SMF() * -1 if the file can not be opened for reading, * -2 if the file can not be opened for writing */ -template<typename T> +template<typename Time> int -SMF<T>::open(const std::string& path) +SMF<Time>::open(const std::string& path) { //cerr << "Opening SMF file " << path() << " writeable: " << writable() << endl; _fd = fopen(path.c_str(), "r+"); @@ -90,9 +90,9 @@ SMF<T>::open(const std::string& path) return (_fd == 0) ? -1 : 0; } -template<typename T> +template<typename Time> void -SMF<T>::close() +SMF<Time>::close() { if (_fd) { flush_header(); @@ -102,16 +102,16 @@ SMF<T>::close() } } -template<typename T> +template<typename Time> void -SMF<T>::seek_to_start() const +SMF<Time>::seek_to_start() const { fseek(_fd, _header_size, SEEK_SET); } -template<typename T> +template<typename Time> void -SMF<T>::seek_to_footer_position() +SMF<Time>::seek_to_footer_position() { uint8_t buffer[4]; @@ -132,16 +132,16 @@ SMF<T>::seek_to_footer_position() } } -template<typename T> +template<typename Time> void -SMF<T>::flush() +SMF<Time>::flush() { fflush(_fd); } -template<typename T> +template<typename Time> int -SMF<T>::flush_header() +SMF<Time>::flush_header() { // FIXME: write timeline position somehow? @@ -169,9 +169,9 @@ SMF<T>::flush_header() return 0; } -template<typename T> +template<typename Time> int -SMF<T>::flush_footer() +SMF<Time>::flush_footer() { //cerr << path() << " SMF Flushing footer\n"; seek_to_footer_position(); @@ -181,9 +181,9 @@ SMF<T>::flush_footer() return 0; } -template<typename T> +template<typename Time> void -SMF<T>::write_footer() +SMF<Time>::write_footer() { write_var_len(0); char eot[3] = { 0xFF, 0x2F, 0x00 }; // end-of-track meta-event @@ -206,9 +206,9 @@ SMF<T>::write_footer() * Returns event length (including status byte) on success, 0 if event was * skipped (eg a meta event), or -1 on EOF (or end of track). */ -template<typename T> +template<typename Time> int -SMF<T>::read_event(uint32_t* delta_t, uint32_t* size, uint8_t** buf) const +SMF<Time>::read_event(uint32_t* delta_t, uint32_t* size, uint8_t** buf) const { if (feof(_fd)) { return -1; @@ -278,9 +278,9 @@ SMF<T>::read_event(uint32_t* delta_t, uint32_t* size, uint8_t** buf) const return (int)*size; } -template<typename T> +template<typename Time> void -SMF<T>::append_event_unlocked(uint32_t delta_t, const Event<T>& ev) +SMF<Time>::append_event_unlocked(uint32_t delta_t, const Event<Time>& ev) { if (ev.size() == 0) return; @@ -301,25 +301,25 @@ SMF<T>::append_event_unlocked(uint32_t delta_t, const Event<T>& ev) _empty = false; } -template<typename T> +template<typename Time> void -SMF<T>::begin_write(FrameTime start_frame) +SMF<Time>::begin_write(FrameTime start_frame) { _last_ev_time = 0; fseek(_fd, _header_size, SEEK_SET); } -template<typename T> +template<typename Time> void -SMF<T>::end_write() +SMF<Time>::end_write() { flush_header(); flush_footer(); } -template<typename T> +template<typename Time> void -SMF<T>::write_chunk_header(const char id[4], uint32_t length) +SMF<Time>::write_chunk_header(const char id[4], uint32_t length) { const uint32_t length_be = GUINT32_TO_BE(length); @@ -327,9 +327,9 @@ SMF<T>::write_chunk_header(const char id[4], uint32_t length) fwrite(&length_be, 4, 1, _fd); } -template<typename T> +template<typename Time> void -SMF<T>::write_chunk(const char id[4], uint32_t length, void* data) +SMF<Time>::write_chunk(const char id[4], uint32_t length, void* data) { write_chunk_header(id, length); @@ -337,9 +337,9 @@ SMF<T>::write_chunk(const char id[4], uint32_t length, void* data) } /** Returns the size (in bytes) of the value written. */ -template<typename T> +template<typename Time> size_t -SMF<T>::write_var_len(uint32_t value) +SMF<Time>::write_var_len(uint32_t value) { size_t ret = 0; diff --git a/libs/evoral/src/Sequence.cpp b/libs/evoral/src/Sequence.cpp index dd597aa5fa..81968566f4 100644 --- a/libs/evoral/src/Sequence.cpp +++ b/libs/evoral/src/Sequence.cpp @@ -35,25 +35,25 @@ using namespace std; namespace Evoral { -template<typename T> -void Sequence<T>::write_lock() { +template<typename Time> +void Sequence<Time>::write_lock() { _lock.writer_lock(); _control_lock.lock(); } -template<typename T> -void Sequence<T>::write_unlock() { +template<typename Time> +void Sequence<Time>::write_unlock() { _lock.writer_unlock(); _control_lock.unlock(); } -template<typename T> -void Sequence<T>::read_lock() const { +template<typename Time> +void Sequence<Time>::read_lock() const { _lock.reader_lock(); } -template<typename T> -void Sequence<T>::read_unlock() const { +template<typename Time> +void Sequence<Time>::read_unlock() const { _lock.reader_unlock(); } @@ -68,8 +68,8 @@ static ostream& errorout = cerr; // Read iterator (const_iterator) -template<typename T> -Sequence<T>::const_iterator::const_iterator(const Sequence<T>& seq, T t) +template<typename Time> +Sequence<Time>::const_iterator::const_iterator(const Sequence<Time>& seq, Time t) : _seq(&seq) , _is_end( (t == DBL_MAX) || seq.empty() ) , _locked( !_is_end ) @@ -84,7 +84,7 @@ Sequence<T>::const_iterator::const_iterator(const Sequence<T>& seq, T t) // find first note which begins after t _note_iter = seq.notes().end(); - for (typename Sequence<T>::Notes::const_iterator i = seq.notes().begin(); + for (typename Sequence<Time>::Notes::const_iterator i = seq.notes().begin(); i != seq.notes().end(); ++i) { if ((*i)->time() >= t) { _note_iter = i; @@ -95,7 +95,7 @@ Sequence<T>::const_iterator::const_iterator(const Sequence<T>& seq, T t) // find first sysex which begins after t _sysex_iter = seq.sysexes().end(); - for (typename Sequence<T>::SysExes::const_iterator i = seq.sysexes().begin(); + for (typename Sequence<Time>::SysExes::const_iterator i = seq.sysexes().begin(); i != seq.sysexes().end(); ++i) { if ((*i)->time() >= t) { _sysex_iter = i; @@ -159,7 +159,7 @@ Sequence<T>::const_iterator::const_iterator(const Sequence<T>& seq, T t) #endif MIDIMessageType type = NIL; - T earliest_t = t; + Time earliest_t = t; // if the note comes before anything else set the iterator to the note if (_note_iter != seq.notes().end() && (*_note_iter)->on_event().time() >= t) { @@ -188,7 +188,7 @@ Sequence<T>::const_iterator::const_iterator(const Sequence<T>& seq, T t) if (type == NOTE_ON) { debugout << "Reading note on event @ " << earliest_t << endl; // initialize the event pointer with a new event - _event = boost::shared_ptr< Event<T> >(new Event<T>((*_note_iter)->on_event(), true)); + _event = boost::shared_ptr< Event<Time> >(new Event<Time>((*_note_iter)->on_event(), true)); _active_notes.push(*_note_iter); ++_note_iter; _control_iter = _control_iters.end(); @@ -198,7 +198,7 @@ Sequence<T>::const_iterator::const_iterator(const Sequence<T>& seq, T t) } else if (type == SYSEX) { debugout << "Reading system exclusive event @ " << earliest_t << endl; // initialize the event pointer with a new event - _event = boost::shared_ptr< Event<T> >(new Event<T>(*(*_sysex_iter), true)); + _event = boost::shared_ptr< Event<Time> >(new Event<Time>(*(*_sysex_iter), true)); ++_sysex_iter; _control_iter = _control_iters.end(); } @@ -216,7 +216,7 @@ Sequence<T>::const_iterator::const_iterator(const Sequence<T>& seq, T t) } } else { debugout << "New Iterator = " << _event->event_type(); - debugout << " : " << hex << (int)((MIDIEvent<T>*)_event.get())->type(); + debugout << " : " << hex << (int)((MIDIEvent<Time>*)_event.get())->type(); debugout << " @ " << _event->time() << endl; } @@ -225,17 +225,17 @@ Sequence<T>::const_iterator::const_iterator(const Sequence<T>& seq, T t) //assert(_is_end || (_event->buffer() && _event->buffer()[0] != '\0')); } -template<typename T> -Sequence<T>::const_iterator::~const_iterator() +template<typename Time> +Sequence<Time>::const_iterator::~const_iterator() { if (_locked) { _seq->read_unlock(); } } -template<typename T> -const typename Sequence<T>::const_iterator& -Sequence<T>::const_iterator::operator++() +template<typename Time> +const typename Sequence<Time>::const_iterator& +Sequence<Time>::const_iterator::operator++() { if (_is_end) { throw std::logic_error("Attempt to iterate past end of Sequence"); @@ -244,7 +244,7 @@ Sequence<T>::const_iterator::operator++() debugout << "Iterator ++" << endl; assert(_event && _event->buffer() && _event->size() > 0); - const MIDIEvent<T>& ev = *((MIDIEvent<T>*)_event.get()); + const MIDIEvent<Time>& ev = *((MIDIEvent<Time>*)_event.get()); //debugout << "const_iterator::operator++: " << _event->to_string() << endl; @@ -291,7 +291,7 @@ Sequence<T>::const_iterator::operator++() } MIDIMessageType type = NIL; - T earliest_t = 0; + Time earliest_t = 0; // Next earliest note on if (_note_iter != _seq->notes().end()) { @@ -349,9 +349,9 @@ Sequence<T>::const_iterator::operator++() return *this; } -template<typename T> +template<typename Time> bool -Sequence<T>::const_iterator::operator==(const const_iterator& other) const +Sequence<Time>::const_iterator::operator==(const const_iterator& other) const { if (_is_end || other._is_end) { return (_is_end == other._is_end); @@ -360,9 +360,9 @@ Sequence<T>::const_iterator::operator==(const const_iterator& other) const } } -template<typename T> -typename Sequence<T>::const_iterator& -Sequence<T>::const_iterator::operator=(const const_iterator& other) +template<typename Time> +typename Sequence<Time>::const_iterator& +Sequence<Time>::const_iterator::operator=(const const_iterator& other) { if (_locked && _seq != other._seq) { _seq->read_unlock(); @@ -382,7 +382,7 @@ Sequence<T>::const_iterator::operator=(const const_iterator& other) if (_event) { *_event = *other._event.get(); } else { - _event = boost::shared_ptr< Event<T> >(new Event<T>(*other._event, true)); + _event = boost::shared_ptr< Event<Time> >(new Event<Time>(*other._event, true)); } } else { if (_event) { @@ -395,8 +395,8 @@ Sequence<T>::const_iterator::operator=(const const_iterator& other) // Sequence -template<typename T> -Sequence<T>::Sequence(const TypeMap& type_map, size_t size) +template<typename Time> +Sequence<Time>::Sequence(const TypeMap& type_map, size_t size) : _read_iter(*this, DBL_MAX) , _edited(false) , _type_map(type_map) @@ -417,9 +417,9 @@ Sequence<T>::Sequence(const TypeMap& type_map, size_t size) * adding \a offset to each event's timestamp. * \return number of events written to \a dst */ -template<typename T> +template<typename Time> size_t -Sequence<T>::read(EventSink<T>& dst, timestamp_t start, timedur_t nframes, timestamp_t offset) const +Sequence<Time>::read(EventSink<Time>& dst, timestamp_t start, timedur_t nframes, timestamp_t offset) const { debugout << this << " read @ " << start << " * " << nframes << " + " << offset << endl; debugout << this << " # notes: " << n_notes() << endl; @@ -462,16 +462,16 @@ Sequence<T>::read(EventSink<T>& dst, timestamp_t start, timedur_t nframes, times * The event_type of \a ev should be set to the expected output type. * \return true on success */ -template<typename T> +template<typename Time> bool -Sequence<T>::control_to_midi_event(boost::shared_ptr< Event<T> >& ev, const ControlIterator& iter) const +Sequence<Time>::control_to_midi_event(boost::shared_ptr< Event<Time> >& ev, const ControlIterator& iter) const { assert(iter.list.get()); const uint32_t event_type = iter.list->parameter().type(); // initialize the event pointer with a new event, if necessary if (!ev) { - ev = boost::shared_ptr< Event<T> >(new Event<T>(event_type, 0, 3, NULL, true)); + ev = boost::shared_ptr< Event<Time> >(new Event<Time>(event_type, 0, 3, NULL, true)); } uint8_t midi_type = _type_map.parameter_midi_type(iter.list->parameter()); @@ -533,9 +533,9 @@ Sequence<T>::control_to_midi_event(boost::shared_ptr< Event<T> >& ev, const Cont /** Clear all events from the model. */ -template<typename T> +template<typename Time> void -Sequence<T>::clear() +Sequence<Time>::clear() { _lock.writer_lock(); _notes.clear(); @@ -553,9 +553,9 @@ Sequence<T>::clear() * stored; note off events are discarded entirely and all contained notes will * have length 0. */ -template<typename T> +template<typename Time> void -Sequence<T>::start_write() +Sequence<Time>::start_write() { debugout << this << " START WRITE, PERCUSSIVE = " << _percussive << endl; write_lock(); @@ -573,9 +573,9 @@ Sequence<T>::start_write() * that were never resolved with a corresonding note off will be deleted. * Otherwise they will remain as notes with length 0. */ -template<typename T> +template<typename Time> void -Sequence<T>::end_write(bool delete_stuck) +Sequence<Time>::end_write(bool delete_stuck) { write_lock(); assert(_writing); @@ -597,7 +597,7 @@ Sequence<T>::end_write(bool delete_stuck) for (int i = 0; i < 16; ++i) { if (!_write_notes[i].empty()) { - errorout << "WARNING: Sequence<T>::end_write: Channel " << i << " has " + errorout << "WARNING: Sequence<Time>::end_write: Channel " << i << " has " << _write_notes[i].size() << " stuck notes" << endl; } _write_notes[i].clear(); @@ -617,14 +617,14 @@ Sequence<T>::end_write(bool delete_stuck) * the start of this model (t=0) and MUST be monotonically increasing * and MUST be >= the latest event currently in the model. */ -template<typename T> +template<typename Time> void -Sequence<T>::append(const Event<T>& event) +Sequence<Time>::append(const Event<Time>& event) { write_lock(); _edited = true; - const MIDIEvent<T>& ev = (const MIDIEvent<T>&)event; + const MIDIEvent<Time>& ev = (const MIDIEvent<Time>&)event; assert(_notes.empty() || ev.time() >= _notes.back()->time()); assert(_writing); @@ -666,9 +666,9 @@ Sequence<T>::append(const Event<T>& event) write_unlock(); } -template<typename T> +template<typename Time> void -Sequence<T>::append_note_on_unlocked(uint8_t chan, T time, uint8_t note_num, uint8_t velocity) +Sequence<Time>::append_note_on_unlocked(uint8_t chan, Time time, uint8_t note_num, uint8_t velocity) { debugout << this << " c" << (int)chan << " note " << (int)note_num << " off @ " << time << endl; assert(note_num <= 127); @@ -681,7 +681,7 @@ Sequence<T>::append_note_on_unlocked(uint8_t chan, T time, uint8_t note_num, uin if (note_num > _highest_note) _highest_note = note_num; - boost::shared_ptr< Note<T> > new_note(new Note<T>(chan, time, 0, note_num, velocity)); + boost::shared_ptr< Note<Time> > new_note(new Note<Time>(chan, time, 0, note_num, velocity)); _notes.push_back(new_note); if (!_percussive) { debugout << "Sustained: Appending active note on " << (unsigned)(uint8_t)note_num << endl; @@ -691,9 +691,9 @@ Sequence<T>::append_note_on_unlocked(uint8_t chan, T time, uint8_t note_num, uin } } -template<typename T> +template<typename Time> void -Sequence<T>::append_note_off_unlocked(uint8_t chan, T time, uint8_t note_num) +Sequence<Time>::append_note_off_unlocked(uint8_t chan, Time time, uint8_t note_num) { debugout << this << " c" << (int)chan << " note " << (int)note_num << " off @ " << time << endl; assert(note_num <= 127); @@ -715,7 +715,7 @@ Sequence<T>::append_note_off_unlocked(uint8_t chan, T time, uint8_t note_num) for (WriteNotes::iterator n = _write_notes[chan].begin(); n != _write_notes[chan].end(); ++n) { - Note<T>& note = *_notes[*n].get(); + Note<Time>& note = *_notes[*n].get(); if (note.note() == note_num) { assert(time >= note.time()); note.set_length(time - note.time()); @@ -732,9 +732,9 @@ Sequence<T>::append_note_off_unlocked(uint8_t chan, T time, uint8_t note_num) } } -template<typename T> +template<typename Time> void -Sequence<T>::append_control_unlocked(const Parameter& param, T time, double value) +Sequence<Time>::append_control_unlocked(const Parameter& param, Time time, double value) { debugout << this << " " << _type_map.to_symbol(param) << " @ " << time << " \t= \t" << value << " # controls: " << _controls.size() << endl; @@ -742,9 +742,9 @@ Sequence<T>::append_control_unlocked(const Parameter& param, T time, double valu c->list()->rt_add(time, value); } -template<typename T> +template<typename Time> void -Sequence<T>::append_sysex_unlocked(const MIDIEvent<T>& ev) +Sequence<Time>::append_sysex_unlocked(const MIDIEvent<Time>& ev) { debugout << this << " SysEx @ " << ev.time() << " \t= \t [ " << hex; for (size_t i=0; i < ev.size(); ++i) { @@ -752,13 +752,13 @@ Sequence<T>::append_sysex_unlocked(const MIDIEvent<T>& ev) } debugout << "]" << endl; - boost::shared_ptr<MIDIEvent<T> > event(new MIDIEvent<T>(ev, true)); + boost::shared_ptr<MIDIEvent<Time> > event(new MIDIEvent<Time>(ev, true)); _sysexes.push_back(event); } -template<typename T> +template<typename Time> void -Sequence<T>::add_note_unlocked(const boost::shared_ptr< Note<T> > note) +Sequence<Time>::add_note_unlocked(const boost::shared_ptr< Note<Time> > note) { debugout << this << " add note " << (int)note->note() << " @ " << note->time() << endl; _edited = true; @@ -767,15 +767,15 @@ Sequence<T>::add_note_unlocked(const boost::shared_ptr< Note<T> > note) _notes.insert(i, note); } -template<typename T> +template<typename Time> void -Sequence<T>::remove_note_unlocked(const boost::shared_ptr< const Note<T> > note) +Sequence<Time>::remove_note_unlocked(const boost::shared_ptr< const Note<Time> > note) { _edited = true; debugout << this << " remove note " << (int)note->note() << " @ " << note->time() << endl; for (typename Notes::iterator n = _notes.begin(); n != _notes.end(); ++n) { - Note<T>& _n = *(*n); - const Note<T>& _note = *note; + Note<Time>& _n = *(*n); + const Note<Time>& _note = *note; // TODO: There is still the issue, that after restarting ardour // persisted undo does not work, because of rounding errors in the // event times after saving/restoring to/from MIDI files @@ -794,9 +794,9 @@ Sequence<T>::remove_note_unlocked(const boost::shared_ptr< const Note<T> > note) /** Slow! for debugging only. */ #ifndef NDEBUG -template<typename T> +template<typename Time> bool -Sequence<T>::is_sorted() const { +Sequence<Time>::is_sorted() const { bool t = 0; for (typename Notes::const_iterator n = _notes.begin(); n != _notes.end(); ++n) if ((*n)->time() < t) |