new files added
[ardour.git] / libs / ardour / route.cc
index 507d33761954ec375ac6bbac636a41bfc935e3cd..be7dfb846973aa67c1c49016d84e8d4f3e420d0d 100644 (file)
@@ -53,21 +53,21 @@ using namespace ARDOUR;
 using namespace PBD;
 
 uint32_t Route::order_key_cnt = 0;
-
+sigc::signal<void> Route::SyncOrderKeys;
 
 Route::Route (Session& sess, string name, int input_min, int input_max, int output_min, int output_max, Flag flg, DataType default_type)
        : IO (sess, name, input_min, input_max, output_min, output_max, default_type),
          _flags (flg),
-         _solo_control (X_("solo"), *this, ToggleControllable::SoloControl),
-         _mute_control (X_("mute"), *this, ToggleControllable::MuteControl)
+         _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl)),
+         _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
 {
        init ();
 }
 
 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
        : IO (sess, *node.child ("IO"), default_type),
-         _solo_control (X_("solo"), *this, ToggleControllable::SoloControl),
-         _mute_control (X_("mute"), *this, ToggleControllable::MuteControl)
+         _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl)),
+         _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
 {
        init ();
        _set_state (node, false);
@@ -161,9 +161,34 @@ void
 Route::set_order_key (const char* name, long n)
 {
        order_keys[strdup(name)] = n;
+
+       if (Config->get_sync_all_route_ordering()) {
+               for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
+                       x->second = n;
+               }
+       } 
+
        _session.set_dirty ();
 }
 
+void
+Route::sync_order_keys ()
+{
+       uint32_t key;
+       
+       if (order_keys.empty()) {
+               return;
+       }
+       
+       OrderKeys::iterator x = order_keys.begin();
+       key = x->second;
+       ++x;
+
+       for (; x != order_keys.end(); ++x) {
+               x->second = key;
+       }
+}
+
 void
 Route::inc_gain (gain_t fraction, void *src)
 {
@@ -177,33 +202,33 @@ Route::set_gain (gain_t val, void *src)
                
                if (_mix_group->is_relative()) {
                        
-                       
-                       gain_t usable_gain  = gain();
+                       gain_t usable_gain = gain();
                        if (usable_gain < 0.000001f) {
-                               usable_gain=0.000001f;
+                               usable_gain = 0.000001f;
                        }
                                                
                        gain_t delta = val;
                        if (delta < 0.000001f) {
-                               delta=0.000001f;
+                               delta = 0.000001f;
                        }
 
                        delta -= usable_gain;
 
-                       if (delta == 0.0f) return;
+                       if (delta == 0.0f)
+                               return;
 
                        gain_t factor = delta / usable_gain;
 
                        if (factor > 0.0f) {
                                factor = _mix_group->get_max_factor(factor);
                                if (factor == 0.0f) {
-                                       gain_changed (src);
+                                       _gain_control->Changed(); /* EMIT SIGNAL */
                                        return;
                                }
                        } else {
                                factor = _mix_group->get_min_factor(factor);
                                if (factor == 0.0f) {
-                                       gain_changed (src);
+                                       _gain_control->Changed(); /* EMIT SIGNAL */
                                        return;
                                }
                        }
@@ -295,17 +320,17 @@ Route::process_output_buffers (BufferSet& bufs,
           -------------------------------------------------------------------------------------------------- */
 
        if (declick > 0) {
-               Amp::run (bufs, nframes, 0.0, 1.0, false);
+               Amp::run_in_place (bufs, nframes, 0.0, 1.0, false);
                _pending_declick = 0;
        } else if (declick < 0) {
-               Amp::run (bufs, nframes, 1.0, 0.0, false);
+               Amp::run_in_place (bufs, nframes, 1.0, 0.0, false);
                _pending_declick = 0;
        } else {
 
                /* no global declick */
 
                if (solo_gain != dsg) {
-                       Amp::run (bufs, nframes, solo_gain, dsg, false);
+                       Amp::run_in_place (bufs, nframes, solo_gain, dsg, false);
                        solo_gain = dsg;
                }
        }
@@ -320,7 +345,7 @@ Route::process_output_buffers (BufferSet& bufs,
        }
 
        if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
-               Amp::run (bufs, nframes, mute_gain, dmg, false);
+               Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
                mute_gain = dmg;
                mute_declick_applied = true;
        }
@@ -381,7 +406,7 @@ Route::process_output_buffers (BufferSet& bufs,
                                for (i = _processors.begin(); i != _processors.end(); ++i) {
                                        switch ((*i)->placement()) {
                                        case PreFader:
-                                               (*i)->run (bufs, start_frame, end_frame, nframes, offset);
+                                               (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
                                                break;
                                        case PostFader:
                                                post_fader_work = true;
@@ -407,7 +432,7 @@ Route::process_output_buffers (BufferSet& bufs,
        bufs.set_count(pre_fader_streams());
        
        if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader) {
-               Amp::run (bufs, nframes, mute_gain, dmg, false);
+               Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
                mute_gain = dmg;
                mute_declick_applied = true;
        }
@@ -417,7 +442,7 @@ Route::process_output_buffers (BufferSet& bufs,
           -------------------------------------------------------------------------------------------------- */
 
        if (meter && (_meter_point == MeterPreFader)) {
-               _meter->run(bufs, start_frame, end_frame, nframes, offset);
+               _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
        }
 
        
@@ -460,13 +485,9 @@ Route::process_output_buffers (BufferSet& bufs,
                
            // OR recording 
                
-               // h/w monitoring not in use 
-               
-               (!Config->get_monitoring_model() == HardwareMonitoring && 
-
                 // AND software monitoring required
 
-                Config->get_monitoring_model() == SoftwareMonitoring)) { 
+               Config->get_monitoring_model() == SoftwareMonitoring) { 
                
                if (apply_gain_automation) {
                        
@@ -498,7 +519,7 @@ Route::process_output_buffers (BufferSet& bufs,
                        
                        if (_gain != dg) {
                                
-                               Amp::run (bufs, nframes, _gain, dg, _phase_invert);
+                               Amp::run_in_place (bufs, nframes, _gain, dg, _phase_invert);
                                _gain = dg;
                                
                        } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
@@ -551,7 +572,7 @@ Route::process_output_buffers (BufferSet& bufs,
                                        case PreFader:
                                                break;
                                        case PostFader:
-                                               (*i)->run (bufs, start_frame, end_frame, nframes, offset);
+                                               (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
                                                break;
                                        }
                                }
@@ -570,7 +591,7 @@ Route::process_output_buffers (BufferSet& bufs,
        }
 
        if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_control_outs) {
-               Amp::run (bufs, nframes, mute_gain, dmg, false);
+               Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
                mute_gain = dmg;
                mute_declick_applied = true;
        }
@@ -615,7 +636,7 @@ Route::process_output_buffers (BufferSet& bufs,
           ----------------------------------------------------------------------*/
 
        if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
-               Amp::run (bufs, nframes, mute_gain, dmg, false);
+               Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
                mute_gain = dmg;
                mute_declick_applied = true;
        }
@@ -677,7 +698,7 @@ Route::process_output_buffers (BufferSet& bufs,
                if ((_gain == 0 && !apply_gain_automation) || dmg == 0) {
                        _meter->reset();
                } else {
-                       _meter->run(output_buffers(), start_frame, end_frame, nframes, offset);
+                       _meter->run_in_place(output_buffers(), start_frame, end_frame, nframes, offset);
                }
        }
 }
@@ -698,7 +719,7 @@ Route::passthru (nframes_t start_frame, nframes_t end_frame, nframes_t nframes,
        collect_input (bufs, nframes, offset);
 
        if (meter_first) {
-               _meter->run(bufs, start_frame, end_frame, nframes, offset);
+               _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
                meter_first = false;
        }
                
@@ -726,7 +747,7 @@ Route::set_solo (bool yn, void *src)
        if (_soloed != yn) {
                _soloed = yn;
                solo_changed (src); /* EMIT SIGNAL */
-               _solo_control.Changed (); /* EMIT SIGNAL */
+               _solo_control->Changed (); /* EMIT SIGNAL */
        }
 }
 
@@ -763,7 +784,7 @@ Route::set_mute (bool yn, void *src)
                _muted = yn;
                mute_changed (src); /* EMIT SIGNAL */
                
-               _mute_control.Changed (); /* EMIT SIGNAL */
+               _mute_control->Changed (); /* EMIT SIGNAL */
                
                Glib::Mutex::Lock lm (declick_lock);
                desired_mute_gain = (yn?0.0f:1.0f);
@@ -1221,6 +1242,8 @@ Route::apply_some_plugin_counts (list<ProcessorCount>& iclist)
 
        for (i = iclist.begin(); i != iclist.end(); ++i) {
                
+               cerr << "now applying for " << (*i).processor->name() << " in = " << (*i).in.n_audio() << " out = " << (*i).out.n_audio() << endl;
+
                if ((*i).processor->configure_io ((*i).in, (*i).out)) {
                        return -1;
                }
@@ -1249,6 +1272,9 @@ Route::check_some_plugin_counts (list<ProcessorCount>& iclist, ChanCount require
 
        for (i = iclist.begin(); i != iclist.end(); ++i) {
 
+
+               cerr << "Checking whether " << (*i).processor->name() << " can support " << required_inputs.n_audio() << " inputs\n";
+
                if ((*i).processor->can_support_input_configuration (required_inputs) < 0) {
                        if (err) {
                                err->index = index;
@@ -1260,6 +1286,8 @@ Route::check_some_plugin_counts (list<ProcessorCount>& iclist, ChanCount require
                (*i).in = required_inputs;
                (*i).out = (*i).processor->output_for_input_configuration (required_inputs);
 
+               cerr << "config looks like " << (*i).processor->name() << " in = " << (*i).in.n_audio() << " out = " << (*i).out.n_audio() << endl;
+
                required_inputs = (*i).out;
                
                ++index;
@@ -1445,7 +1473,7 @@ XMLNode&
 Route::state(bool full_state)
 {
        XMLNode *node = new XMLNode("Route");
-       ProcessorList:: iterator i;
+       ProcessorList::iterator i;
        char buf[32];
 
        if (_flags) {
@@ -1491,8 +1519,8 @@ Route::state(bool full_state)
        node->add_property ("order-keys", order_string);
 
        node->add_child_nocopy (IO::state (full_state));
-       node->add_child_nocopy (_solo_control.get_state ());
-       node->add_child_nocopy (_mute_control.get_state ());
+       node->add_child_nocopy (_solo_control->get_state ());
+       node->add_child_nocopy (_mute_control->get_state ());
 
        XMLNode* remote_control_node = new XMLNode (X_("remote_control"));
        snprintf (buf, sizeof (buf), "%d", _remote_control_id);
@@ -1853,12 +1881,12 @@ Route::_set_state (const XMLNode& node, bool call_base)
                } else if (child->name() == X_("controllable") && (prop = child->property("name")) != 0) {
                        
                        if (prop->value() == "solo") {
-                               _solo_control.set_state (*child);
-                               _session.add_controllable (&_solo_control);
+                               _solo_control->set_state (*child);
+                               _session.add_controllable (_solo_control);
                        }
                        else if (prop->value() == "mute") {
-                               _mute_control.set_state (*child);
-                               _session.add_controllable (&_mute_control);
+                               _mute_control->set_state (*child);
+                               _session.add_controllable (_mute_control);
                        }
                }
                else if (child->name() == X_("remote_control")) {
@@ -2038,7 +2066,7 @@ Route::set_control_outs (const vector<string>& ports)
                _control_outs = 0;
        }
 
-       if (control() || master()) {
+       if (is_control() || is_master()) {
                /* no control outs for these two special busses */
                return 0;
        }
@@ -2067,7 +2095,7 @@ Route::set_control_outs (const vector<string>& ports)
        /* now connect to the named ports */
        
        for (size_t n = 0; n < limit; ++n) {
-               if (_control_outs->connect_output (_control_outs->output (n), ports[n], this)) {
+               if (_control_outs->connect_output (_control_outs->output (n), ports[n % ports.size()], this)) {
                        error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
                        return -1;
                }
@@ -2308,7 +2336,7 @@ Route::pans_required () const
                return 0;
        }
        
-       return max (n_inputs ().n_audio(), static_cast<size_t>(processor_max_outs.n_audio()));
+       return max (n_inputs ().n_audio(), processor_max_outs.n_audio());
 }
 
 int 
@@ -2393,10 +2421,9 @@ Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nfra
                
                if (am.locked() && _session.transport_rolling()) {
                        
-                       ARDOUR::AutomationList& gain_auto = gain_automation();
-                       
-                       if (gain_auto.automation_playback()) {
-                               apply_gain_automation = gain_auto.curve().rt_safe_get_vector (start_frame, end_frame, _session.gain_automation_buffer(), nframes);
+                       if (_gain_control->list()->automation_playback()) {
+                               apply_gain_automation = _gain_control->list()->curve().rt_safe_get_vector (
+                                               start_frame, end_frame, _session.gain_automation_buffer(), nframes);
                        }
                }
        }