diff --git a/libs/ardour/ardour/transport_master.h b/libs/ardour/ardour/transport_master.h index 53e99fdcb3..aebd4cfe06 100644 --- a/libs/ardour/ardour/transport_master.h +++ b/libs/ardour/ardour/transport_master.h @@ -526,7 +526,7 @@ public: private: PBD::ScopedConnectionList port_connections; - PBD::ScopedConnection config_connection; + PBD::ScopedConnectionList session_connections; bool can_notify_on_unknown_rate; static const int sample_tolerance; @@ -566,7 +566,9 @@ private: void parse_timecode_offset (); void parameter_changed (std::string const& p); - void resync_latency (); + void connection_handler (boost::weak_ptr, std::string, boost::weak_ptr, std::string, bool); + void resync_latency (bool); + LatencyRange mtc_slave_latency; }; diff --git a/libs/ardour/mtc_slave.cc b/libs/ardour/mtc_slave.cc index 848e972244..622e4c5309 100644 --- a/libs/ardour/mtc_slave.cc +++ b/libs/ardour/mtc_slave.cc @@ -70,16 +70,12 @@ MTC_TransportMaster::MTC_TransportMaster (std::string const & name) , printed_timecode_warning (false) { init (); - - resync_latency(); - - AudioEngine::instance()->GraphReordered.connect_same_thread (port_connections, boost::bind (&MTC_TransportMaster::resync_latency, this)); } MTC_TransportMaster::~MTC_TransportMaster() { port_connections.drop_connections(); - config_connection.disconnect(); + session_connections.drop_connections(); if (_session && did_reset_tc_format) { _session->config.set_timecode_format (saved_tc_format); @@ -90,11 +86,28 @@ void MTC_TransportMaster::init () { reset (true); + resync_latency (false); } void -MTC_TransportMaster::resync_latency() +MTC_TransportMaster::connection_handler (boost::weak_ptr w0, std::string n0, boost::weak_ptr w1, std::string n1, bool con) { + TransportMaster::connection_handler(w0, n0, w1, n1, con); + + boost::shared_ptr p0 = w0.lock (); + boost::shared_ptr p1 = w1.lock (); + if (p0 == _port || p1 == _port) { + resync_latency (false); + } +} + +void +MTC_TransportMaster::resync_latency (bool playback) +{ + if (playback) { + return; + } + DEBUG_TRACE (DEBUG::MTC, "MTC resync_latency()\n"); if (_port) { @@ -113,8 +126,8 @@ MTC_TransportMaster::create_port () void MTC_TransportMaster::set_session (Session *s) { - config_connection.disconnect (); port_connections.drop_connections(); + session_connections.drop_connections(); _session = s; @@ -132,7 +145,8 @@ MTC_TransportMaster::set_session (Session *s) parser.mtc_qtr.connect_same_thread (port_connections, boost::bind (&MTC_TransportMaster::update_mtc_qtr, this, _1, _2, _3)); parser.mtc_status.connect_same_thread (port_connections, boost::bind (&MTC_TransportMaster::update_mtc_status, this, _1)); - _session->config.ParameterChanged.connect_same_thread (config_connection, boost::bind (&MTC_TransportMaster::parameter_changed, this, _1)); + _session->config.ParameterChanged.connect_same_thread (session_connections, boost::bind (&MTC_TransportMaster::parameter_changed, this, _1)); + _session->LatencyUpdated.connect_same_thread (session_connections, boost::bind (&MTC_TransportMaster::resync_latency, this, _1)); } } @@ -143,7 +157,7 @@ MTC_TransportMaster::pre_process (MIDI::pframes_t nframes, samplepos_t now, boos maybe_reset (); - now -= mtc_slave_latency.max; + now += mtc_slave_latency.max; _midi_port->read_and_parse_entire_midi_buffer_with_no_speed_adjustment (nframes, parser, now);