From 21054f6d8db2c69271bebb99c5a2800d38ae8afd Mon Sep 17 00:00:00 2001 From: nick_m Date: Wed, 31 Aug 2016 03:17:26 +1000 Subject: Add length_pulse to MidiSource, usr quarter-notes in midi_read(). - MidiSource _length_beats is in quarter notes. Here we duplicate length_beats for backwards compatibility --- libs/ardour/ardour/midi_source.h | 6 ++++-- libs/ardour/midi_source.cc | 18 ++++++++++++------ libs/ardour/smf_source.cc | 6 ++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/libs/ardour/ardour/midi_source.h b/libs/ardour/ardour/midi_source.h index c8b4263e2a..c2d029c63b 100644 --- a/libs/ardour/ardour/midi_source.h +++ b/libs/ardour/ardour/midi_source.h @@ -93,8 +93,8 @@ class LIBARDOUR_API MidiSource : virtual public Source, public boost::enable_sha MidiStateTracker* tracker, MidiChannelFilter* filter, const std::set& filtered, - double beat, - double start_beat) const; + const double pulse, + const double start_pulse) const; /** Write data from a MidiRingBuffer to this source. * @param source Source to read from. @@ -167,6 +167,7 @@ class LIBARDOUR_API MidiSource : virtual public Source, public boost::enable_sha void set_length_beats(TimeType l) { _length_beats = l; } TimeType length_beats() const { return _length_beats; } + double length_pulse() const { return _length_pulse; } virtual void load_model(const Glib::Threads::Mutex::Lock& lock, bool force_reload=false) = 0; virtual void destroy_model(const Glib::Threads::Mutex::Lock& lock) = 0; @@ -231,6 +232,7 @@ class LIBARDOUR_API MidiSource : virtual public Source, public boost::enable_sha mutable bool _model_iter_valid; mutable Evoral::Beats _length_beats; + mutable double _length_pulse; mutable framepos_t _last_read_end; /** The total duration of the current capture. */ diff --git a/libs/ardour/midi_source.cc b/libs/ardour/midi_source.cc index 97bce4b1ab..30318b361f 100644 --- a/libs/ardour/midi_source.cc +++ b/libs/ardour/midi_source.cc @@ -63,6 +63,7 @@ MidiSource::MidiSource (Session& s, string name, Source::Flag flags) , _writing(false) , _model_iter_valid(false) , _length_beats(0.0) + , _length_pulse(0.0) , _last_read_end(0) , _capture_length(0) , _capture_loop_length(0) @@ -74,6 +75,7 @@ MidiSource::MidiSource (Session& s, const XMLNode& node) , _writing(false) , _model_iter_valid(false) , _length_beats(0.0) + , _length_pulse(0.0) , _last_read_end(0) , _capture_length(0) , _capture_loop_length(0) @@ -194,11 +196,13 @@ MidiSource::midi_read (const Lock& lm, MidiStateTracker* tracker, MidiChannelFilter* filter, const std::set& filtered, - double beat, - double start_beat) const + const double pulse, + const double start_pulse) const { //BeatsFramesConverter converter(_session.tempo_map(), source_start); - + const int32_t tpb = Timecode::BBT_Time::ticks_per_beat; + const double pulse_tick_res = floor ((pulse * 4.0 * tpb) + 0.5) / tpb; + const double start_qn = (pulse - start_pulse) * 4.0; DEBUG_TRACE (DEBUG::MidiSourceIO, string_compose ("MidiSource::midi_read() %5 sstart %1 start %2 cnt %3 tracker %4\n", source_start, start, cnt, tracker, name())); @@ -250,7 +254,7 @@ MidiSource::midi_read (const Lock& lm, * some way (maybe keep an iterator per playlist). */ for (i = _model->begin(); i != _model->end(); ++i) { - if (i->time().to_double() + (beat - start_beat) >= beat) { + if (floor (((i->time().to_double() + start_qn) * tpb) + 0.5) / tpb >= pulse_tick_res) { break; } } @@ -265,8 +269,8 @@ MidiSource::midi_read (const Lock& lm, // Copy events in [start, start + cnt) into dst for (; i != _model->end(); ++i) { - const framecnt_t time_frames = _session.tempo_map().frame_at_beat (i->time().to_double() + (beat - start_beat)); + const framecnt_t time_frames = _session.tempo_map().frame_at_quarter_note (i->time().to_double() + start_qn); if (time_frames < start + cnt + source_start) { if (filter && filter->filter(i->buffer(), i->size())) { DEBUG_TRACE (DEBUG::MidiSourceIO, @@ -346,8 +350,10 @@ MidiSource::mark_write_starting_now (framecnt_t position, _capture_length = capture_length; _capture_loop_length = loop_length; - BeatsFramesConverter converter(_session.tempo_map(), position); + TempoMap& map (_session.tempo_map()); + BeatsFramesConverter converter(map, position); _length_beats = converter.from(capture_length); + _length_pulse = map.pulse_at_frame (position + capture_length) - map.pulse_at_frame (position); } void diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index 2aae26d847..dac78cd020 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -434,6 +434,8 @@ SMFSource::append_event_beats (const Glib::Threads::Mutex::Lock& lock, } _length_beats = max(_length_beats, time); + /* midi is in quarter note format as distinct from ardour beat */ + _length_pulse = _length_beats.to_double() / 4.0; const Evoral::Beats delta_time_beats = time - _last_ev_time_beats; const uint32_t delta_time_ticks = delta_time_beats.to_ticks(ppqn()); @@ -483,6 +485,8 @@ SMFSource::append_event_frames (const Glib::Threads::Mutex::Lock& lock, } _length_beats = max(_length_beats, ev_time_beats); + /* midi is in quarter note format as distinct from ardour beat */ + _length_pulse = _length_beats.to_double() / 4.0; const Evoral::Beats last_time_beats = converter.from (_last_ev_time_frames); const Evoral::Beats delta_time_beats = ev_time_beats - last_time_beats; @@ -695,6 +699,8 @@ SMFSource::load_model (const Glib::Threads::Mutex::Lock& lock, bool force_reload size = scratch_size; _length_beats = max(_length_beats, event_time); + /* midi is in quarter note format as distinct from ardour beat */ + _length_pulse = _length_beats.to_double() / 4.0; } /* event ID's must immediately precede the event they are for */ -- cgit v1.2.3