(re)implement Yevgeny's LTC branch changes in the context of ardour-merge-from-tracks...
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 26 May 2015 00:56:03 +0000 (20:56 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 29 Jun 2015 18:18:15 +0000 (14:18 -0400)
libs/ardour/ardour/session.h
libs/ardour/ardour/slave.h
libs/ardour/ltc_slave.cc
libs/ardour/session.cc
libs/ardour/session_transport.cc
libs/ardour/utils.cc

index a2f8c164c8659b59a2760ff66794c17cfe6fc4e2..f75e38cff657a2a182e3da733116b38b8b7cc8bc 100644 (file)
@@ -300,7 +300,8 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
 
        /* Timecode status signals */
        PBD::Signal1<void, bool> MTCSyncStateChanged;
-       
+       PBD::Signal1<void, bool> LTCSyncStateChanged;   
+
        /* Record status signals */
 
        PBD::Signal0<void> RecordStateChanged; /* signals changes in recording state (i.e. are we recording) */
@@ -610,6 +611,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        void   request_sync_source (Slave*);
        bool   synced_to_engine() const { return _slave && config.get_external_sync() && Config->get_sync_source() == Engine; }
        bool   synced_to_mtc () const { return config.get_external_sync() && Config->get_sync_source() == MTC && g_atomic_int_get (const_cast<gint*>(&_mtc_active)); }
+       bool   synced_to_ltc () const { return config.get_external_sync() && Config->get_sync_source() == LTC && g_atomic_int_get (const_cast<gint*>(&_ltc_active)); }
        
        double transport_speed() const { return _transport_speed; }
        bool   transport_stopped() const { return _transport_speed == 0.0f; }
@@ -1017,6 +1019,9 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        void reconnect_mtc_ports ();
        void reconnect_mmc_ports (bool);
 
+       void reconnect_ltc_input ();
+       void reconnect_ltc_output ();
+       
   protected:
        friend class AudioEngine;
        void set_block_size (pframes_t nframes);
@@ -1090,6 +1095,8 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
 
        void mtc_status_changed (bool);
        PBD::ScopedConnection mtc_status_connection;
+       void ltc_status_changed (bool);
+       PBD::ScopedConnection ltc_status_connection;
        
        void initialize_latencies ();
        void set_worst_io_latencies ();
@@ -1129,6 +1136,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
 
        SlaveState _slave_state;
        gint _mtc_active;
+       gint _ltc_active;
        framepos_t slave_wait_end;
 
        void reset_slave_state ();
@@ -1796,9 +1804,6 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        boost::shared_ptr<IO>   _ltc_input;
        boost::shared_ptr<IO>   _ltc_output;
 
-       void reconnect_ltc_input ();
-       void reconnect_ltc_output ();
-
        /* Scene Changing */
        SceneChanger* _scene_changer;
        
index 2beacd7bf7de0b6fced86606a8a89fa4e2c84f34..bda47ceba099ca89f2f51c341cb1ed6eaa46c89e 100644 (file)
@@ -237,19 +237,21 @@ struct LIBARDOUR_API SafeTime {
 
 class LIBARDOUR_API TimecodeSlave : public Slave {
   public:
-    TimecodeSlave () {}
-
-    virtual Timecode::TimecodeFormat apparent_timecode_format() const = 0;
-
-    /* this is intended to be used by a UI and polled from a timeout. it should
-       return a string describing the current position of the TC source. it
-       should NOT do any computation, but should use a cached value
-       of the TC source position.
-    */
-    virtual std::string approximate_current_position() const = 0;
-
-    framepos_t        timecode_offset;
-    bool              timecode_negative_offset;
+       TimecodeSlave () {}
+       
+       virtual Timecode::TimecodeFormat apparent_timecode_format() const = 0;
+       
+       /* this is intended to be used by a UI and polled from a timeout. it should
+          return a string describing the current position of the TC source. it
+          should NOT do any computation, but should use a cached value
+          of the TC source position.
+       */
+       virtual std::string approximate_current_position() const = 0;
+       
+       framepos_t        timecode_offset;
+       bool              timecode_negative_offset;
+       
+       PBD::Signal1<void, bool> ActiveChanged;
 };
 
 class LIBARDOUR_API MTC_Slave : public TimecodeSlave {
@@ -273,8 +275,6 @@ class LIBARDOUR_API MTC_Slave : public TimecodeSlave {
         std::string approximate_current_position() const;
        std::string approximate_current_delta() const;
 
-       PBD::Signal1<void, bool> ActiveChanged;
-    
   private:
        Session&    session;
        MidiPort*   port;
index c5840f68d4f0ad76a306ce356c8efa53b70aeec2..5f15f460f819f765aeec5c54a7ff580a9a8ace06 100644 (file)
@@ -26,6 +26,7 @@
 #include "pbd/pthread_utils.h"
 
 #include "ardour/debug.h"
+#include "ardour/profile.h"
 #include "ardour/slave.h"
 #include "ardour/session.h"
 #include "ardour/audioengine.h"
@@ -151,6 +152,8 @@ LTC_Slave::reset()
        ltc_speed = 0;
        engine_dll_initstate = 0;
        sync_lock_broken = false;
+
+       ActiveChanged (false); /* EMIT SIGNAL */
 }
 
 void
@@ -443,8 +446,10 @@ LTC_Slave::speed_and_position (double& speed, framepos_t& pos)
        if (last_timestamp == 0) {
                engine_dll_initstate = 0;
                if (delayedlocked < 10) ++delayedlocked;
-       }
-       else if (engine_dll_initstate != transport_direction && ltc_speed != 0) {
+       } else if (engine_dll_initstate != transport_direction && ltc_speed != 0) {
+
+               ActiveChanged (true); /* EMIT SIGNAL */
+
                engine_dll_initstate = transport_direction;
                init_engine_dll(last_ltc_frame + rint(ltc_speed * double(2 * nframes + now - last_timestamp)),
                                session.engine().samples_per_cycle());
@@ -488,6 +493,7 @@ LTC_Slave::speed_and_position (double& speed, framepos_t& pos)
                reset();
                speed = 0;
                pos = session.transport_frame();
+               ActiveChanged (false); /* EMIT SIGNAL */
                return true;
        }
 
index eb6e97cd0e355c028e19533a0348d529d2728212..ef7bf5d200c1de648dd3d8990909961013b5d8ef 100644 (file)
@@ -191,7 +191,8 @@ Session::Session (AudioEngine &eng,
        , average_dir (0)
        , have_first_delta_accumulator (false)
        , _slave_state (Stopped)
-    , _mtc_active (false)
+       , _mtc_active (false)
+       , _ltc_active (false)
        , post_export_sync (false)
        , post_export_position (0)
        , _exporting (false)
@@ -6132,6 +6133,11 @@ Session::reconnect_ltc_input ()
                if (src != _("None") && !src.empty())  {
                        _ltc_input->nth (0)->connect (src);
                }
+
+               if ( ARDOUR::Profile->get_trx () ) {
+                       // Tracks need this signal to update timecode_source_dropdown
+                       MtcOrLtcInputPortChanged (); //emit signal
+               }
        }
 }
 
@@ -6140,15 +6146,13 @@ Session::reconnect_ltc_output ()
 {
        if (_ltc_output) {
 
-#if 0
-               string src = Config->get_ltc_sink_port();
+               string src = Config->get_ltc_output_port();
 
                _ltc_output->disconnect (this);
 
                if (src != _("None") && !src.empty())  {
                        _ltc_output->nth (0)->connect (src);
                }
-#endif
        }
 }
 
index c0765c399169aace0db3661445a5fd4706fc22b3..80bfb109987a56d5c968e216df96fbd1b9c72346 100644 (file)
@@ -1618,6 +1618,13 @@ Session::mtc_status_changed (bool yn)
        MTCSyncStateChanged( yn );
 }
 
+void
+Session::ltc_status_changed (bool yn)
+{
+       g_atomic_int_set (&_ltc_active, yn);
+       LTCSyncStateChanged( yn );
+}
+
 void
 Session::use_sync_source (Slave* new_slave)
 {
@@ -1642,6 +1649,18 @@ Session::use_sync_source (Slave* new_slave)
                mtc_status_connection.disconnect ();
        }
 
+       LTC_Slave* ltc_slave = dynamic_cast<LTC_Slave*> (_slave);
+       if (ltc_slave) {
+               ltc_slave->ActiveChanged.connect_same_thread (ltc_status_connection, boost::bind (&Session::ltc_status_changed, this, _1));
+               LTCSyncStateChanged (ltc_slave->locked() );
+       } else {
+               if (g_atomic_int_get (&_ltc_active) ){
+                       g_atomic_int_set (&_ltc_active, 0);
+                       LTCSyncStateChanged( false );
+               }
+               ltc_status_connection.disconnect ();
+       }
+
        DEBUG_TRACE (DEBUG::Slave, string_compose ("set new slave to %1\n", _slave));
        
        // need to queue this for next process() cycle
index 6d6511bb9f5f377c29d7cd4eb014fcdefe54e45f..2ada8ce79beaf294126a806cc6cc776a2751a0ba 100644 (file)
@@ -467,6 +467,10 @@ ARDOUR::string_to_sync_source (string str)
                return Engine;
        }
 
+       if (str == _("LTC")) {
+               return LTC;
+       }
+
        fatal << string_compose (_("programming error: unknown sync source string \"%1\""), str) << endmsg;
        abort(); /*NOTREACHED*/
        return Engine;