2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "libardour-config.h"
29 #include <boost/algorithm/string.hpp>
31 #include "pbd/xml++.h"
32 #include "pbd/enumwriter.h"
33 #include "pbd/memento_command.h"
34 #include "pbd/stacktrace.h"
35 #include "pbd/convert.h"
36 #include "pbd/boost_debug.h"
38 #include "ardour/amp.h"
39 #include "ardour/audio_buffer.h"
40 #include "ardour/audio_port.h"
41 #include "ardour/audioengine.h"
42 #include "ardour/buffer.h"
43 #include "ardour/buffer_set.h"
44 #include "ardour/capturing_processor.h"
45 #include "ardour/debug.h"
46 #include "ardour/delivery.h"
47 #include "ardour/internal_return.h"
48 #include "ardour/internal_send.h"
49 #include "ardour/meter.h"
50 #include "ardour/delayline.h"
51 #include "ardour/midi_buffer.h"
52 #include "ardour/midi_port.h"
53 #include "ardour/monitor_processor.h"
54 #include "ardour/pannable.h"
55 #include "ardour/panner.h"
56 #include "ardour/panner_shell.h"
57 #include "ardour/plugin_insert.h"
58 #include "ardour/port.h"
59 #include "ardour/port_insert.h"
60 #include "ardour/processor.h"
61 #include "ardour/route.h"
62 #include "ardour/route_group.h"
63 #include "ardour/send.h"
64 #include "ardour/session.h"
65 #include "ardour/unknown_processor.h"
66 #include "ardour/utils.h"
71 using namespace ARDOUR;
74 PBD::Signal0<void> Route::SyncOrderKeys;
75 PBD::Signal0<void> Route::RemoteControlIDChange;
77 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
78 : SessionObject (sess, name)
80 , GraphNode (sess._process_graph)
83 , _signal_latency_at_amp_position (0)
87 , _pending_declick (true)
88 , _meter_point (MeterPostFader)
89 , _meter_type (MeterPeak)
91 , _soloed_by_others_upstream (0)
92 , _soloed_by_others_downstream (0)
94 , _denormal_protection (false)
97 , _declickable (false)
98 , _mute_master (new MuteMaster (sess, name))
99 , _have_internal_generator (false)
101 , _default_type (default_type)
103 , _has_order_key (false)
104 , _remote_control_id (0)
105 , _in_configure_processors (false)
106 , _initial_io_setup (false)
107 , _custom_meter_position_noted (false)
108 , _last_custom_meter_was_at_end (false)
111 _meter_type = MeterK20;
113 processor_max_streams.reset();
119 /* add standard controls */
121 _solo_control.reset (new SoloControllable (X_("solo"), shared_from_this ()));
122 _mute_control.reset (new MuteControllable (X_("mute"), shared_from_this ()));
124 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
125 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
127 add_control (_solo_control);
128 add_control (_mute_control);
132 if (!(_flags & Route::MonitorOut)) {
133 _pannable.reset (new Pannable (_session));
136 /* input and output objects */
138 _input.reset (new IO (_session, _name, IO::Input, _default_type));
139 _output.reset (new IO (_session, _name, IO::Output, _default_type));
141 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
142 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
144 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
145 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
147 if (!is_master() && !is_monitor() && !is_auditioner()) {
148 _delayline.reset (new DelayLine (_session, _name));
149 add_processor (_delayline, PreFader);
152 /* add amp processor */
154 _amp.reset (new Amp (_session));
155 add_processor (_amp, PostFader);
157 /* create standard processors: meter, main outs, monitor out;
158 they will be added to _processors by setup_invisible_processors ()
161 _meter.reset (new PeakMeter (_session, _name));
162 _meter->set_owner (this);
163 _meter->set_display_to_user (false);
166 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
167 _main_outs->activate ();
170 /* where we listen to tracks */
171 _intreturn.reset (new InternalReturn (_session));
172 _intreturn->activate ();
174 /* the thing that provides proper control over a control/monitor/listen bus
175 (such as per-channel cut, dim, solo, invert, etc).
177 _monitor_control.reset (new MonitorProcessor (_session));
178 _monitor_control->activate ();
181 if (is_master() || is_monitor() || is_auditioner()) {
182 _mute_master->set_solo_ignore (true);
185 /* now that we have _meter, its safe to connect to this */
187 Metering::Meter.connect_same_thread (*this, (boost::bind (&Route::meter, this)));
190 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
191 configure_processors (0);
199 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
201 /* do this early so that we don't get incoming signals as we are going through destruction
206 /* don't use clear_processors here, as it depends on the session which may
207 be half-destroyed by now
210 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
211 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
212 (*i)->drop_references ();
215 _processors.clear ();
219 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
221 if (Config->get_remote_model() != UserOrdered) {
225 set_remote_control_id_internal (id, notify_class_listeners);
229 Route::set_remote_control_id_internal (uint32_t id, bool notify_class_listeners)
231 /* force IDs for master/monitor busses and prevent
232 any other route from accidentally getting these IDs
233 (i.e. legacy sessions)
236 if (is_master() && id != MasterBusRemoteControlID) {
237 id = MasterBusRemoteControlID;
240 if (is_monitor() && id != MonitorBusRemoteControlID) {
241 id = MonitorBusRemoteControlID;
248 /* don't allow it to collide */
250 if (!is_master () && !is_monitor() &&
251 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
252 id += MonitorBusRemoteControlID;
255 if (id != remote_control_id()) {
256 _remote_control_id = id;
257 RemoteControlIDChanged ();
259 if (notify_class_listeners) {
260 RemoteControlIDChange ();
266 Route::remote_control_id() const
269 return MasterBusRemoteControlID;
273 return MonitorBusRemoteControlID;
276 return _remote_control_id;
280 Route::has_order_key () const
282 return _has_order_key;
286 Route::order_key () const
292 Route::set_remote_control_id_explicit (uint32_t rid)
294 if (is_master() || is_monitor() || is_auditioner()) {
295 /* hard-coded remote IDs, or no remote ID */
299 if (_remote_control_id != rid) {
300 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
301 _remote_control_id = rid;
302 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
305 /* don't emit the class-level RID signal RemoteControlIDChange here,
306 leave that to the entity that changed the order key, so that we
307 don't get lots of emissions for no good reasons (e.g. when changing
308 all route order keys).
310 See Session::sync_remote_id_from_order_keys() for the (primary|only)
311 spot where that is emitted.
316 Route::set_order_key (uint32_t n)
318 _has_order_key = true;
320 if (_order_key == n) {
326 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key set to %2\n",
327 name(), order_key ()));
329 _session.set_dirty ();
333 Route::ensure_track_or_route_name(string name, Session &session)
335 string newname = name;
337 while (!session.io_name_is_legal (newname)) {
338 newname = bump_name_once (newname, '.');
346 Route::inc_gain (gain_t fraction, void *src)
348 _amp->inc_gain (fraction, src);
352 Route::set_gain (gain_t val, void *src)
354 if (src != 0 && _route_group && src != _route_group && _route_group->is_active() && _route_group->is_gain()) {
356 if (_route_group->is_relative()) {
358 gain_t usable_gain = _amp->gain();
359 if (usable_gain < 0.000001f) {
360 usable_gain = 0.000001f;
364 if (delta < 0.000001f) {
368 delta -= usable_gain;
373 gain_t factor = delta / usable_gain;
376 factor = _route_group->get_max_factor(factor);
377 if (factor == 0.0f) {
378 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
382 factor = _route_group->get_min_factor(factor);
383 if (factor == 0.0f) {
384 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
389 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor, _route_group));
393 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, _route_group));
399 if (val == _amp->gain()) {
403 _amp->set_gain (val, src);
407 Route::maybe_declick (BufferSet&, framecnt_t, int)
409 /* this is the "bus" implementation and they never declick.
414 /** Process this route for one (sub) cycle (process thread)
416 * @param bufs Scratch buffers to use for the signal path
417 * @param start_frame Initial transport frame
418 * @param end_frame Final transport frame
419 * @param nframes Number of frames to output (to ports)
421 * Note that (end_frame - start_frame) may not be equal to nframes when the
422 * transport speed isn't 1.0 (eg varispeed).
425 Route::process_output_buffers (BufferSet& bufs,
426 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
427 int declick, bool gain_automation_ok)
429 /* Caller must hold process lock */
430 assert (!AudioEngine::instance()->process_lock().trylock());
432 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
435 /* figure out if we're going to use gain automation */
436 if (gain_automation_ok) {
437 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
438 _amp->setup_gain_automation (
439 start_frame + _signal_latency_at_amp_position,
440 end_frame + _signal_latency_at_amp_position,
443 _amp->apply_gain_automation (false);
446 /* Tell main outs what to do about monitoring. We do this so that
447 on a transition between monitoring states we get a de-clicking gain
448 change in the _main_outs delivery.
451 _main_outs->no_outs_cuz_we_no_monitor (monitoring_state () == MonitoringSilence);
453 /* -------------------------------------------------------------------------------------------
454 GLOBAL DECLICK (for transport changes etc.)
455 ----------------------------------------------------------------------------------------- */
457 maybe_declick (bufs, nframes, declick);
458 _pending_declick = 0;
460 /* -------------------------------------------------------------------------------------------
461 DENORMAL CONTROL/PHASE INVERT
462 ----------------------------------------------------------------------------------------- */
464 if (_phase_invert.any ()) {
468 if (_denormal_protection || Config->get_denormal_protection()) {
470 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
471 Sample* const sp = i->data();
473 if (_phase_invert[chn]) {
474 for (pframes_t nx = 0; nx < nframes; ++nx) {
479 for (pframes_t nx = 0; nx < nframes; ++nx) {
487 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
488 Sample* const sp = i->data();
490 if (_phase_invert[chn]) {
491 for (pframes_t nx = 0; nx < nframes; ++nx) {
500 if (_denormal_protection || Config->get_denormal_protection()) {
502 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
503 Sample* const sp = i->data();
504 for (pframes_t nx = 0; nx < nframes; ++nx) {
512 /* -------------------------------------------------------------------------------------------
514 ----------------------------------------------------------------------------------------- */
516 /* set this to be true if the meter will already have been ::run() earlier */
517 bool const meter_already_run = metering_state() == MeteringInput;
519 framecnt_t latency = 0;
521 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
523 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
524 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
529 /* if it has any inputs, make sure they match */
530 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
531 if (bufs.count() != (*i)->input_streams()) {
533 DEBUG::Processors, string_compose (
534 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
535 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
542 /* should we NOT run plugins here if the route is inactive?
543 do we catch route != active somewhere higher?
546 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
547 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
550 (*i)->run (bufs, start_frame - latency, end_frame - latency, nframes, *i != _processors.back());
551 bufs.set_count ((*i)->output_streams());
553 if ((*i)->active ()) {
554 latency += (*i)->signal_latency ();
560 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
561 boost::shared_ptr<Processor> endpoint,
562 bool include_endpoint, bool for_export, bool for_freeze)
564 /* If no processing is required, there's no need to go any further. */
565 if (!endpoint && !include_endpoint) {
569 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
570 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
571 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
574 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
576 if (!include_endpoint && (*i) == endpoint) {
580 /* if we're not exporting, stop processing if we come across a routing processor. */
581 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
584 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
588 /* don't run any processors that does routing.
589 * oh, and don't bother with the peak meter either.
591 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
592 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
593 buffers.set_count ((*i)->output_streams());
594 latency += (*i)->signal_latency ();
597 if ((*i) == endpoint) {
604 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
605 bool include_endpoint, bool for_export, bool for_freeze) const
607 framecnt_t latency = 0;
608 if (!endpoint && !include_endpoint) {
612 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
613 if (!include_endpoint && (*i) == endpoint) {
616 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
619 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
622 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
623 latency += (*i)->signal_latency ();
625 if ((*i) == endpoint) {
633 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
634 bool include_endpoint, bool for_export, bool for_freeze) const
636 if (!endpoint && !include_endpoint) {
640 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
641 if (!include_endpoint && (*i) == endpoint) {
644 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
647 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
650 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
651 cc = (*i)->output_streams();
653 if ((*i) == endpoint) {
661 Route::n_process_buffers ()
663 return max (_input->n_ports(), processor_max_streams);
667 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
669 assert (is_monitor());
670 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
671 fill_buffers_with_input (bufs, _input, nframes);
672 passthru (bufs, start_frame, end_frame, nframes, declick);
676 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
680 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
682 /* control/monitor bus ignores input ports when something is
683 feeding the listen "stream". data will "arrive" into the
684 route from the intreturn processor element.
687 bufs.silence (nframes, 0);
690 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
691 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
695 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
697 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
699 bufs.set_count (_input->n_ports());
700 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
701 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
705 Route::set_listen (bool yn, void* src)
711 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
712 _route_group->foreach_route (boost::bind (&Route::set_listen, _1, yn, _route_group));
717 if (yn != _monitor_send->active()) {
719 _monitor_send->activate ();
720 _mute_master->set_soloed (true);
722 _monitor_send->deactivate ();
723 _mute_master->set_soloed (false);
726 listen_changed (src); /* EMIT SIGNAL */
732 Route::listening_via_monitor () const
735 return _monitor_send->active ();
742 Route::set_solo_safe (bool yn, void *src)
744 if (_solo_safe != yn) {
746 solo_safe_changed (src);
751 Route::solo_safe() const
757 Route::set_solo (bool yn, void *src)
760 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change due to solo-safe\n", name()));
764 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
765 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, _route_group));
769 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set solo => %2, src: %3 grp ? %4 currently self-soloed ? %5\n",
770 name(), yn, src, (src == _route_group), self_soloed()));
772 if (self_soloed() != yn) {
774 set_mute_master_solo ();
775 solo_changed (true, src); /* EMIT SIGNAL */
776 _solo_control->Changed (); /* EMIT SIGNAL */
781 Route::set_self_solo (bool yn)
783 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set SELF solo => %2\n", name(), yn));
788 Route::mod_solo_by_others_upstream (int32_t delta)
791 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo-by-upstream due to solo-safe\n", name()));
795 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-upstream by %2, current up = %3 down = %4\n",
796 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
798 uint32_t old_sbu = _soloed_by_others_upstream;
801 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
802 _soloed_by_others_upstream += delta;
804 _soloed_by_others_upstream = 0;
807 _soloed_by_others_upstream += delta;
810 DEBUG_TRACE (DEBUG::Solo, string_compose (
811 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
812 name(), delta, _soloed_by_others_upstream, old_sbu,
813 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
815 /* push the inverse solo change to everything that feeds us.
817 This is important for solo-within-group. When we solo 1 track out of N that
818 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
819 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
820 tracks that feed it. This will silence them if they were audible because
821 of a bus solo, but the newly soloed track will still be audible (because
824 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
828 if ((_self_solo || _soloed_by_others_downstream) &&
829 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
830 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
832 if (delta > 0 || !Config->get_exclusive_solo()) {
833 DEBUG_TRACE (DEBUG::Solo, "\t ... INVERT push\n");
834 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
835 boost::shared_ptr<Route> sr = i->r.lock();
837 sr->mod_solo_by_others_downstream (-delta);
843 set_mute_master_solo ();
844 solo_changed (false, this);
848 Route::mod_solo_by_others_downstream (int32_t delta)
851 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo-by-downstream due to solo safe\n", name()));
855 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-downstream by %2, current up = %3 down = %4\n",
856 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
859 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
860 _soloed_by_others_downstream += delta;
862 _soloed_by_others_downstream = 0;
865 _soloed_by_others_downstream += delta;
868 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
870 set_mute_master_solo ();
871 solo_changed (false, this);
875 Route::set_mute_master_solo ()
877 _mute_master->set_soloed (self_soloed() || soloed_by_others_downstream() || soloed_by_others_upstream());
881 Route::set_solo_isolated (bool yn, void *src)
883 if (is_master() || is_monitor() || is_auditioner()) {
887 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
888 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, _route_group));
892 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
894 boost::shared_ptr<RouteList> routes = _session.get_routes ();
895 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
897 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
902 bool does_feed = direct_feeds_according_to_graph (*i, &sends_only); // we will recurse anyway, so don't use ::feeds()
904 if (does_feed && !sends_only) {
905 (*i)->set_solo_isolated (yn, (*i)->route_group());
909 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
911 bool changed = false;
914 if (_solo_isolated == 0) {
915 _mute_master->set_solo_ignore (true);
920 if (_solo_isolated > 0) {
922 if (_solo_isolated == 0) {
923 _mute_master->set_solo_ignore (false);
930 solo_isolated_changed (src);
935 Route::solo_isolated () const
937 return _solo_isolated > 0;
941 Route::set_mute_points (MuteMaster::MutePoint mp)
943 _mute_master->set_mute_points (mp);
944 mute_points_changed (); /* EMIT SIGNAL */
946 if (_mute_master->muted_by_self()) {
947 mute_changed (this); /* EMIT SIGNAL */
948 _mute_control->Changed (); /* EMIT SIGNAL */
953 Route::set_mute (bool yn, void *src)
955 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_mute()) {
956 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, _route_group));
961 _mute_master->set_muted_by_self (yn);
962 /* allow any derived classes to respond to the mute change
963 before anybody else knows about it.
966 /* tell everyone else */
967 mute_changed (src); /* EMIT SIGNAL */
968 _mute_control->Changed (); /* EMIT SIGNAL */
973 Route::muted () const
975 return _mute_master->muted_by_self();
980 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
982 cerr << name << " {" << endl;
983 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
984 p != procs.end(); ++p) {
985 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
991 /** Supposing that we want to insert a Processor at a given Placement, return
992 * the processor to add the new one before (or 0 to add at the end).
994 boost::shared_ptr<Processor>
995 Route::before_processor_for_placement (Placement p)
997 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
999 ProcessorList::iterator loc;
1001 if (p == PreFader) {
1002 /* generic pre-fader: insert immediately before the amp */
1003 loc = find (_processors.begin(), _processors.end(), _amp);
1005 /* generic post-fader: insert right before the main outs */
1006 loc = find (_processors.begin(), _processors.end(), _main_outs);
1009 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
1012 /** Supposing that we want to insert a Processor at a given index, return
1013 * the processor to add the new one before (or 0 to add at the end).
1015 boost::shared_ptr<Processor>
1016 Route::before_processor_for_index (int index)
1019 return boost::shared_ptr<Processor> ();
1022 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1024 ProcessorList::iterator i = _processors.begin ();
1026 while (i != _processors.end() && j < index) {
1027 if ((*i)->display_to_user()) {
1034 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
1037 /** Add a processor either pre- or post-fader
1038 * @return 0 on success, non-0 on failure.
1041 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
1043 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
1047 /** Add a processor to a route such that it ends up with a given index into the visible processors.
1048 * @param index Index to add the processor at, or -1 to add at the end of the list.
1049 * @return 0 on success, non-0 on failure.
1052 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
1054 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
1057 /** Add a processor to the route.
1058 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
1059 * @return 0 on success, non-0 on failure.
1062 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
1064 assert (processor != _meter);
1065 assert (processor != _main_outs);
1067 DEBUG_TRACE (DEBUG::Processors, string_compose (
1068 "%1 adding processor %2\n", name(), processor->name()));
1070 if (!AudioEngine::instance()->connected() || !processor) {
1075 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1076 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1077 ProcessorState pstate (this);
1079 boost::shared_ptr<PluginInsert> pi;
1080 boost::shared_ptr<PortInsert> porti;
1082 if (processor == _amp) {
1083 /* Ensure that only one amp is in the list at any time */
1084 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), processor);
1085 if (check != _processors.end()) {
1086 if (before == _amp) {
1087 /* Already in position; all is well */
1090 _processors.erase (check);
1095 assert (find (_processors.begin(), _processors.end(), processor) == _processors.end ());
1097 ProcessorList::iterator loc;
1099 /* inserting before a processor; find it */
1100 loc = find (_processors.begin(), _processors.end(), before);
1101 if (loc == _processors.end ()) {
1106 /* inserting at end */
1107 loc = _processors.end ();
1110 _processors.insert (loc, processor);
1111 processor->set_owner (this);
1113 // Set up processor list channels. This will set processor->[input|output]_streams(),
1114 // configure redirect ports properly, etc.
1117 if (configure_processors_unlocked (err)) {
1119 configure_processors_unlocked (0); // it worked before we tried to add it ...
1124 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1126 if (pi->has_no_inputs ()) {
1127 /* generator plugin */
1128 _have_internal_generator = true;
1133 if (activation_allowed && !_session.get_disable_all_loaded_plugins()) {
1134 processor->activate ();
1137 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1139 _output->set_user_latency (0);
1142 reset_instrument_info ();
1143 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1144 set_processor_positions ();
1150 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
1152 const XMLProperty *prop;
1155 boost::shared_ptr<Processor> processor;
1157 /* bit of a hack: get the `placement' property from the <Redirect> tag here
1158 so that we can add the processor in the right place (pre/post-fader)
1161 XMLNodeList const & children = node.children ();
1162 XMLNodeList::const_iterator i = children.begin ();
1164 while (i != children.end() && (*i)->name() != X_("Redirect")) {
1168 Placement placement = PreFader;
1170 if (i != children.end()) {
1171 if ((prop = (*i)->property (X_("placement"))) != 0) {
1172 placement = Placement (string_2_enum (prop->value(), placement));
1176 if (node.name() == "Insert") {
1178 if ((prop = node.property ("type")) != 0) {
1180 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1181 prop->value() == "lv2" ||
1182 prop->value() == "windows-vst" ||
1183 prop->value() == "lxvst" ||
1184 prop->value() == "audiounit") {
1186 processor.reset (new PluginInsert (_session));
1190 processor.reset (new PortInsert (_session, _pannable, _mute_master));
1195 } else if (node.name() == "Send") {
1197 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
1198 processor.reset (new Send (_session, sendpan, _mute_master));
1202 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1206 if (processor->set_state (node, version)) {
1210 return (add_processor (processor, placement) == 0);
1213 catch (failed_constructor &err) {
1214 warning << _("processor could not be created. Ignored.") << endmsg;
1220 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1222 /* NOTE: this is intended to be used ONLY when copying
1223 processors from another Route. Hence the subtle
1224 differences between this and ::add_processor()
1227 ProcessorList::iterator loc;
1230 loc = find(_processors.begin(), _processors.end(), before);
1232 /* nothing specified - at end */
1233 loc = _processors.end ();
1236 if (!_session.engine().connected()) {
1240 if (others.empty()) {
1245 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1246 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1247 ProcessorState pstate (this);
1249 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1255 boost::shared_ptr<PluginInsert> pi;
1257 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1261 _processors.insert (loc, *i);
1262 (*i)->set_owner (this);
1264 if ((*i)->active()) {
1268 /* Think: does this really need to be called for every processor in the loop? */
1270 if (configure_processors_unlocked (err)) {
1272 configure_processors_unlocked (0); // it worked before we tried to add it ...
1277 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1280 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1281 boost::shared_ptr<PluginInsert> pi;
1283 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1284 if (pi->has_no_inputs ()) {
1285 _have_internal_generator = true;
1291 _output->set_user_latency (0);
1294 reset_instrument_info ();
1295 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1296 set_processor_positions ();
1302 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1304 if (p == PreFader) {
1305 start = _processors.begin();
1306 end = find(_processors.begin(), _processors.end(), _amp);
1308 start = find(_processors.begin(), _processors.end(), _amp);
1310 end = _processors.end();
1314 /** Turn off all processors with a given placement
1315 * @param p Placement of processors to disable
1318 Route::disable_processors (Placement p)
1320 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1322 ProcessorList::iterator start, end;
1323 placement_range(p, start, end);
1325 for (ProcessorList::iterator i = start; i != end; ++i) {
1326 (*i)->deactivate ();
1329 _session.set_dirty ();
1332 /** Turn off all redirects
1335 Route::disable_processors ()
1337 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1339 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1340 (*i)->deactivate ();
1343 _session.set_dirty ();
1346 /** Turn off all redirects with a given placement
1347 * @param p Placement of redirects to disable
1350 Route::disable_plugins (Placement p)
1352 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1354 ProcessorList::iterator start, end;
1355 placement_range(p, start, end);
1357 for (ProcessorList::iterator i = start; i != end; ++i) {
1358 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1359 (*i)->deactivate ();
1363 _session.set_dirty ();
1366 /** Turn off all plugins
1369 Route::disable_plugins ()
1371 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1373 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1374 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1375 (*i)->deactivate ();
1379 _session.set_dirty ();
1384 Route::ab_plugins (bool forward)
1386 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1390 /* forward = turn off all active redirects, and mark them so that the next time
1391 we go the other way, we will revert them
1394 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1395 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1399 if ((*i)->active()) {
1400 (*i)->deactivate ();
1401 (*i)->set_next_ab_is_active (true);
1403 (*i)->set_next_ab_is_active (false);
1409 /* backward = if the redirect was marked to go active on the next ab, do so */
1411 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1413 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1417 if ((*i)->get_next_ab_is_active()) {
1420 (*i)->deactivate ();
1425 _session.set_dirty ();
1429 /** Remove processors with a given placement.
1430 * @param p Placement of processors to remove.
1433 Route::clear_processors (Placement p)
1435 if (!_session.engine().connected()) {
1439 bool already_deleting = _session.deletion_in_progress();
1440 if (!already_deleting) {
1441 _session.set_deletion_in_progress();
1445 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1446 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1447 ProcessorList new_list;
1448 ProcessorStreams err;
1449 bool seen_amp = false;
1451 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1457 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline) {
1459 /* you can't remove these */
1461 new_list.push_back (*i);
1468 new_list.push_back (*i);
1471 (*i)->drop_references ();
1479 (*i)->drop_references ();
1482 new_list.push_back (*i);
1489 _processors = new_list;
1490 configure_processors_unlocked (&err); // this can't fail
1493 processor_max_streams.reset();
1494 _have_internal_generator = false;
1495 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1496 set_processor_positions ();
1498 reset_instrument_info ();
1500 if (!already_deleting) {
1501 _session.clear_deletion_in_progress();
1506 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1508 // TODO once the export point can be configured properly, do something smarter here
1509 if (processor == _capturing_processor) {
1510 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1511 if (need_process_lock) {
1515 _capturing_processor.reset();
1517 if (need_process_lock) {
1522 /* these can never be removed */
1524 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline) {
1528 if (!_session.engine().connected()) {
1532 processor_max_streams.reset();
1535 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1536 if (need_process_lock) {
1540 /* Caller must hold process lock */
1541 assert (!AudioEngine::instance()->process_lock().trylock());
1543 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1545 ProcessorState pstate (this);
1547 ProcessorList::iterator i;
1548 bool removed = false;
1550 for (i = _processors.begin(); i != _processors.end(); ) {
1551 if (*i == processor) {
1553 /* move along, see failure case for configure_processors()
1554 where we may need to reconfigure the processor.
1557 /* stop redirects that send signals to JACK ports
1558 from causing noise as a result of no longer being
1562 boost::shared_ptr<IOProcessor> iop;
1564 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1568 i = _processors.erase (i);
1576 _output->set_user_latency (0);
1584 if (configure_processors_unlocked (err)) {
1586 /* we know this will work, because it worked before :) */
1587 configure_processors_unlocked (0);
1591 _have_internal_generator = false;
1593 for (i = _processors.begin(); i != _processors.end(); ++i) {
1594 boost::shared_ptr<PluginInsert> pi;
1596 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1597 if (pi->has_no_inputs ()) {
1598 _have_internal_generator = true;
1603 if (need_process_lock) {
1608 reset_instrument_info ();
1609 processor->drop_references ();
1610 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1611 set_processor_positions ();
1617 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1619 ProcessorList deleted;
1621 if (!_session.engine().connected()) {
1625 processor_max_streams.reset();
1628 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1629 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1630 ProcessorState pstate (this);
1632 ProcessorList::iterator i;
1633 boost::shared_ptr<Processor> processor;
1635 for (i = _processors.begin(); i != _processors.end(); ) {
1639 /* these can never be removed */
1641 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline) {
1646 /* see if its in the list of processors to delete */
1648 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1653 /* stop IOProcessors that send to JACK ports
1654 from causing noise as a result of no longer being
1658 boost::shared_ptr<IOProcessor> iop;
1660 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1664 deleted.push_back (processor);
1665 i = _processors.erase (i);
1668 if (deleted.empty()) {
1669 /* none of those in the requested list were found */
1673 _output->set_user_latency (0);
1675 if (configure_processors_unlocked (err)) {
1677 /* we know this will work, because it worked before :) */
1678 configure_processors_unlocked (0);
1683 _have_internal_generator = false;
1685 for (i = _processors.begin(); i != _processors.end(); ++i) {
1686 boost::shared_ptr<PluginInsert> pi;
1688 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1689 if (pi->has_no_inputs ()) {
1690 _have_internal_generator = true;
1697 /* now try to do what we need to so that those that were removed will be deleted */
1699 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1700 (*i)->drop_references ();
1703 reset_instrument_info ();
1704 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1705 set_processor_positions ();
1711 Route::reset_instrument_info ()
1713 boost::shared_ptr<Processor> instr = the_instrument();
1715 _instrument_info.set_internal_instrument (instr);
1719 /** Caller must hold process lock */
1721 Route::configure_processors (ProcessorStreams* err)
1723 #ifndef PLATFORM_WINDOWS
1724 assert (!AudioEngine::instance()->process_lock().trylock());
1727 if (!_in_configure_processors) {
1728 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1729 return configure_processors_unlocked (err);
1736 Route::input_streams () const
1738 return _input->n_ports ();
1741 list<pair<ChanCount, ChanCount> >
1742 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1744 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1746 return try_configure_processors_unlocked (in, err);
1749 list<pair<ChanCount, ChanCount> >
1750 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1752 // Check each processor in order to see if we can configure as requested
1754 list<pair<ChanCount, ChanCount> > configuration;
1757 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1758 DEBUG_TRACE (DEBUG::Processors, "{\n");
1760 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1762 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1763 DEBUG_TRACE (DEBUG::Processors, "--- CONFIGURE ABORTED due to unknown processor.\n");
1764 DEBUG_TRACE (DEBUG::Processors, "}\n");
1765 return list<pair<ChanCount, ChanCount> > ();
1768 if ((*p)->can_support_io_configuration(in, out)) {
1769 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1770 configuration.push_back(make_pair(in, out));
1777 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1778 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1779 DEBUG_TRACE (DEBUG::Processors, "}\n");
1780 return list<pair<ChanCount, ChanCount> > ();
1784 DEBUG_TRACE (DEBUG::Processors, "}\n");
1786 return configuration;
1789 /** Set the input/output configuration of each processor in the processors list.
1790 * Caller must hold process lock.
1791 * Return 0 on success, otherwise configuration is impossible.
1794 Route::configure_processors_unlocked (ProcessorStreams* err)
1796 #ifndef PLATFORM_WINDOWS
1797 assert (!AudioEngine::instance()->process_lock().trylock());
1800 if (_in_configure_processors) {
1804 /* put invisible processors where they should be */
1805 setup_invisible_processors ();
1807 _in_configure_processors = true;
1809 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1811 if (configuration.empty ()) {
1812 _in_configure_processors = false;
1817 bool seen_mains_out = false;
1818 processor_out_streams = _input->n_ports();
1819 processor_max_streams.reset();
1821 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1822 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1824 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1828 (*p)->configure_io(c->first, c->second);
1829 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1830 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1833 if (boost::dynamic_pointer_cast<Delivery> (*p)
1834 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1835 /* main delivery will increase port count to match input.
1836 * the Delivery::Main is usually the last processor - followed only by
1839 seen_mains_out = true;
1841 if (!seen_mains_out) {
1842 processor_out_streams = out;
1848 _meter->reset_max_channels (processor_max_streams);
1851 /* make sure we have sufficient scratch buffers to cope with the new processor
1854 _session.ensure_buffers (n_process_buffers ());
1856 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1858 _in_configure_processors = false;
1862 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1863 * @param state New active state for those processors.
1866 Route::all_visible_processors_active (bool state)
1868 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1870 if (_processors.empty()) {
1874 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1875 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1882 (*i)->deactivate ();
1886 _session.set_dirty ();
1890 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1892 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1893 NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1894 processors in the current actual processor list that are hidden. Any visible processors
1895 in the current list but not in "new_order" will be assumed to be deleted.
1899 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1900 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1901 ProcessorState pstate (this);
1903 ProcessorList::iterator oiter;
1904 ProcessorList::const_iterator niter;
1905 ProcessorList as_it_will_be;
1907 oiter = _processors.begin();
1908 niter = new_order.begin();
1910 while (niter != new_order.end()) {
1912 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1913 then append it to the temp list.
1915 Otherwise, see if the next processor in the old list is in the new list. if not,
1916 its been deleted. If its there, append it to the temp list.
1919 if (oiter == _processors.end()) {
1921 /* no more elements in the old list, so just stick the rest of
1922 the new order onto the temp list.
1925 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1926 while (niter != new_order.end()) {
1933 if (!(*oiter)->display_to_user()) {
1935 as_it_will_be.push_back (*oiter);
1939 /* visible processor: check that its in the new order */
1941 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1942 /* deleted: do nothing, shared_ptr<> will clean up */
1944 /* ignore this one, and add the next item from the new order instead */
1945 as_it_will_be.push_back (*niter);
1950 /* now remove from old order - its taken care of no matter what */
1951 oiter = _processors.erase (oiter);
1956 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1958 /* If the meter is in a custom position, find it and make a rough note of its position */
1959 maybe_note_meter_position ();
1961 if (configure_processors_unlocked (err)) {
1967 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1968 set_processor_positions ();
1980 Route::get_template()
1982 return state(false);
1986 Route::state(bool full_state)
1988 XMLNode *node = new XMLNode("Route");
1989 ProcessorList::iterator i;
1992 id().print (buf, sizeof (buf));
1993 node->add_property("id", buf);
1994 node->add_property ("name", _name);
1995 node->add_property("default-type", _default_type.to_string());
1998 node->add_property("flags", enum_2_string (_flags));
2001 node->add_property("active", _active?"yes":"no");
2003 boost::to_string (_phase_invert, p);
2004 node->add_property("phase-invert", p);
2005 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2006 node->add_property("meter-point", enum_2_string (_meter_point));
2008 node->add_property("meter-type", enum_2_string (_meter_type));
2011 node->add_property("route-group", _route_group->name());
2014 snprintf (buf, sizeof (buf), "%d", _order_key);
2015 node->add_property ("order-key", buf);
2016 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
2017 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
2018 node->add_property ("soloed-by-upstream", buf);
2019 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
2020 node->add_property ("soloed-by-downstream", buf);
2021 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
2022 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
2024 node->add_child_nocopy (_input->state (full_state));
2025 node->add_child_nocopy (_output->state (full_state));
2026 node->add_child_nocopy (_solo_control->get_state ());
2027 node->add_child_nocopy (_mute_control->get_state ());
2028 node->add_child_nocopy (_mute_master->get_state ());
2030 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
2031 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2032 remote_control_node->add_property (X_("id"), buf);
2033 node->add_child_nocopy (*remote_control_node);
2035 if (_comment.length()) {
2036 XMLNode *cmt = node->add_child ("Comment");
2037 cmt->add_content (_comment);
2041 node->add_child_nocopy (_pannable->state (full_state));
2044 for (i = _processors.begin(); i != _processors.end(); ++i) {
2046 /* template save: do not include internal sends functioning as
2047 aux sends because the chance of the target ID
2048 in the session where this template is used
2051 similarly, do not save listen sends which connect to
2052 the monitor section, because these will always be
2055 boost::shared_ptr<InternalSend> is;
2057 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2058 if (is->role() == Delivery::Listen) {
2063 node->add_child_nocopy((*i)->state (full_state));
2067 node->add_child_copy (*_extra_xml);
2070 if (_custom_meter_position_noted) {
2071 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2073 after->id().print (buf, sizeof (buf));
2074 node->add_property (X_("processor-after-last-custom-meter"), buf);
2077 node->add_property (X_("last-custom-meter-was-at-end"), _last_custom_meter_was_at_end ? "yes" : "no");
2084 Route::set_state (const XMLNode& node, int version)
2086 if (version < 3000) {
2087 return set_state_2X (node, version);
2091 XMLNodeConstIterator niter;
2093 const XMLProperty *prop;
2095 if (node.name() != "Route"){
2096 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2100 if ((prop = node.property (X_("name"))) != 0) {
2101 Route::set_name (prop->value());
2105 _initial_io_setup = true;
2107 if ((prop = node.property (X_("flags"))) != 0) {
2108 _flags = Flag (string_2_enum (prop->value(), _flags));
2113 if (is_master() || is_monitor() || is_auditioner()) {
2114 _mute_master->set_solo_ignore (true);
2118 /* monitor bus does not get a panner, but if (re)created
2119 via XML, it will already have one by the time we
2120 call ::set_state(). so ... remove it.
2125 /* add all processors (except amp, which is always present) */
2127 nlist = node.children();
2128 XMLNode processor_state (X_("processor_state"));
2130 Stateful::save_extra_xml (node);
2132 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2136 if (child->name() == IO::state_node_name) {
2137 if ((prop = child->property (X_("direction"))) == 0) {
2141 if (prop->value() == "Input") {
2142 _input->set_state (*child, version);
2143 } else if (prop->value() == "Output") {
2144 _output->set_state (*child, version);
2148 if (child->name() == X_("Processor")) {
2149 processor_state.add_child_copy (*child);
2152 if (child->name() == X_("Pannable")) {
2154 _pannable->set_state (*child, version);
2156 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2161 if ((prop = node.property (X_("meter-point"))) != 0) {
2162 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2163 set_meter_point (mp, true);
2165 _meter->set_display_to_user (_meter_point == MeterCustom);
2169 if ((prop = node.property (X_("meter-type"))) != 0) {
2170 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2173 _initial_io_setup = false;
2175 set_processor_state (processor_state);
2177 // this looks up the internal instrument in processors
2178 reset_instrument_info();
2180 if ((prop = node.property ("self-solo")) != 0) {
2181 set_self_solo (string_is_affirmative (prop->value()));
2184 if ((prop = node.property ("soloed-by-upstream")) != 0) {
2185 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
2186 mod_solo_by_others_upstream (atoi (prop->value()));
2189 if ((prop = node.property ("soloed-by-downstream")) != 0) {
2190 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
2191 mod_solo_by_others_downstream (atoi (prop->value()));
2194 if ((prop = node.property ("solo-isolated")) != 0) {
2195 set_solo_isolated (string_is_affirmative (prop->value()), this);
2198 if ((prop = node.property ("solo-safe")) != 0) {
2199 set_solo_safe (string_is_affirmative (prop->value()), this);
2202 if ((prop = node.property (X_("phase-invert"))) != 0) {
2203 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2206 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2207 set_denormal_protection (string_is_affirmative (prop->value()));
2210 if ((prop = node.property (X_("active"))) != 0) {
2211 bool yn = string_is_affirmative (prop->value());
2212 _active = !yn; // force switch
2213 set_active (yn, this);
2216 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2217 set_order_key (atoi(prop->value()));
2220 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2224 string::size_type colon, equal;
2225 string remaining = prop->value();
2227 while (remaining.length()) {
2229 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2230 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2233 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2234 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2237 string keyname = remaining.substr (0, equal);
2239 if ((keyname == "EditorSort") || (keyname == "editor")) {
2240 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2246 colon = remaining.find_first_of (':');
2248 if (colon != string::npos) {
2249 remaining = remaining.substr (colon+1);
2256 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2257 PBD::ID id (prop->value ());
2258 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2259 ProcessorList::const_iterator i = _processors.begin ();
2260 while (i != _processors.end() && (*i)->id() != id) {
2264 if (i != _processors.end ()) {
2265 _processor_after_last_custom_meter = *i;
2266 _custom_meter_position_noted = true;
2270 if ((prop = node.property (X_("last-custom-meter-was-at-end"))) != 0) {
2271 _last_custom_meter_was_at_end = string_is_affirmative (prop->value ());
2274 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2277 if (child->name() == X_("Comment")) {
2279 /* XXX this is a terrible API design in libxml++ */
2281 XMLNode *cmt = *(child->children().begin());
2282 _comment = cmt->content();
2284 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2285 if (prop->value() == "solo") {
2286 _solo_control->set_state (*child, version);
2287 } else if (prop->value() == "mute") {
2288 _mute_control->set_state (*child, version);
2291 } else if (child->name() == X_("RemoteControl")) {
2292 if ((prop = child->property (X_("id"))) != 0) {
2294 sscanf (prop->value().c_str(), "%d", &x);
2295 set_remote_control_id_internal (x);
2298 } else if (child->name() == X_("MuteMaster")) {
2299 _mute_master->set_state (*child, version);
2307 Route::set_state_2X (const XMLNode& node, int version)
2310 XMLNodeConstIterator niter;
2312 const XMLProperty *prop;
2314 /* 2X things which still remain to be handled:
2320 if (node.name() != "Route") {
2321 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2325 if ((prop = node.property (X_("flags"))) != 0) {
2326 string f = prop->value ();
2327 boost::replace_all (f, "ControlOut", "MonitorOut");
2328 _flags = Flag (string_2_enum (f, _flags));
2333 if (is_master() || is_monitor() || is_auditioner()) {
2334 _mute_master->set_solo_ignore (true);
2337 if ((prop = node.property (X_("phase-invert"))) != 0) {
2338 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
2339 if (string_is_affirmative (prop->value ())) {
2342 set_phase_invert (p);
2345 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2346 set_denormal_protection (string_is_affirmative (prop->value()));
2349 if ((prop = node.property (X_("soloed"))) != 0) {
2350 bool yn = string_is_affirmative (prop->value());
2352 /* XXX force reset of solo status */
2354 set_solo (yn, this);
2357 if ((prop = node.property (X_("muted"))) != 0) {
2360 bool muted = string_is_affirmative (prop->value());
2366 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2368 if (string_is_affirmative (prop->value())){
2369 mute_point = mute_point + "PreFader";
2374 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2376 if (string_is_affirmative (prop->value())){
2379 mute_point = mute_point + ",";
2382 mute_point = mute_point + "PostFader";
2387 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2389 if (string_is_affirmative (prop->value())){
2392 mute_point = mute_point + ",";
2395 mute_point = mute_point + "Listen";
2400 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2402 if (string_is_affirmative (prop->value())){
2405 mute_point = mute_point + ",";
2408 mute_point = mute_point + "Main";
2412 _mute_master->set_mute_points (mute_point);
2413 _mute_master->set_muted_by_self (true);
2417 if ((prop = node.property (X_("meter-point"))) != 0) {
2418 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2421 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2422 don't mean the same thing.
2425 if ((prop = node.property (X_("order-keys"))) != 0) {
2429 string::size_type colon, equal;
2430 string remaining = prop->value();
2432 while (remaining.length()) {
2434 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2435 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2438 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2439 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2442 string keyname = remaining.substr (0, equal);
2444 if (keyname == "EditorSort" || keyname == "editor") {
2445 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
2451 colon = remaining.find_first_of (':');
2453 if (colon != string::npos) {
2454 remaining = remaining.substr (colon+1);
2463 nlist = node.children ();
2464 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2468 if (child->name() == IO::state_node_name) {
2470 /* there is a note in IO::set_state_2X() about why we have to call
2474 _input->set_state_2X (*child, version, true);
2475 _output->set_state_2X (*child, version, false);
2477 if ((prop = child->property (X_("name"))) != 0) {
2478 Route::set_name (prop->value ());
2483 if ((prop = child->property (X_("active"))) != 0) {
2484 bool yn = string_is_affirmative (prop->value());
2485 _active = !yn; // force switch
2486 set_active (yn, this);
2489 if ((prop = child->property (X_("gain"))) != 0) {
2492 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2493 _amp->gain_control()->set_value (val);
2497 /* Set up Panners in the IO */
2498 XMLNodeList io_nlist = child->children ();
2500 XMLNodeConstIterator io_niter;
2503 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2505 io_child = *io_niter;
2507 if (io_child->name() == X_("Panner")) {
2508 _main_outs->panner_shell()->set_state(*io_child, version);
2509 } else if (io_child->name() == X_("Automation")) {
2510 /* IO's automation is for the fader */
2511 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2517 XMLNodeList redirect_nodes;
2519 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2523 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2524 redirect_nodes.push_back(child);
2529 set_processor_state_2X (redirect_nodes, version);
2531 Stateful::save_extra_xml (node);
2533 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2536 if (child->name() == X_("Comment")) {
2538 /* XXX this is a terrible API design in libxml++ */
2540 XMLNode *cmt = *(child->children().begin());
2541 _comment = cmt->content();
2543 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2544 if (prop->value() == X_("solo")) {
2545 _solo_control->set_state (*child, version);
2546 } else if (prop->value() == X_("mute")) {
2547 _mute_control->set_state (*child, version);
2550 } else if (child->name() == X_("RemoteControl")) {
2551 if ((prop = child->property (X_("id"))) != 0) {
2553 sscanf (prop->value().c_str(), "%d", &x);
2554 set_remote_control_id_internal (x);
2564 Route::get_processor_state ()
2566 XMLNode* root = new XMLNode (X_("redirects"));
2567 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2568 root->add_child_nocopy ((*i)->state (true));
2575 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2577 /* We don't bother removing existing processors not in nList, as this
2578 method will only be called when creating a Route from scratch, not
2579 for undo purposes. Just put processors in at the appropriate place
2583 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2584 add_processor_from_xml_2X (**i, version);
2589 Route::set_processor_state (const XMLNode& node)
2591 const XMLNodeList &nlist = node.children();
2592 XMLNodeConstIterator niter;
2593 ProcessorList new_order;
2594 bool must_configure = false;
2596 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2598 XMLProperty* prop = (*niter)->property ("type");
2600 if (prop->value() == "amp") {
2601 _amp->set_state (**niter, Stateful::current_state_version);
2602 new_order.push_back (_amp);
2603 } else if (prop->value() == "meter") {
2604 _meter->set_state (**niter, Stateful::current_state_version);
2605 new_order.push_back (_meter);
2606 } else if (prop->value() == "delay") {
2607 _delayline->set_state (**niter, Stateful::current_state_version);
2608 new_order.push_back (_delayline);
2609 } else if (prop->value() == "main-outs") {
2610 _main_outs->set_state (**niter, Stateful::current_state_version);
2611 } else if (prop->value() == "intreturn") {
2613 _intreturn.reset (new InternalReturn (_session));
2614 must_configure = true;
2616 _intreturn->set_state (**niter, Stateful::current_state_version);
2617 } else if (is_monitor() && prop->value() == "monitor") {
2618 if (!_monitor_control) {
2619 _monitor_control.reset (new MonitorProcessor (_session));
2620 must_configure = true;
2622 _monitor_control->set_state (**niter, Stateful::current_state_version);
2623 } else if (prop->value() == "capture") {
2624 /* CapturingProcessor should never be restored, it's always
2625 added explicitly when needed */
2627 ProcessorList::iterator o;
2629 for (o = _processors.begin(); o != _processors.end(); ++o) {
2630 XMLProperty* id_prop = (*niter)->property(X_("id"));
2631 if (id_prop && (*o)->id() == id_prop->value()) {
2632 (*o)->set_state (**niter, Stateful::current_state_version);
2633 new_order.push_back (*o);
2638 // If the processor (*niter) is not on the route then create it
2640 if (o == _processors.end()) {
2642 boost::shared_ptr<Processor> processor;
2644 if (prop->value() == "intsend") {
2646 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::shared_ptr<Route>(), Delivery::Aux, true));
2648 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2649 prop->value() == "lv2" ||
2650 prop->value() == "windows-vst" ||
2651 prop->value() == "lxvst" ||
2652 prop->value() == "audiounit") {
2654 processor.reset (new PluginInsert(_session));
2656 } else if (prop->value() == "port") {
2658 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2660 } else if (prop->value() == "send") {
2662 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
2665 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2669 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2670 /* This processor could not be configured. Turn it into a UnknownProcessor */
2671 processor.reset (new UnknownProcessor (_session, **niter));
2674 /* we have to note the monitor send here, otherwise a new one will be created
2675 and the state of this one will be lost.
2677 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
2678 if (isend && isend->role() == Delivery::Listen) {
2679 _monitor_send = isend;
2682 /* it doesn't matter if invisible processors are added here, as they
2683 will be sorted out by setup_invisible_processors () shortly.
2686 new_order.push_back (processor);
2687 must_configure = true;
2693 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2694 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2695 _processors = new_order;
2697 if (must_configure) {
2698 configure_processors_unlocked (0);
2701 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2703 (*i)->set_owner (this);
2704 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2706 boost::shared_ptr<PluginInsert> pi;
2708 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2709 if (pi->has_no_inputs ()) {
2710 _have_internal_generator = true;
2717 reset_instrument_info ();
2718 processors_changed (RouteProcessorChange ());
2719 set_processor_positions ();
2723 Route::curve_reallocate ()
2725 // _gain_automation_curve.finish_resize ();
2726 // _pan_automation_curve.finish_resize ();
2730 Route::silence (framecnt_t nframes)
2732 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
2737 silence_unlocked (nframes);
2741 Route::silence_unlocked (framecnt_t nframes)
2743 /* Must be called with the processor lock held */
2747 _output->silence (nframes);
2749 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2750 boost::shared_ptr<PluginInsert> pi;
2752 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2753 // skip plugins, they don't need anything when we're not active
2757 (*i)->silence (nframes);
2760 if (nframes == _session.get_block_size()) {
2767 Route::add_internal_return ()
2770 _intreturn.reset (new InternalReturn (_session));
2771 add_processor (_intreturn, PreFader);
2776 Route::add_send_to_internal_return (InternalSend* send)
2778 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2780 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2781 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2784 return d->add_send (send);
2790 Route::remove_send_from_internal_return (InternalSend* send)
2792 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2794 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2795 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2798 return d->remove_send (send);
2804 Route::enable_monitor_send ()
2806 /* Caller must hold process lock */
2807 assert (!AudioEngine::instance()->process_lock().trylock());
2809 /* master never sends to monitor section via the normal mechanism */
2810 assert (!is_master ());
2811 assert (!is_monitor ());
2813 /* make sure we have one */
2814 if (!_monitor_send) {
2815 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, _session.monitor_out(), Delivery::Listen));
2816 _monitor_send->set_display_to_user (false);
2820 configure_processors (0);
2823 /** Add an aux send to a route.
2824 * @param route route to send to.
2825 * @param before Processor to insert before, or 0 to insert at the end.
2828 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
2830 assert (route != _session.monitor_out ());
2833 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2835 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2837 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
2839 if (d && d->target_route() == route) {
2840 /* already listening via the specified IO: do nothing */
2848 boost::shared_ptr<InternalSend> listener;
2851 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
2852 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
2853 listener.reset (new InternalSend (_session, sendpan, _mute_master, route, Delivery::Aux));
2856 add_processor (listener, before);
2858 } catch (failed_constructor& err) {
2866 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
2868 ProcessorStreams err;
2869 ProcessorList::iterator tmp;
2872 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
2874 /* have to do this early because otherwise processor reconfig
2875 * will put _monitor_send back in the list
2878 if (route == _session.monitor_out()) {
2879 _monitor_send.reset ();
2883 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2885 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2887 if (d && d->target_route() == route) {
2889 remove_processor (*x, &err, false);
2892 /* list could have been demolished while we dropped the lock
2903 Route::set_comment (string cmt, void *src)
2906 comment_changed (src);
2907 _session.set_dirty ();
2911 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
2913 FeedRecord fr (other, via_sends_only);
2915 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
2917 if (!result.second) {
2919 /* already a record for "other" - make sure sends-only information is correct */
2920 if (!via_sends_only && result.first->sends_only) {
2921 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
2922 frp->sends_only = false;
2926 return result.second;
2930 Route::clear_fed_by ()
2936 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
2938 const FedBy& fed_by (other->fed_by());
2940 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
2941 boost::shared_ptr<Route> sr = f->r.lock();
2943 if (sr && (sr.get() == this)) {
2945 if (via_sends_only) {
2946 *via_sends_only = f->sends_only;
2957 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
2959 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
2961 if (_output->connected_to (other->input())) {
2962 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
2963 if (via_send_only) {
2964 *via_send_only = false;
2971 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
2973 boost::shared_ptr<IOProcessor> iop;
2975 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
2976 if (iop->feeds (other)) {
2977 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
2978 if (via_send_only) {
2979 *via_send_only = true;
2983 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
2986 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
2991 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
2996 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
2998 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3001 /** Called from the (non-realtime) butler thread when the transport is stopped */
3003 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3005 framepos_t now = _session.transport_frame();
3008 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3010 Automatable::transport_stopped (now);
3012 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3014 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3018 (*i)->transport_stopped (now);
3022 _roll_delay = _initial_delay;
3026 Route::input_change_handler (IOChange change, void * /*src*/)
3028 bool need_to_queue_solo_change = true;
3030 if ((change.type & IOChange::ConfigurationChanged)) {
3031 /* This is called with the process lock held if change
3032 contains ConfigurationChanged
3034 need_to_queue_solo_change = false;
3035 configure_processors (0);
3036 _phase_invert.resize (_input->n_ports().n_audio ());
3037 io_changed (); /* EMIT SIGNAL */
3040 if (!_input->connected() && _soloed_by_others_upstream) {
3041 if (need_to_queue_solo_change) {
3042 _session.cancel_solo_after_disconnect (shared_from_this(), true);
3044 cancel_solo_after_disconnect (true);
3050 Route::output_change_handler (IOChange change, void * /*src*/)
3052 bool need_to_queue_solo_change = true;
3053 if (_initial_io_setup) {
3057 if ((change.type & IOChange::ConfigurationChanged)) {
3058 /* This is called with the process lock held if change
3059 contains ConfigurationChanged
3061 need_to_queue_solo_change = false;
3062 configure_processors (0);
3063 io_changed (); /* EMIT SIGNAL */
3066 if (!_output->connected() && _soloed_by_others_downstream) {
3067 if (need_to_queue_solo_change) {
3068 _session.cancel_solo_after_disconnect (shared_from_this(), false);
3070 cancel_solo_after_disconnect (false);
3076 Route::cancel_solo_after_disconnect (bool upstream)
3079 _soloed_by_others_upstream = 0;
3081 _soloed_by_others_downstream = 0;
3083 set_mute_master_solo ();
3084 solo_changed (false, this);
3088 Route::pans_required () const
3090 if (n_outputs().n_audio() < 2) {
3094 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3098 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3100 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3106 if (n_outputs().n_total() == 0) {
3110 if (!_active || n_inputs() == ChanCount::ZERO) {
3111 silence_unlocked (nframes);
3115 if (session_state_changing) {
3116 if (_session.transport_speed() != 0.0f) {
3117 /* we're rolling but some state is changing (e.g. our diskstream contents)
3118 so we cannot use them. Be silent till this is over.
3120 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3122 silence_unlocked (nframes);
3125 /* we're really not rolling, so we're either delivery silence or actually
3126 monitoring, both of which are safe to do while session_state_changing is true.
3130 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3132 fill_buffers_with_input (bufs, _input, nframes);
3134 if (_meter_point == MeterInput) {
3135 _meter->run (bufs, start_frame, end_frame, nframes, true);
3138 _amp->apply_gain_automation (false);
3139 passthru (bufs, start_frame, end_frame, nframes, 0);
3145 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3147 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3152 if (n_outputs().n_total() == 0) {
3156 if (!_active || n_inputs().n_total() == 0) {
3157 silence_unlocked (nframes);
3161 framepos_t unused = 0;
3163 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3169 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3171 fill_buffers_with_input (bufs, _input, nframes);
3173 if (_meter_point == MeterInput) {
3174 _meter->run (bufs, start_frame, end_frame, nframes, true);
3177 passthru (bufs, start_frame, end_frame, nframes, declick);
3183 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3190 Route::flush_processors ()
3192 /* XXX shouldn't really try to take this lock, since
3193 this is called from the RT audio thread.
3196 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3198 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3204 Route::set_meter_point (MeterPoint p, bool force)
3206 if (_meter_point == p && !force) {
3210 bool meter_was_visible_to_user = _meter->display_to_user ();
3213 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3214 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3216 maybe_note_meter_position ();
3220 if (_meter_point != MeterCustom) {
3222 _meter->set_display_to_user (false);
3224 setup_invisible_processors ();
3228 _meter->set_display_to_user (true);
3230 /* If we have a previous position for the custom meter, try to put it there */
3231 if (_custom_meter_position_noted) {
3232 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3235 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3236 if (i != _processors.end ()) {
3237 _processors.remove (_meter);
3238 _processors.insert (i, _meter);
3240 } else if (_last_custom_meter_was_at_end) {
3241 _processors.remove (_meter);
3242 _processors.push_back (_meter);
3247 /* Set up the meter for its new position */
3249 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3253 if (loc == _processors.begin()) {
3254 m_in = _input->n_ports();
3256 ProcessorList::iterator before = loc;
3258 m_in = (*before)->output_streams ();
3261 _meter->reflect_inputs (m_in);
3263 /* we do not need to reconfigure the processors, because the meter
3264 (a) is always ready to handle processor_max_streams
3265 (b) is always an N-in/N-out processor, and thus moving
3266 it doesn't require any changes to the other processors.
3270 meter_change (); /* EMIT SIGNAL */
3272 bool const meter_visibly_changed = (_meter->display_to_user() != meter_was_visible_to_user);
3274 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
3278 Route::listen_position_changed ()
3281 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3282 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3283 ProcessorState pstate (this);
3285 if (configure_processors_unlocked (0)) {
3287 configure_processors_unlocked (0); // it worked before we tried to add it ...
3292 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3293 _session.set_dirty ();
3296 boost::shared_ptr<CapturingProcessor>
3297 Route::add_export_point()
3299 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3300 if (!_capturing_processor) {
3302 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3303 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3305 _capturing_processor.reset (new CapturingProcessor (_session));
3306 _capturing_processor->activate ();
3308 configure_processors_unlocked (0);
3312 return _capturing_processor;
3316 Route::update_signal_latency ()
3318 framecnt_t l = _output->user_latency();
3319 framecnt_t lamp = 0;
3320 bool before_amp = true;
3322 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3323 if ((*i)->active ()) {
3324 l += (*i)->signal_latency ();
3334 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3336 _signal_latency_at_amp_position = lamp;
3337 if (_signal_latency != l) {
3338 _signal_latency = l;
3339 signal_latency_changed (); /* EMIT SIGNAL */
3342 return _signal_latency;
3346 Route::set_user_latency (framecnt_t nframes)
3348 _output->set_user_latency (nframes);
3349 _session.update_latency_compensation ();
3353 Route::set_latency_compensation (framecnt_t longest_session_latency)
3355 framecnt_t old = _initial_delay;
3357 if (_signal_latency < longest_session_latency) {
3358 _initial_delay = longest_session_latency - _signal_latency;
3363 DEBUG_TRACE (DEBUG::Latency, string_compose (
3364 "%1: compensate for maximum latency of %2,"
3365 "given own latency of %3, using initial delay of %4\n",
3366 name(), longest_session_latency, _signal_latency, _initial_delay));
3368 if (_initial_delay != old) {
3369 initial_delay_changed (); /* EMIT SIGNAL */
3372 if (_session.transport_stopped()) {
3373 _roll_delay = _initial_delay;
3377 Route::SoloControllable::SoloControllable (std::string name, boost::shared_ptr<Route> r)
3378 : AutomationControl (r->session(), Evoral::Parameter (SoloAutomation),
3379 boost::shared_ptr<AutomationList>(), name)
3382 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
3387 Route::SoloControllable::set_value (double val)
3389 bool bval = ((val >= 0.5f) ? true: false);
3391 boost::shared_ptr<RouteList> rl (new RouteList);
3393 boost::shared_ptr<Route> r = _route.lock ();
3400 if (Config->get_solo_control_is_listen_control()) {
3401 _session.set_listen (rl, bval);
3403 _session.set_solo (rl, bval);
3408 Route::SoloControllable::get_value () const
3410 boost::shared_ptr<Route> r = _route.lock ();
3415 if (Config->get_solo_control_is_listen_control()) {
3416 return r->listening_via_monitor() ? 1.0f : 0.0f;
3418 return r->self_soloed() ? 1.0f : 0.0f;
3422 Route::MuteControllable::MuteControllable (std::string name, boost::shared_ptr<Route> r)
3423 : AutomationControl (r->session(), Evoral::Parameter (MuteAutomation),
3424 boost::shared_ptr<AutomationList>(), name)
3427 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
3432 Route::MuteControllable::set_value (double val)
3434 bool bval = ((val >= 0.5f) ? true: false);
3436 boost::shared_ptr<RouteList> rl (new RouteList);
3438 boost::shared_ptr<Route> r = _route.lock ();
3444 _session.set_mute (rl, bval);
3448 Route::MuteControllable::get_value () const
3450 boost::shared_ptr<Route> r = _route.lock ();
3455 return r->muted() ? 1.0f : 0.0f;
3459 Route::set_block_size (pframes_t nframes)
3461 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3462 (*i)->set_block_size (nframes);
3465 _session.ensure_buffers (n_process_buffers ());
3469 Route::protect_automation ()
3471 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3472 (*i)->protect_automation();
3475 /** @param declick 1 to set a pending declick fade-in,
3476 * -1 to set a pending declick fade-out
3479 Route::set_pending_declick (int declick)
3482 /* this call is not allowed to turn off a pending declick */
3484 _pending_declick = declick;
3487 _pending_declick = 0;
3491 /** Shift automation forwards from a particular place, thereby inserting time.
3492 * Adds undo commands for any shifts that are performed.
3494 * @param pos Position to start shifting from.
3495 * @param frames Amount to shift forwards by.
3499 Route::shift (framepos_t pos, framecnt_t frames)
3501 /* gain automation */
3503 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
3505 XMLNode &before = gc->alist()->get_state ();
3506 gc->alist()->shift (pos, frames);
3507 XMLNode &after = gc->alist()->get_state ();
3508 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3511 /* pan automation */
3513 ControlSet::Controls& c (_pannable->controls());
3515 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
3516 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
3518 boost::shared_ptr<AutomationList> al = pc->alist();
3519 XMLNode& before = al->get_state ();
3520 al->shift (pos, frames);
3521 XMLNode& after = al->get_state ();
3522 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3527 /* redirect automation */
3529 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3530 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
3532 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
3534 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
3535 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
3537 boost::shared_ptr<AutomationList> al = ac->alist();
3538 XMLNode &before = al->get_state ();
3539 al->shift (pos, frames);
3540 XMLNode &after = al->get_state ();
3541 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3550 Route::save_as_template (const string& path, const string& name)
3552 XMLNode& node (state (false));
3555 IO::set_name_in_state (*node.children().front(), name);
3557 tree.set_root (&node);
3558 return tree.write (path.c_str());
3563 Route::set_name (const string& str)
3569 name = Route::ensure_track_or_route_name (str, _session);
3570 SessionObject::set_name (name);
3572 ret = (_input->set_name(name) && _output->set_name(name));
3575 /* rename the main outs. Leave other IO processors
3576 * with whatever name they already have, because its
3577 * just fine as it is (it will not contain the route
3578 * name if its a port insert, port send or port return).
3582 if (_main_outs->set_name (name)) {
3583 /* XXX returning false here is stupid because
3584 we already changed the route name.
3594 /** Set the name of a route in an XML description.
3595 * @param node XML <Route> node to set the name in.
3596 * @param name New name.
3599 Route::set_name_in_state (XMLNode& node, string const & name)
3601 node.add_property (X_("name"), name);
3603 XMLNodeList children = node.children();
3604 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
3606 if ((*i)->name() == X_("IO")) {
3608 IO::set_name_in_state (**i, name);
3610 } else if ((*i)->name() == X_("Processor")) {
3612 XMLProperty* role = (*i)->property (X_("role"));
3613 if (role && role->value() == X_("Main")) {
3614 (*i)->add_property (X_("name"), name);
3617 } else if ((*i)->name() == X_("Diskstream")) {
3619 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
3620 (*i)->add_property (X_("name"), name);
3626 boost::shared_ptr<Send>
3627 Route::internal_send_for (boost::shared_ptr<const Route> target) const
3629 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3631 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3632 boost::shared_ptr<InternalSend> send;
3634 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
3635 if (send->target_route() == target) {
3641 return boost::shared_ptr<Send>();
3644 /** @param c Audio channel index.
3645 * @param yn true to invert phase, otherwise false.
3648 Route::set_phase_invert (uint32_t c, bool yn)
3650 if (_phase_invert[c] != yn) {
3651 _phase_invert[c] = yn;
3652 phase_invert_changed (); /* EMIT SIGNAL */
3653 _session.set_dirty ();
3658 Route::set_phase_invert (boost::dynamic_bitset<> p)
3660 if (_phase_invert != p) {
3662 phase_invert_changed (); /* EMIT SIGNAL */
3663 _session.set_dirty ();
3668 Route::phase_invert (uint32_t c) const
3670 return _phase_invert[c];
3673 boost::dynamic_bitset<>
3674 Route::phase_invert () const
3676 return _phase_invert;
3680 Route::set_denormal_protection (bool yn)
3682 if (_denormal_protection != yn) {
3683 _denormal_protection = yn;
3684 denormal_protection_changed (); /* EMIT SIGNAL */
3689 Route::denormal_protection () const
3691 return _denormal_protection;
3695 Route::set_active (bool yn, void* src)
3697 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
3698 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
3702 if (_active != yn) {
3704 _input->set_active (yn);
3705 _output->set_active (yn);
3706 active_changed (); // EMIT SIGNAL
3707 _session.set_dirty ();
3714 Glib::Threads::RWLock::ReaderLock rm (_processor_lock, Glib::Threads::TRY_LOCK);
3720 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3722 boost::shared_ptr<Send> s;
3723 boost::shared_ptr<Return> r;
3725 if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
3726 s->meter()->meter();
3727 } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
3728 r->meter()->meter ();
3733 boost::shared_ptr<Pannable>
3734 Route::pannable() const
3739 boost::shared_ptr<Panner>
3740 Route::panner() const
3743 return _main_outs->panner_shell()->panner();
3746 boost::shared_ptr<PannerShell>
3747 Route::panner_shell() const
3749 return _main_outs->panner_shell();
3752 boost::shared_ptr<AutomationControl>
3753 Route::gain_control() const
3755 return _amp->gain_control();
3758 boost::shared_ptr<AutomationControl>
3759 Route::get_control (const Evoral::Parameter& param)
3761 /* either we own the control or .... */
3763 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
3767 /* maybe one of our processors does or ... */
3769 Glib::Threads::RWLock::ReaderLock rm (_processor_lock, Glib::Threads::TRY_LOCK);
3770 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3771 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
3779 /* nobody does so we'll make a new one */
3781 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
3788 boost::shared_ptr<Processor>
3789 Route::nth_plugin (uint32_t n)
3791 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3792 ProcessorList::iterator i;
3794 for (i = _processors.begin(); i != _processors.end(); ++i) {
3795 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
3802 return boost::shared_ptr<Processor> ();
3805 boost::shared_ptr<Processor>
3806 Route::nth_send (uint32_t n)
3808 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3809 ProcessorList::iterator i;
3811 for (i = _processors.begin(); i != _processors.end(); ++i) {
3812 if (boost::dynamic_pointer_cast<Send> (*i)) {
3819 return boost::shared_ptr<Processor> ();
3823 Route::has_io_processor_named (const string& name)
3825 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3826 ProcessorList::iterator i;
3828 for (i = _processors.begin(); i != _processors.end(); ++i) {
3829 if (boost::dynamic_pointer_cast<Send> (*i) ||
3830 boost::dynamic_pointer_cast<PortInsert> (*i)) {
3831 if ((*i)->name() == name) {
3840 MuteMaster::MutePoint
3841 Route::mute_points () const
3843 return _mute_master->mute_points ();
3847 Route::set_processor_positions ()
3849 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3851 bool had_amp = false;
3852 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3853 (*i)->set_pre_fader (!had_amp);
3854 if (boost::dynamic_pointer_cast<Amp> (*i)) {
3860 /** Called when there is a proposed change to the input port count */
3862 Route::input_port_count_changing (ChanCount to)
3864 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
3866 /* The processors cannot be configured with the new input arrangement, so
3872 /* The change is ok */
3876 /** Called when there is a proposed change to the output port count */
3878 Route::output_port_count_changing (ChanCount to)
3880 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
3881 if (processor_out_streams.get(*t) > to.get(*t)) {
3885 /* The change is ok */
3890 Route::unknown_processors () const
3894 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3895 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3896 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
3897 p.push_back ((*i)->name ());
3906 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
3908 /* we assume that all our input ports feed all our output ports. its not
3909 universally true, but the alternative is way too corner-case to worry about.
3912 LatencyRange all_connections;
3915 all_connections.min = 0;
3916 all_connections.max = 0;
3918 all_connections.min = ~((pframes_t) 0);
3919 all_connections.max = 0;
3921 /* iterate over all "from" ports and determine the latency range for all of their
3922 connections to the "outside" (outside of this Route).
3925 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
3929 p->get_connected_latency_range (range, playback);
3931 all_connections.min = min (all_connections.min, range.min);
3932 all_connections.max = max (all_connections.max, range.max);
3936 /* set the "from" port latencies to the max/min range of all their connections */
3938 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
3939 p->set_private_latency_range (all_connections, playback);
3942 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
3944 all_connections.min += our_latency;
3945 all_connections.max += our_latency;
3947 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
3948 p->set_private_latency_range (all_connections, playback);
3951 return all_connections.max;
3955 Route::set_private_port_latencies (bool playback) const
3957 framecnt_t own_latency = 0;
3959 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
3960 OR LATENCY CALLBACK.
3962 This is called (early) from the latency callback. It computes the REAL
3963 latency associated with each port and stores the result as the "private"
3964 latency of the port. A later call to Route::set_public_port_latencies()
3965 sets all ports to the same value to reflect the fact that we do latency
3966 compensation and so all signals are delayed by the same amount as they
3967 flow through ardour.
3970 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3971 if ((*i)->active ()) {
3972 own_latency += (*i)->signal_latency ();
3977 /* playback: propagate latency from "outside the route" to outputs to inputs */
3978 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
3980 /* capture: propagate latency from "outside the route" to inputs to outputs */
3981 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
3986 Route::set_public_port_latencies (framecnt_t value, bool playback) const
3988 /* this is called to set the JACK-visible port latencies, which take
3989 latency compensation into account.
3998 const PortSet& ports (_input->ports());
3999 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4000 p->set_public_latency_range (range, playback);
4005 const PortSet& ports (_output->ports());
4006 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4007 p->set_public_latency_range (range, playback);
4012 /** Put the invisible processors in the right place in _processors.
4013 * Must be called with a writer lock on _processor_lock held.
4016 Route::setup_invisible_processors ()
4019 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4020 assert (!lm.locked ());
4024 /* too early to be doing this stuff */
4028 /* we'll build this new list here and then use it */
4030 ProcessorList new_processors;
4032 /* find visible processors */
4034 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4035 if ((*i)->display_to_user ()) {
4036 new_processors.push_back (*i);
4042 ProcessorList::iterator amp = new_processors.begin ();
4043 while (amp != new_processors.end() && boost::dynamic_pointer_cast<Amp> (*amp) == 0) {
4047 assert (amp != new_processors.end ());
4049 /* and the processor after the amp */
4051 ProcessorList::iterator after_amp = amp;
4057 switch (_meter_point) {
4059 assert (!_meter->display_to_user ());
4060 new_processors.push_front (_meter);
4063 assert (!_meter->display_to_user ());
4064 new_processors.insert (amp, _meter);
4066 case MeterPostFader:
4067 /* do nothing here */
4070 /* do nothing here */
4073 /* the meter is visible, so we don't touch it here */
4080 assert (_main_outs);
4081 assert (!_main_outs->display_to_user ());
4082 new_processors.push_back (_main_outs);
4084 /* iterator for the main outs */
4086 ProcessorList::iterator main = new_processors.end();
4089 /* OUTPUT METERING */
4091 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4092 assert (!_meter->display_to_user ());
4094 /* add the processor just before or just after the main outs */
4096 ProcessorList::iterator meter_point = main;
4098 if (_meter_point == MeterOutput) {
4101 new_processors.insert (meter_point, _meter);
4106 if (_monitor_send && !is_monitor ()) {
4107 assert (!_monitor_send->display_to_user ());
4108 if (Config->get_solo_control_is_listen_control()) {
4109 switch (Config->get_listen_position ()) {
4110 case PreFaderListen:
4111 switch (Config->get_pfl_position ()) {
4112 case PFLFromBeforeProcessors:
4113 new_processors.push_front (_monitor_send);
4115 case PFLFromAfterProcessors:
4116 new_processors.insert (amp, _monitor_send);
4119 _monitor_send->set_can_pan (false);
4121 case AfterFaderListen:
4122 switch (Config->get_afl_position ()) {
4123 case AFLFromBeforeProcessors:
4124 new_processors.insert (after_amp, _monitor_send);
4126 case AFLFromAfterProcessors:
4127 new_processors.insert (new_processors.end(), _monitor_send);
4130 _monitor_send->set_can_pan (true);
4134 new_processors.insert (new_processors.end(), _monitor_send);
4135 _monitor_send->set_can_pan (false);
4139 if (!is_master() && !is_monitor() && !is_auditioner()) {
4140 new_processors.push_front (_delayline);
4143 /* MONITOR CONTROL */
4145 if (_monitor_control && is_monitor ()) {
4146 assert (!_monitor_control->display_to_user ());
4147 new_processors.push_front (_monitor_control);
4150 /* INTERNAL RETURN */
4152 /* doing this here means that any monitor control will come just after
4157 assert (!_intreturn->display_to_user ());
4158 new_processors.push_front (_intreturn);
4161 /* EXPORT PROCESSOR */
4163 if (_capturing_processor) {
4164 assert (!_capturing_processor->display_to_user ());
4165 new_processors.push_front (_capturing_processor);
4168 _processors = new_processors;
4170 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4171 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4172 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4179 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4180 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4184 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4185 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4192 /** If the meter point is `Custom', make a note of where the meter is.
4193 * This is so that if the meter point is subsequently set to something else,
4194 * and then back to custom, we can put the meter back where it was last time
4195 * custom was enabled.
4197 * Must be called with the _processor_lock held.
4200 Route::maybe_note_meter_position ()
4202 if (_meter_point != MeterCustom) {
4206 _custom_meter_position_noted = true;
4207 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4208 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4209 ProcessorList::iterator j = i;
4211 if (j != _processors.end ()) {
4212 _processor_after_last_custom_meter = *j;
4213 _last_custom_meter_was_at_end = false;
4215 _last_custom_meter_was_at_end = true;
4221 boost::shared_ptr<Processor>
4222 Route::processor_by_id (PBD::ID id) const
4224 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4225 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4226 if ((*i)->id() == id) {
4231 return boost::shared_ptr<Processor> ();
4234 /** @return the monitoring state, or in other words what data we are pushing
4235 * into the route (data from the inputs, data from disk or silence)
4238 Route::monitoring_state () const
4240 return MonitoringInput;
4243 /** @return what we should be metering; either the data coming from the input
4244 * IO or the data that is flowing through the route.
4247 Route::metering_state () const
4249 return MeteringRoute;
4253 Route::has_external_redirects () const
4255 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4257 /* ignore inactive processors and obviously ignore the main
4258 * outs since everything has them and we don't care.
4261 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4269 boost::shared_ptr<Processor>
4270 Route::the_instrument () const
4272 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4273 return the_instrument_unlocked ();
4276 boost::shared_ptr<Processor>
4277 Route::the_instrument_unlocked () const
4279 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4280 if (boost::dynamic_pointer_cast<PluginInsert>(*i)) {
4281 if ((*i)->input_streams().n_midi() > 0 &&
4282 (*i)->output_streams().n_audio() > 0) {
4287 return boost::shared_ptr<Processor>();
4293 Route::non_realtime_locate (framepos_t pos)
4296 _pannable->transport_located (pos);
4299 if (_delayline.get()) {
4300 _delayline.get()->flush();
4304 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4305 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4307 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4308 (*i)->transport_located (pos);
4314 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4321 * We don't currently mix MIDI input together, so we don't need the
4322 * complex logic of the audio case.
4325 n_buffers = bufs.count().n_midi ();
4327 for (i = 0; i < n_buffers; ++i) {
4329 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4330 MidiBuffer& buf (bufs.get_midi (i));
4333 buf.copy (source_port->get_midi_buffer(nframes));
4335 buf.silence (nframes);
4341 n_buffers = bufs.count().n_audio();
4343 size_t n_ports = io->n_ports().n_audio();
4344 float scaling = 1.0f;
4346 if (n_ports > n_buffers) {
4347 scaling = ((float) n_buffers) / n_ports;
4350 for (i = 0; i < n_ports; ++i) {
4352 /* if there are more ports than buffers, map them onto buffers
4353 * in a round-robin fashion
4356 boost::shared_ptr<AudioPort> source_port = io->audio (i);
4357 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
4360 if (i < n_buffers) {
4362 /* first time through just copy a channel into
4366 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
4368 if (scaling != 1.0f) {
4369 buf.apply_gain (scaling, nframes);
4374 /* on subsequent times around, merge data from
4375 * the port with what is already there
4378 if (scaling != 1.0f) {
4379 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
4381 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
4386 /* silence any remaining buffers */
4388 for (; i < n_buffers; ++i) {
4389 AudioBuffer& buf (bufs.get_audio (i));
4390 buf.silence (nframes);
4393 /* establish the initial setup of the buffer set, reflecting what was
4394 copied into it. unless, of course, we are the auditioner, in which
4395 case nothing was fed into it from the inputs at all.
4398 if (!is_auditioner()) {
4399 bufs.set_count (io->n_ports());