add new ::update_interval() method for transport masters, and use in shared ::speed_a...
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 4 Oct 2018 04:40:35 +0000 (00:40 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 4 Oct 2018 04:42:14 +0000 (00:42 -0400)
libs/ardour/ardour/transport_master.h
libs/ardour/disk_reader.cc
libs/ardour/engine_slave.cc
libs/ardour/ltc_slave.cc
libs/ardour/midi_clock_slave.cc
libs/ardour/mtc_slave.cc
libs/ardour/transport_master.cc

index f6dae4bff136271b69ee084d1fef75b7535338ab..e4fee4bba23871a4cf47189cdcf44ce785111d10 100644 (file)
@@ -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; }
index 375dda70759f0f4345e193223d07eb67b0c04fb5..4c62b03de25212ffa2cc0b65de9bb2115ec6d585 100644 (file)
@@ -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);
index a308557bcac2210e0a257b6be861c7e323ac89f7..451356536aef99189c289bc85b06f58dc0a23726 100644 (file)
@@ -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();
+}
+
index 71e560c2f56decbfc91fddae999ecb5a5a40bd68..9f8411103f80ca0569177b920bd8d1d0502decda 100644 (file)
@@ -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 */
index 7fd1c7a58e2f0af47e26db841b454a9839ba3f14..de371687fb40d508795f45447559cf2d772e20c6 100644 (file)
@@ -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
 {
index d89950068d48aab806281d2bf15e637c0fb4ba27..f8afe66d93d6986d59a3a5a91ff2155bd4f31c26 100644 (file)
@@ -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
 {
index 135e022dbffebaab50c4a19039affe7550fa18de..5d02eb00732dc64fb206e8515f6bd879b09fc617 100644 (file)
@@ -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;
                }
        }