move ownership of LTC I/O ports to Session, and manage as IO objects
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 25 Oct 2012 19:46:23 +0000 (19:46 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 25 Oct 2012 19:46:23 +0000 (19:46 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@13341 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/audioengine.h
libs/ardour/ardour/session.h
libs/ardour/audioengine.cc
libs/ardour/session.cc
libs/ardour/session_state.cc

index a908cf0bc160299260713bfc8af87cfb581d67bf..165ad6744f341db3d809bc56b22ee6f0744a748c 100644 (file)
@@ -260,9 +260,6 @@ _      the regular process() call to session->process() is not made.
 
        int create_process_thread (boost::function<void()>, pthread_t*, size_t stacksize);
 
-        boost::shared_ptr<Port> ltc_input_port() const { return _ltc_input; }
-        boost::shared_ptr<Port> ltc_output_port() const { return _ltc_output; }
-
 private:
        static AudioEngine*       _instance;
 
@@ -292,10 +289,6 @@ private:
         Glib::Threads::Thread*     m_meter_thread;
        ProcessThread*            _main_thread;
 
-        boost::shared_ptr<Port>   _ltc_input;
-        boost::shared_ptr<Port>   _ltc_output;
-        void reconnect_ltc ();
-
        SerializedRCUManager<Ports> ports;
 
        boost::shared_ptr<Port> register_port (DataType type, const std::string& portname, bool input);
index 2f9c114c0c0d09b494149cefb2982907b732dc49..e3376ae45fe2e76c50b3b93498c398b253a38f1c 100644 (file)
@@ -847,6 +847,9 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        /** Emitted when the session wants Ardour to quit */
        static PBD::Signal0<void> Quit;
 
+        boost::shared_ptr<Port> ltc_input_port() const;
+        boost::shared_ptr<Port> ltc_output_port() const;
+
   protected:
        friend class AudioEngine;
        void set_block_size (pframes_t nframes);
@@ -1554,6 +1557,12 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        bool ignore_route_processor_changes;
 
        MidiClockTicker* midi_clock;
+
+        boost::shared_ptr<IO>   _ltc_input;
+        boost::shared_ptr<IO>   _ltc_output;
+
+        void reconnect_ltc_input ();
+        void reconnect_ltc_output ();
 };
 
 } // namespace ARDOUR
index ef3899bf2f125cef513ed7cd061247f444f4a81d..2c57949074e2e4551cb45bccb531fb82fbe6042b 100644 (file)
@@ -78,8 +78,6 @@ AudioEngine::AudioEngine (string client_name, string session_uuid)
        , port_remove_in_progress (false)
        , m_meter_thread (0)
        , _main_thread (0)
-       , _ltc_input ()
-       , _ltc_output ()
        , ports (new Ports)
 {
        _instance = this; /* singleton */
@@ -91,34 +89,11 @@ AudioEngine::AudioEngine (string client_name, string session_uuid)
        }
 
        Port::set_engine (this);
-
-#ifdef HAVE_LTC
-       _ltc_input = register_port (DataType::AUDIO, _("LTC in"), true);
-
-       /* register_port() would allocate buffers and pass a shadow copy
-        * which is subject to ardour's route buffering behavioud and
-        * not suitable for generating LTC independent of transport state.
-        */
-       _ltc_output.reset(new AudioPort ("LTC out", Port::IsOutput));
-
-       /* As of October 2012, the LTC source port is the only thing that needs
-        * to care about Config parameters, so don't bother to listen if we're
-        * not doing LTC stuff. This might change if other parameters show up
-        * in the future that we need to care about with or without LTC.
-        */
-
-       Config->ParameterChanged.connect_same_thread (config_connection, boost::bind (&AudioEngine::parameter_changed, this, _1));
-#endif
 }
 
 AudioEngine::~AudioEngine ()
 {
        config_connection.disconnect ();
-#ifdef HAVE_LTC
-       if (_ltc_output && _ltc_output->jack_port()) {
-               jack_port_disconnect (_jack, _ltc_output->jack_port());
-       }
-#endif
 
        {
                Glib::Threads::Mutex::Lock tm (_process_lock);
@@ -234,9 +209,6 @@ AudioEngine::start ()
                        _running = true;
                        _has_run = true;
                        Running(); /* EMIT SIGNAL */
-
-                       reconnect_ltc ();
-
                } else {
                        // error << _("cannot activate JACK client") << endmsg;
                }
@@ -1513,8 +1485,6 @@ AudioEngine::reconnect_to_jack ()
 
        MIDI::Manager::instance()->reconnect ();
 
-       reconnect_ltc ();
-
        Running (); /* EMIT SIGNAL*/
 
        start_metering_thread ();
@@ -1659,29 +1629,3 @@ AudioEngine::destroy ()
        _instance = 0;
 }
 
-void
-AudioEngine::parameter_changed (const std::string& s)
-{
-       if (s == "ltc-source-port") {
-               reconnect_ltc ();
-       }
-       else if (s == "ltc-sink-port") {
-               // TODO
-       }
-
-}
-
-void
-AudioEngine::reconnect_ltc ()
-{
-       if (_ltc_input) {
-
-               string src = Config->get_ltc_source_port();
-
-               _ltc_input->disconnect_all ();
-
-               if (src != _("None") && !src.empty())  {
-                       _ltc_input->connect (src);
-               }
-       }
-}
index 8c36f95726961d0946f50bb6dcf59a1799966e43..c335e021aa616e7294ac25542db15af52c68aa2c 100644 (file)
@@ -145,7 +145,6 @@ Session::Session (AudioEngine &eng,
        , _bundles (new BundleList)
        , _bundle_xml_node (0)
        , _current_trans (0)
-       , _click_io ((IO*) 0)
        , click_data (0)
        , click_emphasis_data (0)
        , main_outs (0)
@@ -371,7 +370,30 @@ Session::when_engine_running ()
 
        try {
                XMLNode* child = 0;
+               
+               _ltc_input.reset (new IO (*this, _("LTC In"), IO::Input));
+               _ltc_output.reset (new IO (*this, _("LTC Out"), IO::Output));
+               
+               if (state_tree && (child = find_named_node (*state_tree->root(), "LTC-In")) != 0) {
+                       _ltc_input->set_state (*(child->children().front()), Stateful::loading_state_version);
+               } else {
+                       {
+                               Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
+                               _ltc_input->ensure_io (ChanCount (DataType::AUDIO, 1), true, this);
+                       }
+                       reconnect_ltc_input ();
+               }
 
+               if (state_tree && (child = find_named_node (*state_tree->root(), "LTC-Out")) != 0) {
+                       _ltc_output->set_state (*(child->children().front()), Stateful::loading_state_version);
+               } else {
+                       {
+                               Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
+                               _ltc_output->ensure_io (ChanCount (DataType::AUDIO, 1), true, this);
+                       }
+                       reconnect_ltc_output ();
+               }
+                                               
                _click_io.reset (new ClickIO (*this, "click"));
                _click_gain.reset (new Amp (*this));
                _click_gain->activate ();
@@ -4740,3 +4762,47 @@ Session::operation_in_progress (GQuark op) const
 {
        return (find (_current_trans_quarks.begin(), _current_trans_quarks.end(), op) != _current_trans_quarks.end());
 }
+
+boost::shared_ptr<Port>
+Session::ltc_input_port () const
+{
+       return _ltc_input->nth (0);
+}
+
+boost::shared_ptr<Port>
+Session::ltc_output_port () const
+{
+       return _ltc_output->nth (0);
+}
+
+void
+Session::reconnect_ltc_input ()
+{
+       if (_ltc_input) {
+
+               string src = Config->get_ltc_source_port();
+
+               _ltc_input->disconnect (this);
+
+               if (src != _("None") && !src.empty())  {
+                       _ltc_input->nth (0)->connect (src);
+               }
+       }
+}
+
+void
+Session::reconnect_ltc_output ()
+{
+       if (_ltc_output) {
+
+#if 0
+               string src = Config->get_ltc_sink_port();
+
+               _ltc_output->disconnect (this);
+
+               if (src != _("None") && !src.empty())  {
+                       _ltc_output->nth (0)->connect (src);
+               }
+#endif
+       }
+}
index 8cf58a7793e8acc82a60956aee84a533c2ee3c1e..1a566ec20eebb0a62329b8f5be8f2928400b4a6d 100644 (file)
@@ -1161,6 +1161,16 @@ Session::state (bool full_state)
                gain_child->add_child_nocopy (_click_gain->state (full_state));
        }
 
+       if (_ltc_input) {
+               XMLNode* ltc_input_child = node->add_child ("LTC-In");
+               ltc_input_child->add_child_nocopy (_ltc_input->state (full_state));
+       }
+
+       if (_ltc_input) {
+               XMLNode* ltc_output_child = node->add_child ("LTC-Out");
+               ltc_output_child->add_child_nocopy (_ltc_output->state (full_state));
+       }
+
         node->add_child_nocopy (_speakers->get_state());
        node->add_child_nocopy (_tempo_map->get_state());
        node->add_child_nocopy (get_control_protocol_state());
@@ -3551,6 +3561,10 @@ Session::config_changed (std::string p, bool ours)
                AudioSource::allocate_working_buffers (frame_rate());
        } else if (p == "automation-thinning-factor") {
                Evoral::ControlList::set_thinning_factor (Config->get_automation_thinning_factor());
+       } else if (p == "ltc-source-port") {
+               reconnect_ltc_input ();
+       } else if (p == "ltc-sink-port") {
+               reconnect_ltc_output ();
        }
 
        set_dirty ();