move VCA assignment up to Route level
[ardour.git] / libs / ardour / route.cc
index 6cd593d5adbd8ee4c20e5ad307f58f0a7159bd43..edffc3f3cec7cb03a662bf0370a7eeaacae23575 100644 (file)
@@ -69,6 +69,7 @@
 #include "ardour/session.h"
 #include "ardour/unknown_processor.h"
 #include "ardour/utils.h"
+#include "ardour/vca.h"
 
 #include "i18n.h"
 
@@ -82,7 +83,7 @@ PBD::Signal3<int,boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, Rout
 
 /** Base class for all routable/mixable objects (tracks and busses) */
 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
-       : SessionObject (sess, name)
+       : Stripable (sess, name)
        , Automatable (sess)
        , GraphNode (sess._process_graph)
        , _active (true)
@@ -172,14 +173,9 @@ Route::init ()
        _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
        _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
 
-#if 0 // not used - just yet
-       if (!is_master() && !is_monitor() && !is_auditioner()) {
-               _delayline.reset (new DelayLine (_session, _name));
-               add_processor (_delayline, PreFader);
-       }
-#endif
-
-       /* add amp processor  */
+       /* add the amp/fader processor.
+        * it should be the first processor to be added on every route.
+        */
 
        _gain_control = boost::shared_ptr<GainControllable> (new GainControllable (_session, GainAutomation, shared_from_this ()));
        add_control (_gain_control);
@@ -191,6 +187,13 @@ Route::init ()
                _amp->set_display_name (_("Monitor"));
        }
 
+#if 0 // not used - just yet
+       if (!is_master() && !is_monitor() && !is_auditioner()) {
+               _delayline.reset (new DelayLine (_session, _name));
+               add_processor (_delayline, PreFader);
+       }
+#endif
+
        /* and input trim */
 
        _trim_control = boost::shared_ptr<GainControllable> (new GainControllable (_session, TrimAutomation, shared_from_this ()));
@@ -3343,7 +3346,7 @@ Route::set_processor_state (const XMLNode& node)
 
        for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
 
-               XMLProperty const * prop = (*niter)->property ("type");
+               XMLProperty* prop = (*niter)->property ("type");
 
                if (prop->value() == "amp") {
                        _amp->set_state (**niter, Stateful::current_state_version);
@@ -4729,13 +4732,13 @@ Route::gain_control() const
        return _gain_control;
 }
 
-boost::shared_ptr<GainControl>
+boost::shared_ptr<AutomationControl>
 Route::trim_control() const
 {
        return _trim_control;
 }
 
-boost::shared_ptr<Route::PhaseControllable>
+boost::shared_ptr<AutomationControl>
 Route::phase_control() const
 {
        if (phase_invert().size()) {
@@ -5051,12 +5054,13 @@ Route::setup_invisible_processors ()
 
        /* find the amp */
 
-       ProcessorList::iterator amp = new_processors.begin ();
-       while (amp != new_processors.end() && *amp != _amp) {
-               ++amp;
-       }
+       ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
 
-       assert (amp != new_processors.end ());
+       if (amp == new_processors.end ()) {
+               error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
+               new_processors.push_front (_amp);
+               amp = find (new_processors.begin(), new_processors.end(), _amp);
+       }
 
        /* and the processor after the amp */
 
@@ -5880,3 +5884,33 @@ Route::master_send_enable_controllable () const
        return boost::shared_ptr<AutomationControl>();
 #endif
 }
+
+bool
+Route::slaved_to (boost::shared_ptr<VCA> vca) const
+{
+       if (!vca || !_gain_control) {
+               return false;
+       }
+
+       return _gain_control->slaved_to (vca);
+}
+
+void
+Route::vca_assign (boost::shared_ptr<VCA> vca)
+{
+       _gain_control->add_master (vca);
+       vca->add_solo_mute_target (shared_from_this());
+}
+
+void
+Route::vca_unassign (boost::shared_ptr<VCA> vca)
+{
+       if (!vca) {
+               /* unassign from all */
+               _gain_control->clear_masters ();
+               /* XXXX need to remove from solo/mute target lists */
+       } else {
+               _gain_control->remove_master (vca);
+               vca->remove_solo_mute_target (shared_from_this());
+       }
+}