diff options
author | David Robillard <d@drobilla.net> | 2009-02-02 02:36:05 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-02-02 02:36:05 +0000 |
commit | 166ef64e3db4ab72b7b1e7455234e2b9ceddf6d8 (patch) | |
tree | 0f28067a301556c5c0a67091c691c82960db57c1 /libs/ardour | |
parent | ead5dd45689be089d79a4a5daad88da737ca4cd9 (diff) |
Make (MIDI) event time stamp type a template parameter.
git-svn-id: svn://localhost/ardour2/branches/3.0@4473 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour')
29 files changed, 157 insertions, 125 deletions
diff --git a/libs/ardour/ardour/automatable.h b/libs/ardour/ardour/automatable.h index ca4624f281..98ab28d12d 100644 --- a/libs/ardour/ardour/automatable.h +++ b/libs/ardour/ardour/automatable.h @@ -114,12 +114,13 @@ public: /** Contains notes and controllers */ -class AutomatableSequence : public Automatable, public Evoral::Sequence { +template<typename T> +class AutomatableSequence : public Automatable, public Evoral::Sequence<T> { public: AutomatableSequence(Session& s, size_t size) : Evoral::ControlSet() , Automatable(s) - , Evoral::Sequence(EventTypeMap::instance()) + , Evoral::Sequence<T>(EventTypeMap::instance()) {} }; diff --git a/libs/ardour/ardour/diskstream.h b/libs/ardour/ardour/diskstream.h index 211933c778..03d2e23cbd 100644 --- a/libs/ardour/ardour/diskstream.h +++ b/libs/ardour/ardour/diskstream.h @@ -143,7 +143,8 @@ class Diskstream : public SessionObject void remove_region_from_last_capture (boost::weak_ptr<Region> wregion); - void move_processor_automation (boost::weak_ptr<Processor>, Evoral::RangeMoveList const &); + void move_processor_automation (boost::weak_ptr<Processor>, + list< Evoral::RangeMove<nframes_t> > const &); sigc::signal<void> RecordEnableChanged; sigc::signal<void> SpeedChanged; @@ -209,7 +210,7 @@ class Diskstream : public SessionObject virtual void playlist_changed (Change); virtual void playlist_deleted (boost::weak_ptr<Playlist>); - virtual void playlist_ranges_moved (Evoral::RangeMoveList const &); + virtual void playlist_ranges_moved (list< Evoral::RangeMove<nframes_t> > const &); virtual void transport_stopped (struct tm&, time_t, bool abort) = 0; virtual void transport_looped (nframes_t transport_frame) = 0; diff --git a/libs/ardour/ardour/midi_buffer.h b/libs/ardour/ardour/midi_buffer.h index 36610c61cb..9c5bb294c3 100644 --- a/libs/ardour/ardour/midi_buffer.h +++ b/libs/ardour/ardour/midi_buffer.h @@ -32,6 +32,8 @@ namespace ARDOUR { class MidiBuffer : public Buffer { public: + typedef double TimeType; + MidiBuffer(size_t capacity); ~MidiBuffer(); @@ -41,7 +43,7 @@ public: void copy(const MidiBuffer& copy); - bool push_back(const Evoral::MIDIEvent& event); + bool push_back(const Evoral::MIDIEvent<TimeType>& event); bool push_back(const jack_midi_event_t& event); uint8_t* reserve(double time, size_t size); @@ -54,14 +56,14 @@ public: struct iterator_base { iterator_base<B,E>(B& b, size_t o) : buffer(b), offset(o) {} inline E operator*() const { - uint8_t* ev_start = buffer._data + offset + sizeof(Evoral::EventTime); + uint8_t* ev_start = buffer._data + offset + sizeof(TimeType); return E(EventTypeMap::instance().midi_event_type(*ev_start), - *(Evoral::EventTime*)(buffer._data + offset), + *(TimeType*)(buffer._data + offset), Evoral::midi_event_size(*ev_start) + 1, ev_start); } inline iterator_base<B,E>& operator++() { - uint8_t* ev_start = buffer._data + offset + sizeof(Evoral::EventTime); - offset += sizeof(Evoral::EventTime) + Evoral::midi_event_size(*ev_start) + 1; + uint8_t* ev_start = buffer._data + offset + sizeof(TimeType); + offset += sizeof(TimeType) + Evoral::midi_event_size(*ev_start) + 1; return *this; } inline bool operator!=(const iterator_base<B,E>& other) const { @@ -71,8 +73,8 @@ public: size_t offset; }; - typedef iterator_base<MidiBuffer, Evoral::MIDIEvent> iterator; - typedef iterator_base<const MidiBuffer, const Evoral::MIDIEvent> const_iterator; + typedef iterator_base< MidiBuffer, Evoral::MIDIEvent<TimeType> > iterator; + typedef iterator_base< const MidiBuffer, const Evoral::MIDIEvent<TimeType> > const_iterator; iterator begin() { return iterator(*this, 0); } iterator end() { return iterator(*this, _size); } @@ -81,8 +83,8 @@ public: const_iterator end() const { return const_iterator(*this, _size); } private: - friend class iterator_base<MidiBuffer, Evoral::MIDIEvent>; - friend class iterator_base<const MidiBuffer, const Evoral::MIDIEvent>; + friend class iterator_base< MidiBuffer, Evoral::MIDIEvent<TimeType> >; + friend class iterator_base< const MidiBuffer, const Evoral::MIDIEvent<TimeType> >; size_t _size; ///< Size in bytes of used portion of _data uint8_t* _data; ///< timestamp, event, timestamp, event, ... diff --git a/libs/ardour/ardour/midi_diskstream.h b/libs/ardour/ardour/midi_diskstream.h index 852a329544..8ebbf4ce04 100644 --- a/libs/ardour/ardour/midi_diskstream.h +++ b/libs/ardour/ardour/midi_diskstream.h @@ -170,18 +170,18 @@ class MidiDiskstream : public Diskstream void engage_record_enable (); void disengage_record_enable (); - void check_note_onoffs(Evoral::MIDIEvent &event); + void check_note_onoffs(Evoral::MIDIEvent<MidiBuffer::TimeType> &event); void emit_pending_note_offs(MidiBuffer &dst, nframes_t time); - MidiRingBuffer* _playback_buf; - MidiRingBuffer* _capture_buf; - MidiPort* _source_port; - boost::shared_ptr<SMFSource> _write_source; - nframes_t _last_flush_frame; - NoteMode _note_mode; - MidiStateTracker _midistate_tracker; - volatile gint _frames_written_to_ringbuffer; - volatile gint _frames_read_from_ringbuffer; + MidiRingBuffer<MidiBuffer::TimeType>* _playback_buf; + MidiRingBuffer<MidiBuffer::TimeType>* _capture_buf; + MidiPort* _source_port; + boost::shared_ptr<SMFSource> _write_source; + nframes_t _last_flush_frame; + NoteMode _note_mode; + MidiStateTracker _midistate_tracker; + volatile gint _frames_written_to_ringbuffer; + volatile gint _frames_read_from_ringbuffer; }; }; /* namespace ARDOUR */ diff --git a/libs/ardour/ardour/midi_model.h b/libs/ardour/ardour/midi_model.h index a1a0da7296..fb881ae127 100644 --- a/libs/ardour/ardour/midi_model.h +++ b/libs/ardour/ardour/midi_model.h @@ -47,8 +47,10 @@ class MidiSource; * Because of this MIDI controllers and automatable controllers/widgets/etc * are easily interchangeable. */ -class MidiModel : public AutomatableSequence { +class MidiModel : public AutomatableSequence<double> { public: + typedef double TimeType; + MidiModel(MidiSource* s, size_t size=0); NoteMode note_mode() const { return (percussive() ? Percussive : Sustained); } @@ -71,17 +73,17 @@ public: int set_state (const XMLNode&); XMLNode& get_state (); - void add(const boost::shared_ptr<Evoral::Note> note); - void remove(const boost::shared_ptr<Evoral::Note> note); + void add(const boost::shared_ptr< Evoral::Note<TimeType> > note); + void remove(const boost::shared_ptr< Evoral::Note<TimeType> > note); private: - XMLNode &marshal_note(const boost::shared_ptr<Evoral::Note> note); - boost::shared_ptr<Evoral::Note> unmarshal_note(XMLNode *xml_note); + XMLNode &marshal_note(const boost::shared_ptr< Evoral::Note<TimeType> > note); + boost::shared_ptr< Evoral::Note<TimeType> > unmarshal_note(XMLNode *xml_note); boost::shared_ptr<MidiModel> _model; const std::string _name; - typedef std::list< boost::shared_ptr<Evoral::Note> > NoteList; + typedef std::list< boost::shared_ptr< Evoral::Note<TimeType> > > NoteList; NoteList _added_notes; NoteList _removed_notes; diff --git a/libs/ardour/ardour/midi_playlist.h b/libs/ardour/ardour/midi_playlist.h index 697d80611b..d7fdadb2f5 100644 --- a/libs/ardour/ardour/midi_playlist.h +++ b/libs/ardour/ardour/midi_playlist.h @@ -34,7 +34,7 @@ class Session; class Region; class MidiRegion; class Source; -class MidiRingBuffer; +template<typename T> class MidiRingBuffer; class MidiPlaylist : public ARDOUR::Playlist { @@ -47,7 +47,7 @@ public: ~MidiPlaylist (); - nframes_t read (MidiRingBuffer& buf, + nframes_t read (MidiRingBuffer<double>& buf, nframes_t start, nframes_t cnt, uint32_t chan_n=0); int set_state (const XMLNode&); diff --git a/libs/ardour/ardour/midi_region.h b/libs/ardour/ardour/midi_region.h index 2cbed8f99c..781f815ec5 100644 --- a/libs/ardour/ardour/midi_region.h +++ b/libs/ardour/ardour/midi_region.h @@ -43,11 +43,13 @@ class Playlist; class Session; class MidiFilter; class MidiSource; -class MidiRingBuffer; +template<typename T> class MidiRingBuffer; class MidiRegion : public Region { public: + typedef double TimeType; + ~MidiRegion(); boost::shared_ptr<MidiSource> midi_source (uint32_t n=0) const; @@ -56,13 +58,13 @@ class MidiRegion : public Region virtual nframes64_t read (Sample*, nframes64_t pos, nframes64_t cnt, int channel) const { return 0; } virtual nframes64_t readable_length() const { return length(); } - nframes_t read_at (MidiRingBuffer& dst, + nframes_t read_at (MidiRingBuffer<TimeType>& dst, nframes_t position, nframes_t dur, uint32_t chan_n = 0, NoteMode mode = Sustained) const; - nframes_t master_read_at (MidiRingBuffer& dst, + nframes_t master_read_at (MidiRingBuffer<TimeType>& dst, nframes_t position, nframes_t dur, uint32_t chan_n = 0, @@ -106,7 +108,7 @@ class MidiRegion : public Region MidiRegion (const SourceList &, const XMLNode&); private: - nframes_t _read_at (const SourceList&, MidiRingBuffer& dst, + nframes_t _read_at (const SourceList&, MidiRingBuffer<TimeType>& dst, nframes_t position, nframes_t dur, uint32_t chan_n = 0, diff --git a/libs/ardour/ardour/midi_ring_buffer.h b/libs/ardour/ardour/midi_ring_buffer.h index 7ffdcf3b8c..228479067f 100644 --- a/libs/ardour/ardour/midi_ring_buffer.h +++ b/libs/ardour/ardour/midi_ring_buffer.h @@ -37,16 +37,17 @@ class MidiBuffer; * * [timestamp][type][size][size bytes of raw MIDI][timestamp][type][size](etc...) */ -class MidiRingBuffer : public Evoral::EventRingBuffer { +template<typename T> +class MidiRingBuffer : public Evoral::EventRingBuffer<T> { public: /** @param size Size in bytes. */ MidiRingBuffer(size_t size) - : Evoral::EventRingBuffer(size) + : Evoral::EventRingBuffer<T>(size) , _channel_mask(0x0000FFFF) {} - inline bool read_prefix(Evoral::EventTime* time, Evoral::EventType* type, uint32_t* size); + inline bool read_prefix(T* time, Evoral::EventType* type, uint32_t* size); inline bool read_contents(uint32_t size, uint8_t* buf); size_t read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t offset=0); @@ -86,14 +87,15 @@ private: /** Read the time and size of an event. This call MUST be immediately proceeded * by a call to read_contents (or the read pointer will be garbage). */ +template<typename T> inline bool -MidiRingBuffer::read_prefix(Evoral::EventTime* time, Evoral::EventType* type, uint32_t* size) +MidiRingBuffer<T>::read_prefix(T* time, Evoral::EventType* type, uint32_t* size) { - bool success = Evoral::EventRingBuffer::full_read(sizeof(Evoral::EventTime), (uint8_t*)time); + bool success = Evoral::EventRingBuffer<T>::full_read(sizeof(T), (uint8_t*)time); if (success) - success = Evoral::EventRingBuffer::full_read(sizeof(Evoral::EventType), (uint8_t*)type); + success = Evoral::EventRingBuffer<T>::full_read(sizeof(Evoral::EventType), (uint8_t*)type); if (success) - success = Evoral::EventRingBuffer::full_read(sizeof(uint32_t), (uint8_t*)size); + success = Evoral::EventRingBuffer<T>::full_read(sizeof(uint32_t), (uint8_t*)size); return success; } @@ -102,10 +104,11 @@ MidiRingBuffer::read_prefix(Evoral::EventTime* time, Evoral::EventType* type, ui /** Read the content of an event. This call MUST be immediately preceded * by a call to read_prefix (or the returned even will be garbage). */ +template<typename T> inline bool -MidiRingBuffer::read_contents(uint32_t size, uint8_t* buf) +MidiRingBuffer<T>::read_contents(uint32_t size, uint8_t* buf) { - return Evoral::EventRingBuffer::full_read(size, buf); + return Evoral::EventRingBuffer<T>::full_read(size, buf); } diff --git a/libs/ardour/ardour/midi_source.h b/libs/ardour/ardour/midi_source.h index 895dcb25cc..c0b105decd 100644 --- a/libs/ardour/ardour/midi_source.h +++ b/libs/ardour/ardour/midi_source.h @@ -39,12 +39,14 @@ using std::string; namespace ARDOUR { -class MidiRingBuffer; +template<typename T> class MidiRingBuffer; /** Source for MIDI data */ class MidiSource : public Source { public: + typedef double TimeType; + MidiSource (Session& session, string name); MidiSource (Session& session, const XMLNode&); virtual ~MidiSource (); @@ -55,10 +57,10 @@ class MidiSource : public Source virtual uint32_t n_channels () const { return 1; } // FIXME: integrate this with the Readable::read interface somehow - virtual nframes_t midi_read (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset, nframes_t negative_stamp_offset) const; - virtual nframes_t midi_write (MidiRingBuffer& src, nframes_t cnt); + virtual nframes_t midi_read (MidiRingBuffer<TimeType>& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset, nframes_t negative_stamp_offset) const; + virtual nframes_t midi_write (MidiRingBuffer<TimeType>& src, nframes_t cnt); - virtual void append_event_unlocked(EventTimeUnit unit, const Evoral::Event& ev) = 0; + virtual void append_event_unlocked(EventTimeUnit unit, const Evoral::Event<TimeType>& ev) = 0; virtual void mark_for_remove() = 0; virtual void mark_streaming_midi_write_started (NoteMode mode, nframes_t start_time); @@ -99,8 +101,8 @@ class MidiSource : public Source //virtual int flush_header() = 0; //virtual int flush_footer() = 0; - virtual nframes_t read_unlocked (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset, nframes_t negative_stamp_offset) const = 0; - virtual nframes_t write_unlocked (MidiRingBuffer& dst, nframes_t cnt) = 0; + virtual nframes_t read_unlocked (MidiRingBuffer<TimeType>& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset, nframes_t negative_stamp_offset) const = 0; + virtual nframes_t write_unlocked (MidiRingBuffer<TimeType>& dst, nframes_t cnt) = 0; mutable Glib::Mutex _lock; string _captured_for; diff --git a/libs/ardour/ardour/midi_state_tracker.h b/libs/ardour/ardour/midi_state_tracker.h index bd8bdb650a..0bc7897b53 100644 --- a/libs/ardour/ardour/midi_state_tracker.h +++ b/libs/ardour/ardour/midi_state_tracker.h @@ -40,7 +40,7 @@ public: void resolve_notes (MidiBuffer& buffer, nframes_t time); private: - void track_note_onoffs(const Evoral::MIDIEvent& event); + void track_note_onoffs(const Evoral::MIDIEvent<MidiBuffer::TimeType>& event); std::bitset<128*16> _active_notes; }; diff --git a/libs/ardour/ardour/midi_track.h b/libs/ardour/ardour/midi_track.h index 56f73fbe9d..09c64c2978 100644 --- a/libs/ardour/ardour/midi_track.h +++ b/libs/ardour/ardour/midi_track.h @@ -104,8 +104,8 @@ private: void set_state_part_two (); void set_state_part_three (); - MidiRingBuffer _immediate_events; - NoteMode _note_mode; + MidiRingBuffer<double> _immediate_events; + NoteMode _note_mode; }; } /* namespace ARDOUR*/ diff --git a/libs/ardour/ardour/playlist.h b/libs/ardour/ardour/playlist.h index cdde9855b2..d2920fb610 100644 --- a/libs/ardour/ardour/playlist.h +++ b/libs/ardour/ardour/playlist.h @@ -128,7 +128,7 @@ class Playlist : public SessionObject, public boost::enable_shared_from_this<Pla sigc::signal<void> Modified; sigc::signal<void> NameChanged; sigc::signal<void> LengthChanged; - sigc::signal<void, Evoral::RangeMoveList const &> RangesMoved; + sigc::signal<void, list< Evoral::RangeMove<nframes_t> > const &> RangesMoved; static string bump_name (string old_name, Session&); @@ -190,7 +190,7 @@ class Playlist : public SessionObject, public boost::enable_shared_from_this<Pla RegionList pending_bounds; bool pending_modified; bool pending_length; - Evoral::RangeMoveList pending_range_moves; + list< Evoral::RangeMove<nframes_t> > pending_range_moves; bool save_on_thaw; string last_save_reason; uint32_t in_set_state; diff --git a/libs/ardour/ardour/smf_source.h b/libs/ardour/ardour/smf_source.h index 0c0dba3d96..e92ae59c3f 100644 --- a/libs/ardour/ardour/smf_source.h +++ b/libs/ardour/ardour/smf_source.h @@ -27,14 +27,14 @@ #include <ardour/midi_source.h> #include <evoral/SMF.hpp> -namespace Evoral { class Event; } +namespace Evoral { template<typename T> class Event; } namespace ARDOUR { -class MidiRingBuffer; +template<typename T> class MidiRingBuffer; /** Standard Midi File (Type 0) Source */ -class SMFSource : public MidiSource, public Evoral::SMF { +class SMFSource : public MidiSource, public Evoral::SMF<double> { public: enum Flag { Writable = 0x1, @@ -74,7 +74,7 @@ class SMFSource : public MidiSource, public Evoral::SMF { void set_allow_remove_if_empty (bool yn); void mark_for_remove(); - void append_event_unlocked(EventTimeUnit unit, const Evoral::Event& ev); + void append_event_unlocked(EventTimeUnit unit, const Evoral::Event<double>& ev); int move_to_trash (const string trash_dir_name); @@ -100,14 +100,14 @@ class SMFSource : public MidiSource, public Evoral::SMF { int init (string idstr, bool must_exist); nframes_t read_unlocked ( - MidiRingBuffer& dst, + MidiRingBuffer<double>& dst, nframes_t start, nframes_t cn, nframes_t stamp_offset, nframes_t negative_stamp_offset) const; nframes_t write_unlocked ( - MidiRingBuffer& src, + MidiRingBuffer<double>& src, nframes_t cnt); bool find (std::string path, bool must_exist, bool& is_new); diff --git a/libs/ardour/diskstream.cc b/libs/ardour/diskstream.cc index 54d5360aa3..d277e4c37e 100644 --- a/libs/ardour/diskstream.cc +++ b/libs/ardour/diskstream.cc @@ -418,12 +418,18 @@ Diskstream::remove_region_from_last_capture (boost::weak_ptr<Region> wregion) } void -Diskstream::playlist_ranges_moved (Evoral::RangeMoveList const & movements) +Diskstream::playlist_ranges_moved (list< Evoral::RangeMove<nframes_t> > const & movements_frames) { if (Config->get_automation_follows_regions () == false) { return; } + list< Evoral::RangeMove<double> > movements; + for (list< Evoral::RangeMove<nframes_t> >::const_iterator i = movements_frames.begin(); + i != movements_frames.end(); ++i) { + movements.push_back(Evoral::RangeMove<double>(i->from, i->length, i->to)); + } + /* move gain automation */ boost::shared_ptr<AutomationList> gain_alist = _io->gain_control()->alist(); XMLNode & before = gain_alist->get_state (); @@ -452,18 +458,25 @@ Diskstream::playlist_ranges_moved (Evoral::RangeMoveList const & movements) /* XXX: ewww */ Route * route = dynamic_cast<Route*> (_io); if (route) { - route->foreach_processor (sigc::bind (sigc::mem_fun (*this, &Diskstream::move_processor_automation), movements)); + route->foreach_processor (sigc::bind (sigc::mem_fun (*this, &Diskstream::move_processor_automation), movements_frames)); } } void -Diskstream::move_processor_automation (boost::weak_ptr<Processor> p, Evoral::RangeMoveList const & movements) +Diskstream::move_processor_automation (boost::weak_ptr<Processor> p, + list< Evoral::RangeMove<nframes_t> > const & movements_frames) { boost::shared_ptr<Processor> processor (p.lock ()); if (!processor) { return; } + list< Evoral::RangeMove<double> > movements; + for (list< Evoral::RangeMove<nframes_t> >::const_iterator i = movements_frames.begin(); + i != movements_frames.end(); ++i) { + movements.push_back(Evoral::RangeMove<double>(i->from, i->length, i->to)); + } + set<Evoral::Parameter> const a = processor->what_can_be_automated (); for (set<Evoral::Parameter>::iterator i = a.begin (); i != a.end (); ++i) { diff --git a/libs/ardour/import.cc b/libs/ardour/import.cc index 6b3871c814..76975d8237 100644 --- a/libs/ardour/import.cc +++ b/libs/ardour/import.cc @@ -312,7 +312,7 @@ static void write_midi_data_to_new_files (Evoral::SMFReader* source, Session::import_status& status, vector<boost::shared_ptr<Source> >& newfiles) { - Evoral::Event ev(0, 0.0, 4, NULL, true); + Evoral::Event<double> ev(0, 0.0, 4, NULL, true); status.progress = 0.0f; diff --git a/libs/ardour/meter.cc b/libs/ardour/meter.cc index 4839223f40..39d7f63221 100644 --- a/libs/ardour/meter.cc +++ b/libs/ardour/meter.cc @@ -50,7 +50,7 @@ PeakMeter::run_in_place (BufferSet& bufs, nframes_t start_frame, nframes_t end_f // GUI needs a better MIDI meter, not much information can be // expressed through peaks alone for (MidiBuffer::iterator i = bufs.get_midi(n).begin(); i != bufs.get_midi(n).end(); ++i) { - const Evoral::MIDIEvent ev(*i, false); + const Evoral::MIDIEvent<double> ev(*i, false); if (ev.is_note_on()) { const float this_vel = log(ev.buffer()[2] / 127.0 * (M_E*M_E-M_E) + M_E) - 1.0; //printf("V %d -> %f\n", (int)((Byte)ev.buffer[2]), this_vel); diff --git a/libs/ardour/midi_buffer.cc b/libs/ardour/midi_buffer.cc index df4ee13558..f724aac100 100644 --- a/libs/ardour/midi_buffer.cc +++ b/libs/ardour/midi_buffer.cc @@ -99,7 +99,7 @@ MidiBuffer::read_from(const Buffer& src, nframes_t nframes, nframes_t offset) } for (MidiBuffer::const_iterator i = msrc.begin(); i != msrc.end(); ++i) { - const Evoral::MIDIEvent ev(*i, false); + const Evoral::MIDIEvent<TimeType> ev(*i, false); /*cout << this << " MidiBuffer::read_from event type: " << int(ev.type()) << " time: " << ev.time() << " size: " << ev.size() << " status: " << (int)*ev.buffer() << " buffer size: " << _size << endl;*/ @@ -126,16 +126,16 @@ MidiBuffer::read_from(const Buffer& src, nframes_t nframes, nframes_t offset) * @return false if operation failed (not enough room) */ bool -MidiBuffer::push_back(const Evoral::MIDIEvent& ev) +MidiBuffer::push_back(const Evoral::MIDIEvent<TimeType>& ev) { - const size_t stamp_size = sizeof(Evoral::EventTime); + const size_t stamp_size = sizeof(TimeType); if (_size + stamp_size + ev.size() >= _capacity) { cerr << "MidiBuffer::push_back failed (buffer is full)" << endl; return false; } uint8_t* const write_loc = _data + _size; - *((Evoral::EventTime*)write_loc) = ev.time(); + *((TimeType*)write_loc) = ev.time(); memcpy(write_loc + stamp_size, ev.buffer(), ev.size()); _size += stamp_size + ev.size(); @@ -155,14 +155,14 @@ MidiBuffer::push_back(const Evoral::MIDIEvent& ev) bool MidiBuffer::push_back(const jack_midi_event_t& ev) { - const size_t stamp_size = sizeof(Evoral::EventTime); + const size_t stamp_size = sizeof(TimeType); if (_size + stamp_size + ev.size >= _capacity) { cerr << "MidiBuffer::push_back failed (buffer is full)" << endl; return false; } uint8_t* const write_loc = _data + _size; - *((Evoral::EventTime*)write_loc) = ev.time; + *((TimeType*)write_loc) = ev.time; memcpy(write_loc + stamp_size, ev.buffer, ev.size); _size += stamp_size + ev.size; @@ -180,15 +180,15 @@ MidiBuffer::push_back(const jack_midi_event_t& ev) * location, or the buffer will be corrupted and very nasty things will happen. */ uint8_t* -MidiBuffer::reserve(Evoral::EventTime time, size_t size) +MidiBuffer::reserve(TimeType time, size_t size) { - const size_t stamp_size = sizeof(Evoral::EventTime); + const size_t stamp_size = sizeof(TimeType); if (_size + stamp_size + size >= _capacity) { return 0; } uint8_t* const write_loc = _data + _size; - *((Evoral::EventTime*)write_loc) = time; + *((TimeType*)write_loc) = time; _size += stamp_size + size; _silent = false; diff --git a/libs/ardour/midi_diskstream.cc b/libs/ardour/midi_diskstream.cc index cd50fc950a..b80f6217cf 100644 --- a/libs/ardour/midi_diskstream.cc +++ b/libs/ardour/midi_diskstream.cc @@ -121,8 +121,9 @@ MidiDiskstream::init (Diskstream::Flag f) set_block_size (_session.get_block_size()); allocate_temporary_buffers (); - _playback_buf = new MidiRingBuffer (_session.midi_diskstream_buffer_size()); - _capture_buf = new MidiRingBuffer (_session.midi_diskstream_buffer_size()); + const size_t size = _session.midi_diskstream_buffer_size(); + _playback_buf = new MidiRingBuffer<MidiBuffer::TimeType> (size); + _capture_buf = new MidiRingBuffer<MidiBuffer::TimeType> (size); _n_channels = ChanCount(DataType::MIDI, 1); @@ -521,7 +522,7 @@ MidiDiskstream::process (nframes_t transport_frame, nframes_t nframes, nframes_t // Pump entire port buffer into the ring buffer (FIXME: split cycles?) MidiBuffer& buf = _source_port->get_midi_buffer(nframes, offset); for (MidiBuffer::iterator i = buf.begin(); i != buf.end(); ++i) { - const Evoral::MIDIEvent ev(*i, false); + const Evoral::MIDIEvent<MidiBuffer::TimeType> ev(*i, false); assert(ev.buffer()); _capture_buf->write(ev.time() + transport_frame, ev.type(), ev.size(), ev.buffer()); } diff --git a/libs/ardour/midi_model.cc b/libs/ardour/midi_model.cc index 59776c59d6..99f87e845c 100644 --- a/libs/ardour/midi_model.cc +++ b/libs/ardour/midi_model.cc @@ -38,7 +38,7 @@ using namespace ARDOUR; using namespace PBD; MidiModel::MidiModel(MidiSource *s, size_t size) - : AutomatableSequence(s->session(), size) + : AutomatableSequence<TimeType>(s->session(), size) , _midi_source(s) { cerr << "MidiModel \"" << s->name() << "\" constructed: " << this << endl; @@ -90,7 +90,7 @@ MidiModel::DeltaCommand::DeltaCommand(boost::shared_ptr<MidiModel> m, } void -MidiModel::DeltaCommand::add(const boost::shared_ptr<Evoral::Note> note) +MidiModel::DeltaCommand::add(const boost::shared_ptr< Evoral::Note<TimeType> > note) { //cerr << "MEC: apply" << endl; _removed_notes.remove(note); @@ -98,7 +98,7 @@ MidiModel::DeltaCommand::add(const boost::shared_ptr<Evoral::Note> note) } void -MidiModel::DeltaCommand::remove(const boost::shared_ptr<Evoral::Note> note) +MidiModel::DeltaCommand::remove(const boost::shared_ptr< Evoral::Note<TimeType> > note) { //cerr << "MEC: remove" << endl; _added_notes.remove(note); @@ -156,7 +156,7 @@ MidiModel::DeltaCommand::undo() } XMLNode& -MidiModel::DeltaCommand::marshal_note(const boost::shared_ptr<Evoral::Note> note) +MidiModel::DeltaCommand::marshal_note(const boost::shared_ptr< Evoral::Note<TimeType> > note) { XMLNode *xml_note = new XMLNode("note"); ostringstream note_str(ios::ate); @@ -182,7 +182,7 @@ MidiModel::DeltaCommand::marshal_note(const boost::shared_ptr<Evoral::Note> note return *xml_note; } -boost::shared_ptr<Evoral::Note> +boost::shared_ptr< Evoral::Note<double> > MidiModel::DeltaCommand::unmarshal_note(XMLNode *xml_note) { unsigned int note; @@ -232,7 +232,8 @@ MidiModel::DeltaCommand::unmarshal_note(XMLNode *xml_note) velocity = 127; } - boost::shared_ptr<Evoral::Note> note_ptr(new Evoral::Note(channel, time, length, note, velocity)); + boost::shared_ptr< Evoral::Note<TimeType> > note_ptr(new Evoral::Note<TimeType>( + channel, time, length, note, velocity)); return note_ptr; } @@ -296,7 +297,7 @@ MidiModel::write_to(boost::shared_ptr<MidiSource> source) const bool old_percussive = percussive(); set_percussive(false); - for (Evoral::Sequence::const_iterator i = begin(); i != end(); ++i) { + for (Evoral::Sequence<TimeType>::const_iterator i = begin(); i != end(); ++i) { source->append_event_unlocked(Frames, *i); } diff --git a/libs/ardour/midi_playlist.cc b/libs/ardour/midi_playlist.cc index 7403438483..7139447a19 100644 --- a/libs/ardour/midi_playlist.cc +++ b/libs/ardour/midi_playlist.cc @@ -124,7 +124,7 @@ struct RegionSortByLayer { /** Returns the number of frames in time duration read (eg could be large when 0 events are read) */ nframes_t -MidiPlaylist::read (MidiRingBuffer& dst, nframes_t start, +MidiPlaylist::read (MidiRingBuffer<MidiBuffer::TimeType>& dst, nframes_t start, nframes_t dur, unsigned chan_n) { /* this function is never called from a realtime thread, so diff --git a/libs/ardour/midi_port.cc b/libs/ardour/midi_port.cc index c69dc7fc05..ead5f5aeac 100644 --- a/libs/ardour/midi_port.cc +++ b/libs/ardour/midi_port.cc @@ -147,7 +147,7 @@ MidiPort::flush_buffers (nframes_t nframes, nframes_t offset) void* jack_buffer = jack_port_get_buffer (_jack_port, nframes); for (MidiBuffer::iterator i = _buffer->begin(); i != _buffer->end(); ++i) { - const Evoral::Event& ev = *i; + const Evoral::Event<double>& ev = *i; // event times should be frames, relative to cycle start assert(ev.time() >= 0); assert(ev.time() < (nframes+offset)); diff --git a/libs/ardour/midi_region.cc b/libs/ardour/midi_region.cc index e29fb1e659..f0c4b2297e 100644 --- a/libs/ardour/midi_region.cc +++ b/libs/ardour/midi_region.cc @@ -117,19 +117,19 @@ MidiRegion::~MidiRegion () } nframes_t -MidiRegion::read_at (MidiRingBuffer& out, nframes_t position, nframes_t dur, uint32_t chan_n, NoteMode mode) const +MidiRegion::read_at (MidiRingBuffer<TimeType>& out, nframes_t position, nframes_t dur, uint32_t chan_n, NoteMode mode) const { return _read_at (_sources, out, position, dur, chan_n, mode); } nframes_t -MidiRegion::master_read_at (MidiRingBuffer& out, nframes_t position, nframes_t dur, uint32_t chan_n, NoteMode mode) const +MidiRegion::master_read_at (MidiRingBuffer<TimeType>& out, nframes_t position, nframes_t dur, uint32_t chan_n, NoteMode mode) const { return _read_at (_master_sources, out, position, dur, chan_n, mode); } nframes_t -MidiRegion::_read_at (const SourceList& srcs, MidiRingBuffer& dst, nframes_t position, nframes_t dur, uint32_t chan_n, NoteMode mode) const +MidiRegion::_read_at (const SourceList& srcs, MidiRingBuffer<TimeType>& dst, nframes_t position, nframes_t dur, uint32_t chan_n, NoteMode mode) const { /*cerr << "MidiRegion " << _name << "._read_at(" << position << ") - " << position << " duration: " << dur << endl;*/ diff --git a/libs/ardour/midi_ring_buffer.cc b/libs/ardour/midi_ring_buffer.cc index e09406a683..6327ab45c2 100644 --- a/libs/ardour/midi_ring_buffer.cc +++ b/libs/ardour/midi_ring_buffer.cc @@ -29,14 +29,15 @@ namespace ARDOUR { * Timestamps of events returned are relative to start (i.e. event with stamp 0 * occurred at start), with offset added. */ +template<typename T> size_t -MidiRingBuffer::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t offset) +MidiRingBuffer<T>::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t offset) { - if (read_space() == 0) { + if (this->read_space() == 0) { return 0; } - Evoral::EventTime ev_time; + T ev_time; Evoral::EventType ev_type; uint32_t ev_size; @@ -44,9 +45,9 @@ MidiRingBuffer::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t //cerr << "MRB read " << start << " .. " << end << " + " << offset << endl; - while (read_space() >= sizeof(Evoral::EventTime) + sizeof(Evoral::EventType) + sizeof(uint32_t)) { + while (this->read_space() >= sizeof(T) + sizeof(Evoral::EventType) + sizeof(uint32_t)) { - full_peek(sizeof(Evoral::EventTime), (uint8_t*)&ev_time); + this->full_peek(sizeof(T), (uint8_t*)&ev_time); if (ev_time > end) { //cerr << "MRB: PAST END (" << ev_time << " : " << end << ")" << endl; @@ -67,7 +68,7 @@ MidiRingBuffer::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t if (ev_type == LoopEventType) { ev_time -= start; ev_time += offset; - Evoral::MIDIEvent loopevent(LoopEventType, ev_time); + Evoral::MIDIEvent<T> loopevent(LoopEventType, ev_time); dst.push_back(loopevent); // We can safely return, without reading the data, because @@ -76,7 +77,7 @@ MidiRingBuffer::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t } uint8_t status; - success = full_peek(sizeof(uint8_t), &status); + success = this->full_peek(sizeof(uint8_t), &status); assert(success); // If this failed, buffer is corrupt, all hope is lost // Ignore event if it doesn't match channel filter @@ -84,7 +85,7 @@ MidiRingBuffer::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t const uint8_t channel = status & 0x0F; if ( !(get_channel_mask() & (1L << channel)) ) { //cerr << "MRB skipping event due to channel mask" << endl; - skip(ev_size); // Advance read pointer to next event + this->skip(ev_size); // Advance read pointer to next event continue; } } @@ -103,7 +104,7 @@ MidiRingBuffer::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t continue; } - success = Evoral::EventRingBuffer::full_read(ev_size, write_loc); + success = Evoral::EventRingBuffer<T>::full_read(ev_size, write_loc); if (success) { if (is_channel_event(status) && get_channel_mode() == ForceChannel) { @@ -121,6 +122,7 @@ MidiRingBuffer::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t return count; } +template class MidiRingBuffer<double>; } // namespace ARDOUR diff --git a/libs/ardour/midi_source.cc b/libs/ardour/midi_source.cc index 2aed2cad28..7adb0f177b 100644 --- a/libs/ardour/midi_source.cc +++ b/libs/ardour/midi_source.cc @@ -101,7 +101,7 @@ MidiSource::set_state (const XMLNode& node) } nframes_t -MidiSource::midi_read (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset, nframes_t negative_stamp_offset) const +MidiSource::midi_read (MidiRingBuffer<MidiBuffer::TimeType>& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset, nframes_t negative_stamp_offset) const { Glib::Mutex::Lock lm (_lock); if (_model) { @@ -115,7 +115,7 @@ MidiSource::midi_read (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, nfra } nframes_t -MidiSource::midi_write (MidiRingBuffer& dst, nframes_t cnt) +MidiSource::midi_write (MidiRingBuffer<MidiBuffer::TimeType>& dst, nframes_t cnt) { Glib::Mutex::Lock lm (_lock); return write_unlocked (dst, cnt); diff --git a/libs/ardour/midi_state_tracker.cc b/libs/ardour/midi_state_tracker.cc index 3871c139df..e1508717e4 100644 --- a/libs/ardour/midi_state_tracker.cc +++ b/libs/ardour/midi_state_tracker.cc @@ -31,7 +31,7 @@ MidiStateTracker::MidiStateTracker () } void -MidiStateTracker::track_note_onoffs (const Evoral::MIDIEvent &event) +MidiStateTracker::track_note_onoffs (const Evoral::MIDIEvent<MidiBuffer::TimeType>& event) { if (event.is_note_on()) { _active_notes [event.note() + 128 * event.channel()] = true; @@ -46,7 +46,7 @@ MidiStateTracker::track (const MidiBuffer::iterator &from, const MidiBuffer::ite bool ret = false; for (MidiBuffer::iterator i = from; i != to; ++i) { - const Evoral::MIDIEvent ev(*i, false); + const Evoral::MIDIEvent<MidiBuffer::TimeType> ev(*i, false); if (ev.event_type() == LoopEventType) { ret = true; continue; @@ -68,7 +68,8 @@ MidiStateTracker::resolve_notes (MidiBuffer &dst, nframes_t time) for (int note = 0; note < 128; ++note) { if (_active_notes[channel * 128 + note]) { uint8_t buffer[3] = { MIDI_CMD_NOTE_OFF | channel, note, 0 }; - Evoral::MIDIEvent noteoff (time, MIDI_CMD_NOTE_OFF, 3, buffer, false); + Evoral::MIDIEvent<MidiBuffer::TimeType> noteoff + (time, MIDI_CMD_NOTE_OFF, 3, buffer, false); dst.push_back (noteoff); diff --git a/libs/ardour/midi_stretch.cc b/libs/ardour/midi_stretch.cc index 975ec6d714..88aa436b03 100644 --- a/libs/ardour/midi_stretch.cc +++ b/libs/ardour/midi_stretch.cc @@ -87,11 +87,12 @@ MidiStretch::run (boost::shared_ptr<Region> r) boost::shared_ptr<MidiModel> new_model = new_src->model(); new_model->start_write(); - for (Evoral::Sequence::const_iterator i = old_model->begin(); i != old_model->end(); ++i) { + for (Evoral::Sequence<MidiModel::TimeType>::const_iterator i = old_model->begin(); + i != old_model->end(); ++i) { const double new_time = i->time() * _request.time_fraction; // FIXME: double copy - Evoral::Event ev = Evoral::Event(*i, true); + Evoral::Event<MidiModel::TimeType> ev(*i, true); ev.time() = new_time; new_model->append(ev); } diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc index 44ba67cb67..8f4c94078d 100644 --- a/libs/ardour/playlist.cc +++ b/libs/ardour/playlist.cc @@ -363,7 +363,7 @@ Playlist::notify_region_removed (boost::shared_ptr<Region> r) void Playlist::notify_region_moved (boost::shared_ptr<Region> r) { - Evoral::RangeMove const move (r->last_position (), r->length (), r->position ()); + Evoral::RangeMove<nframes_t> const move (r->last_position (), r->length (), r->position ()); if (holding_state ()) { @@ -371,7 +371,7 @@ Playlist::notify_region_moved (boost::shared_ptr<Region> r) } else { - Evoral::RangeMoveList m; + list< Evoral::RangeMove<nframes_t> > m; m.push_back (move); RangesMoved (m); diff --git a/libs/ardour/quantize.cc b/libs/ardour/quantize.cc index 3b5a264a7b..e4a2809277 100644 --- a/libs/ardour/quantize.cc +++ b/libs/ardour/quantize.cc @@ -69,7 +69,7 @@ Quantize::run (boost::shared_ptr<Region> r) double q_frames = _q * (m.frames_per_bar(t, session.frame_rate()) / (double)m.beats_per_bar()); - for (Evoral::Sequence::Notes::iterator i = model->notes().begin(); + for (Evoral::Sequence<MidiModel::TimeType>::Notes::iterator i = model->notes().begin(); i != model->notes().end(); ++i) { const double new_time = lrint((*i)->time() / q_frames) * q_frames; double new_dur = lrint((*i)->length() / q_frames) * q_frames; diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index 978192dc0a..f4dd5e1534 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -55,7 +55,7 @@ uint64_t SMFSource::header_position_offset; SMFSource::SMFSource (Session& s, std::string path, Flag flags) : MidiSource (s, region_name_from_path(path, false)) - , SMF () + , Evoral::SMF<double> () , _flags (Flag(flags | Writable)) // FIXME: this needs to be writable for now , _allow_remove_if_empty(true) { @@ -128,7 +128,7 @@ SMFSource::init (string pathstr, bool must_exist) /** All stamps in audio frames */ nframes_t -SMFSource::read_unlocked (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset, nframes_t negative_stamp_offset) const +SMFSource::read_unlocked (MidiRingBuffer<double>& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset, nframes_t negative_stamp_offset) const { //cerr << "SMF read_unlocked " << name() << " read " << start << ", count=" << cnt << ", offset=" << stamp_offset << endl; @@ -146,7 +146,7 @@ SMFSource::read_unlocked (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, n size_t scratch_size = 0; // keep track of scratch to minimize reallocs // FIXME: don't seek to start and search every read (brutal!) - SMF::seek_to_start(); + Evoral::SMF<double>::seek_to_start(); // FIXME: assumes tempo never changes after start const double frames_per_beat = _session.tempo_map().tempo_at(_timeline_position).frames_per_beat( @@ -155,7 +155,7 @@ SMFSource::read_unlocked (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, n const uint64_t start_ticks = (uint64_t)((start / frames_per_beat) * ppqn()); - while (!SMF::eof()) { + while (!Evoral::SMF<double>::eof()) { int ret = read_event(&ev_delta_t, &ev_size, &ev_buffer); if (ret == -1) { // EOF //cerr << "SMF - EOF\n"; @@ -194,11 +194,11 @@ SMFSource::read_unlocked (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, n /** All stamps in audio frames */ nframes_t -SMFSource::write_unlocked (MidiRingBuffer& src, nframes_t cnt) +SMFSource::write_unlocked (MidiRingBuffer<double>& src, nframes_t cnt) { _write_data_count = 0; - Evoral::EventTime time; + double time; Evoral::EventType type; uint32_t size; @@ -208,7 +208,7 @@ SMFSource::write_unlocked (MidiRingBuffer& src, nframes_t cnt) if (_model && ! _model->writing()) _model->start_write(); - Evoral::MIDIEvent ev(0, 0.0, 4, NULL, true); + Evoral::MIDIEvent<double> ev(0, 0.0, 4, NULL, true); while (true) { bool ret = src.peek_time(&time); @@ -251,7 +251,7 @@ SMFSource::write_unlocked (MidiRingBuffer& src, nframes_t cnt) make_sure_controls_have_the_right_interpolation(); } - SMF::flush(); + Evoral::SMF<double>::flush(); free(buf); const nframes_t oldlen = _length; @@ -264,7 +264,7 @@ SMFSource::write_unlocked (MidiRingBuffer& src, nframes_t cnt) void -SMFSource::append_event_unlocked(EventTimeUnit unit, const Evoral::Event& ev) +SMFSource::append_event_unlocked(EventTimeUnit unit, const Evoral::Event<double>& ev) { if (ev.size() == 0) { cerr << "SMFSource: Warning: skipping empty event" << endl; @@ -299,7 +299,7 @@ SMFSource::append_event_unlocked(EventTimeUnit unit, const Evoral::Event& ev) delta_time = (uint32_t)((ev.time() - last_event_time()) * ppqn()); } - SMF::append_event_unlocked(delta_time, ev); + Evoral::SMF<double>::append_event_unlocked(delta_time, ev); _write_data_count += ev.size(); } @@ -354,7 +354,7 @@ void SMFSource::mark_streaming_midi_write_started (NoteMode mode, nframes_t start_frame) { MidiSource::mark_streaming_midi_write_started (mode, start_frame); - SMF::begin_write (start_frame); + Evoral::SMF<double>::begin_write (start_frame); } void @@ -367,7 +367,7 @@ SMFSource::mark_streaming_write_completed () } _model->set_edited(false); - SMF::end_write (); + Evoral::SMF<double>::end_write (); } void @@ -632,10 +632,10 @@ SMFSource::load_model(bool lock, bool force_reload) } _model->start_write(); - SMF::seek_to_start(); + Evoral::SMF<double>::seek_to_start(); uint64_t time = 0; /* in SMF ticks */ - Evoral::Event ev; + Evoral::Event<double> ev; size_t scratch_size = 0; // keep track of scratch and minimize reallocs @@ -655,7 +655,7 @@ SMFSource::load_model(bool lock, bool force_reload) if (ret > 0) { // didn't skip (meta) event // make ev.time absolute time in frames - ev.time() = time * frames_per_beat / (Evoral::EventTime)ppqn(); + ev.time() = time * frames_per_beat / (double)ppqn(); ev.set_event_type(EventTypeMap::instance().midi_event_type(buf[0])); _model->append(ev); } @@ -704,6 +704,6 @@ SMFSource::destroy_model() void SMFSource::flush_midi() { - SMF::end_write(); + Evoral::SMF<double>::end_write(); } |