From 0047b87e3dba286906097d5b15ca73b5b529b0eb Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 26 Oct 2012 11:39:10 +0000 Subject: [PATCH] LTC Slave - re-init on xrun or graph change git-svn-id: svn://localhost/ardour2/branches/3.0@13350 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/session.h | 3 +++ libs/ardour/ardour/slave.h | 3 +++ libs/ardour/ltc_slave.cc | 26 ++++++++++++++++++++++---- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 33fadcd6bd..c5172c337d 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -850,6 +850,9 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi boost::shared_ptr ltc_input_port() const; boost::shared_ptr ltc_output_port() const; + boost::shared_ptr ltc_input_io() { return _ltc_input; } + boost::shared_ptr ltc_output_io() { return _ltc_output; } + protected: friend class AudioEngine; void set_block_size (pframes_t nframes); diff --git a/libs/ardour/ardour/slave.h b/libs/ardour/ardour/slave.h index e96a90fc76..0ff1da7884 100644 --- a/libs/ardour/ardour/slave.h +++ b/libs/ardour/ardour/slave.h @@ -380,6 +380,9 @@ public: Timecode::TimecodeFormat ltc_timecode; Timecode::TimecodeFormat a3e_timecode; + PBD::ScopedConnectionList port_connections; + jack_latency_range_t ltc_slave_latency; + /* DLL - chase LTC */ int transport_direction; int engine_dll_initstate; diff --git a/libs/ardour/ltc_slave.cc b/libs/ardour/ltc_slave.cc index 3be0ce6c82..12386eeb18 100644 --- a/libs/ardour/ltc_slave.cc +++ b/libs/ardour/ltc_slave.cc @@ -61,10 +61,14 @@ LTC_Slave::LTC_Slave (Session& s) decoder = ltc_decoder_create((int) frames_per_ltc_frame, 128 /*queue size*/); reset(); + session.Xrun.connect_same_thread (port_connections, boost::bind (<C_Slave::reset, this)); + session.engine().GraphReordered.connect_same_thread (port_connections, boost::bind (<C_Slave::reset, this)); } LTC_Slave::~LTC_Slave() { + port_connections.drop_connections(); + if (did_reset_tc_format) { session.config.set_timecode_format (saved_tc_format); } @@ -99,6 +103,11 @@ LTC_Slave::reset() transport_direction = 0; ltc_speed = 0; engine_dll_initstate = 0; + + if (session.ltc_output_io()) { /* check if Port exits */ + boost::shared_ptr ltcport = session.ltc_input_port(); + ltcport->get_connected_latency_range(ltc_slave_latency, false); + } } void @@ -351,15 +360,24 @@ LTC_Slave::speed_and_position (double& speed, framepos_t& pos) framecnt_t nframes = session.engine().frames_per_cycle(); jack_default_audio_sample_t *in; - jack_latency_range_t ltc_latency; boost::shared_ptr ltcport = session.ltc_input_port(); - ltcport->get_connected_latency_range(ltc_latency, false); + +#if 1 + /* TODO read layency only on demand -> ::reset() + * this is already prepared. + * + * ..but first fix jack2 issue with re-computing latency + * in the correct order. Until then, querying it in the + * process-callback is the only way to get the current value + */ + ltcport->get_connected_latency_range(ltc_slave_latency, false); +#endif in = (jack_default_audio_sample_t*) jack_port_get_buffer (ltcport->jack_port(), nframes); frameoffset_t skip = now - (monotonic_cnt + nframes); monotonic_cnt = now; - DEBUG_TRACE (DEBUG::LTC, string_compose ("speed_and_position - TID:%1 | latency: %2 | skip %3\n", ::pthread_self(), ltc_latency.max, skip)); + DEBUG_TRACE (DEBUG::LTC, string_compose ("speed_and_position - TID:%1 | latency: %2 | skip %3\n", ::pthread_self(), ltc_slave_latency.max, skip)); if (last_timestamp == 0) { engine_dll_initstate = 0; @@ -390,7 +408,7 @@ LTC_Slave::speed_and_position (double& speed, framepos_t& pos) reset(); } - parse_ltc(nframes, in, now + ltc_latency.max ); + parse_ltc(nframes, in, now + ltc_slave_latency.max ); process_ltc(now); }