From 22061310c0855aeb6183efddac0e20402d4e62b3 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 4 Oct 2018 00:40:35 -0400 Subject: add new ::update_interval() method for transport masters, and use in shared ::speed_and_position() implementation --- libs/ardour/ardour/transport_master.h | 12 ++++++++++++ libs/ardour/disk_reader.cc | 4 +++- libs/ardour/engine_slave.cc | 7 +++++++ libs/ardour/ltc_slave.cc | 14 ++++++++++++-- libs/ardour/midi_clock_slave.cc | 10 ++++++++++ libs/ardour/mtc_slave.cc | 10 ++++++++++ libs/ardour/transport_master.cc | 4 ++-- 7 files changed, 56 insertions(+), 5 deletions(-) diff --git a/libs/ardour/ardour/transport_master.h b/libs/ardour/ardour/transport_master.h index f6dae4bff1..e4fee4bba2 100644 --- a/libs/ardour/ardour/transport_master.h +++ b/libs/ardour/ardour/transport_master.h @@ -244,6 +244,14 @@ class LIBARDOUR_API TransportMaster : public PBD::Stateful { */ virtual samplecnt_t resolution() const = 0; + /** + * @return - the expected update interval for the data source used by + * this transport master. Even if the data is effectively continuous, + * this number indicates how long it is between changes to the known + * position of the master. + */ + virtual samplecnt_t update_interval() const = 0; + /** * @return - when returning true, ARDOUR will wait for seekahead_distance() before transport * starts rolling @@ -409,6 +417,7 @@ class LIBARDOUR_API MTC_TransportMaster : public TimecodeTransportMaster, public bool ok() const; void handle_locate (const MIDI::byte*); + samplecnt_t update_interval () const; samplecnt_t resolution () const; bool requires_seekahead () const { return false; } samplecnt_t seekahead_distance() const; @@ -474,6 +483,7 @@ public: bool locked() const; bool ok() const; + samplecnt_t update_interval () const; samplecnt_t resolution () const; bool requires_seekahead () const { return false; } samplecnt_t seekahead_distance () const { return 0; } @@ -538,6 +548,7 @@ class LIBARDOUR_API MIDIClock_TransportMaster : public TransportMaster, public T bool ok() const; bool starting() const; + samplecnt_t update_interval () const; samplecnt_t resolution () const; bool requires_seekahead () const { return false; } void init (); @@ -597,6 +608,7 @@ class LIBARDOUR_API Engine_TransportMaster : public TransportMaster bool starting() const { return _starting; } bool locked() const; bool ok() const; + samplecnt_t update_interval () const; samplecnt_t resolution () const { return 1; } bool requires_seekahead () const { return false; } bool sample_clock_synced() const { return true; } diff --git a/libs/ardour/disk_reader.cc b/libs/ardour/disk_reader.cc index 375dda7075..4c62b03de2 100644 --- a/libs/ardour/disk_reader.cc +++ b/libs/ardour/disk_reader.cc @@ -345,7 +345,9 @@ DiskReader::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp } if ((speed > 0) && (start_sample != playback_sample)) { - cerr << owner()->name() << " playback not aligned, jump ahead " << (start_sample - playback_sample) << endl; + stringstream str; + str << owner()->name() << " playback @ " << start_sample << " not aligned with " << playback_sample << " jump ahead " << (start_sample - playback_sample) << endl; + cerr << str.str(); if (can_internal_playback_seek (start_sample - playback_sample)) { internal_playback_seek (start_sample - playback_sample); diff --git a/libs/ardour/engine_slave.cc b/libs/ardour/engine_slave.cc index a308557bca..451356536a 100644 --- a/libs/ardour/engine_slave.cc +++ b/libs/ardour/engine_slave.cc @@ -125,3 +125,10 @@ Engine_TransportMaster::allow_request (TransportRequestSource src, TransportRequ return true; } + +samplecnt_t +Engine_TransportMaster::update_interval () const +{ + return AudioEngine::instance()->samples_per_cycle(); +} + diff --git a/libs/ardour/ltc_slave.cc b/libs/ardour/ltc_slave.cc index 71e560c2f5..9f8411103f 100644 --- a/libs/ardour/ltc_slave.cc +++ b/libs/ardour/ltc_slave.cc @@ -142,6 +142,16 @@ LTC_TransportMaster::parameter_changed (std::string const & p) } } +ARDOUR::samplecnt_t +LTC_TransportMaster::update_interval() const +{ + if (timecode.rate) { + return AudioEngine::instance()->sample_rate() / timecode.rate; + } + + return AudioEngine::instance()->sample_rate(); /* useless but what other answer is there? */ +} + ARDOUR::samplecnt_t LTC_TransportMaster::resolution () const { @@ -459,7 +469,7 @@ LTC_TransportMaster::process_ltc(samplepos_t const now) samplepos_t cur_timestamp = sample.off_end + 1; double ltc_speed = current.speed; - DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC S: %1 LS: %2 N: %3 L: %4\n", ltc_sample, current.position, cur_timestamp, current.timestamp)); + DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC S: %1 LS: %2 N: %3 L: %4 span %5..%6\n", ltc_sample, current.position, cur_timestamp, current.timestamp, sample.off_start, sample.off_end)); if (cur_timestamp <= current.timestamp || current.timestamp == 0) { DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC speed: UNCHANGED: %1\n", current.speed)); @@ -477,7 +487,7 @@ LTC_TransportMaster::process_ltc(samplepos_t const now) DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC speed: %1\n", ltc_speed)); } - + DEBUG_TRACE (DEBUG::LTC, string_compose ("update current to %1 %2 %3\n", ltc_sample, cur_timestamp, ltc_speed)); current.update (ltc_sample, cur_timestamp, ltc_speed); } /* end foreach decoded LTC sample */ diff --git a/libs/ardour/midi_clock_slave.cc b/libs/ardour/midi_clock_slave.cc index 7fd1c7a58e..de371687fb 100644 --- a/libs/ardour/midi_clock_slave.cc +++ b/libs/ardour/midi_clock_slave.cc @@ -375,6 +375,16 @@ MIDIClock_TransportMaster::starting() const return false; } +ARDOUR::samplecnt_t +MIDIClock_TransportMaster::update_interval() const +{ + if (one_ppqn_in_samples) { + return resolution (); + } + + return AudioEngine::instance()->sample_rate() / 120 / 4; /* pure guesswork */ +} + ARDOUR::samplecnt_t MIDIClock_TransportMaster::resolution() const { diff --git a/libs/ardour/mtc_slave.cc b/libs/ardour/mtc_slave.cc index d89950068d..f8afe66d93 100644 --- a/libs/ardour/mtc_slave.cc +++ b/libs/ardour/mtc_slave.cc @@ -164,6 +164,16 @@ MTC_TransportMaster::parameter_changed (std::string const & p) } } +ARDOUR::samplecnt_t +MTC_TransportMaster::update_interval() const +{ + if (timecode.rate) { + return AudioEngine::instance()->sample_rate() / timecode.rate; + } + + return AudioEngine::instance()->sample_rate(); /* useless but what other answer is there? */ +} + ARDOUR::samplecnt_t MTC_TransportMaster::resolution () const { diff --git a/libs/ardour/transport_master.cc b/libs/ardour/transport_master.cc index 135e022dbf..5d02eb0073 100644 --- a/libs/ardour/transport_master.cc +++ b/libs/ardour/transport_master.cc @@ -99,7 +99,7 @@ TransportMaster::speed_and_position (double& speed, samplepos_t& pos, samplepos_ return false; } - if (last.timestamp && now > last.timestamp && now - last.timestamp > labs (seekahead_distance())) { + if (last.timestamp && now > last.timestamp && now - last.timestamp > (2.0 * update_interval())) { /* no timecode for two cycles - conclude that it's stopped */ if (!Config->get_transport_masters_just_roll_when_sync_lost()) { @@ -109,7 +109,7 @@ TransportMaster::speed_and_position (double& speed, samplepos_t& pos, samplepos_ when = last.timestamp; _current_delta = 0; // queue_reset (false); - DEBUG_TRACE (DEBUG::Slave, string_compose ("%1 not seen for 2 samples - reset pending, pos = %2\n", name(), pos)); + DEBUG_TRACE (DEBUG::Slave, string_compose ("%1 not seen since %2 vs %3 (%4) with seekahead = %5 reset pending, pos = %6\n", name(), last.timestamp, now, (now - last.timestamp), update_interval(), pos)); return false; } } -- cgit v1.2.3