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.
24 #include <sigc++/bind.h>
25 #include <pbd/xml++.h>
26 #include <pbd/enumwriter.h>
27 #include <pbd/stacktrace.h>
29 #include <ardour/timestamps.h>
30 #include <ardour/audioengine.h>
31 #include <ardour/route.h>
32 #include <ardour/buffer.h>
33 #include <ardour/processor.h>
34 #include <ardour/plugin_insert.h>
35 #include <ardour/port_insert.h>
36 #include <ardour/send.h>
37 #include <ardour/session.h>
38 #include <ardour/utils.h>
39 #include <ardour/configuration.h>
40 #include <ardour/cycle_timer.h>
41 #include <ardour/route_group.h>
42 #include <ardour/port.h>
43 #include <ardour/audio_port.h>
44 #include <ardour/ladspa_plugin.h>
45 #include <ardour/panner.h>
46 #include <ardour/dB.h>
47 #include <ardour/amp.h>
48 #include <ardour/meter.h>
49 #include <ardour/buffer_set.h>
50 #include <ardour/mix.h>
51 #include <ardour/profile.h>
56 using namespace ARDOUR;
59 uint32_t Route::order_key_cnt = 0;
60 sigc::signal<void> Route::SyncOrderKeys;
62 Route::Route (Session& sess, string name, int input_min, int input_max, int output_min, int output_max, Flag flg, DataType default_type)
63 : IO (sess, name, input_min, input_max, output_min, output_max, default_type),
65 _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl)),
66 _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
71 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
72 : IO (sess, *node.child ("IO"), default_type),
73 _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl)),
74 _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
77 _set_state (node, false);
83 processor_max_outs.reset();
89 _phase_invert = false;
90 _denormal_protection = false;
91 order_keys[strdup (N_("signal"))] = order_key_cnt++;
93 _meter_point = MeterPostFader;
98 _have_internal_generator = false;
100 _pending_declick = true;
101 _remote_control_id = 0;
106 _mute_affects_pre_fader = Config->get_mute_affects_pre_fader();
107 _mute_affects_post_fader = Config->get_mute_affects_post_fader();
108 _mute_affects_control_outs = Config->get_mute_affects_control_outs();
109 _mute_affects_main_outs = Config->get_mute_affects_main_outs();
112 desired_solo_gain = 1.0;
114 desired_mute_gain = 1.0;
118 input_changed.connect (mem_fun (this, &Route::input_change_handler));
119 output_changed.connect (mem_fun (this, &Route::output_change_handler));
124 clear_processors (PreFader);
125 clear_processors (PostFader);
127 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
128 free ((void*)(i->first));
132 delete _control_outs;
137 Route::set_remote_control_id (uint32_t id)
139 if (id != _remote_control_id) {
140 _remote_control_id = id;
141 RemoteControlIDChanged ();
146 Route::remote_control_id() const
148 return _remote_control_id;
152 Route::order_key (const char* name) const
154 OrderKeys::const_iterator i;
156 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
157 if (!strcmp (name, i->first)) {
166 Route::set_order_key (const char* name, long n)
168 order_keys[strdup(name)] = n;
170 if (Config->get_sync_all_route_ordering()) {
171 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
176 _session.set_dirty ();
180 Route::sync_order_keys ()
184 if (order_keys.empty()) {
188 OrderKeys::iterator x = order_keys.begin();
192 for (; x != order_keys.end(); ++x) {
198 Route::ensure_track_or_route_name(string name, Session &session)
200 string newname = name;
202 while (session.route_by_name (newname)!=NULL)
204 newname = bump_name_once (newname);
212 Route::inc_gain (gain_t fraction, void *src)
214 IO::inc_gain (fraction, src);
218 Route::set_gain (gain_t val, void *src)
220 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
222 if (_mix_group->is_relative()) {
224 gain_t usable_gain = gain();
225 if (usable_gain < 0.000001f) {
226 usable_gain = 0.000001f;
230 if (delta < 0.000001f) {
234 delta -= usable_gain;
239 gain_t factor = delta / usable_gain;
242 factor = _mix_group->get_max_factor(factor);
243 if (factor == 0.0f) {
244 _gain_control->Changed(); /* EMIT SIGNAL */
248 factor = _mix_group->get_min_factor(factor);
249 if (factor == 0.0f) {
250 _gain_control->Changed(); /* EMIT SIGNAL */
255 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
259 _mix_group->apply (&Route::set_gain, val, _mix_group);
269 IO::set_gain (val, src);
272 /** Process this route for one (sub) cycle (process thread)
274 * @param bufs Scratch buffers to use for the signal path
275 * @param start_frame Initial transport frame
276 * @param end_frame Final transport frame
277 * @param nframes Number of frames to output (to ports)
278 * @param offset Output offset (of port buffers, for split cycles)
280 * Note that (end_frame - start_frame) may not be equal to nframes when the
281 * transport speed isn't 1.0 (eg varispeed).
284 Route::process_output_buffers (BufferSet& bufs,
285 nframes_t start_frame, nframes_t end_frame,
286 nframes_t nframes, nframes_t offset, bool with_processors, int declick,
289 // This is definitely very audio-only for now
290 assert(_default_type == DataType::AUDIO);
292 ProcessorList::iterator i;
293 bool post_fader_work = false;
294 bool mute_declick_applied = false;
300 gain_t* gab = _session.gain_automation_buffer();
302 switch (Config->get_monitoring_model()) {
303 case HardwareMonitoring:
304 case ExternalMonitoring:
311 declick = _pending_declick;
314 Glib::Mutex::Lock cm (_control_outs_lock, Glib::TRY_LOCK);
324 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
327 dmg = desired_mute_gain;
328 dsg = desired_solo_gain;
337 /* ----------------------------------------------------------------------------------------------------
338 GLOBAL DECLICK (for transport changes etc.)
339 -------------------------------------------------------------------------------------------------- */
342 Amp::run_in_place (bufs, nframes, 0.0, 1.0, false);
343 _pending_declick = 0;
344 } else if (declick < 0) {
345 Amp::run_in_place (bufs, nframes, 1.0, 0.0, false);
346 _pending_declick = 0;
349 /* no global declick */
351 if (solo_gain != dsg) {
352 Amp::run_in_place (bufs, nframes, solo_gain, dsg, false);
358 /* ----------------------------------------------------------------------------------------------------
359 INPUT METERING & MONITORING
360 -------------------------------------------------------------------------------------------------- */
362 if (meter && (_meter_point == MeterInput)) {
363 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
366 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
367 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
369 mute_declick_applied = true;
372 if ((_meter_point == MeterInput) && co) {
374 solo_audible = dsg > 0;
375 mute_audible = dmg > 0;// || !_mute_affects_pre_fader;
377 if ( // muted by solo of another track
381 // muted by mute of this track
385 // rec-enabled but not s/w monitoring
387 // TODO: this is probably wrong
389 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
393 co->silence (nframes, offset);
397 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
402 /* -----------------------------------------------------------------------------------------------------
404 -------------------------------------------------------------------------------------------------- */
406 if (_denormal_protection || Config->get_denormal_protection()) {
408 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
409 Sample* const sp = i->data();
411 for (nframes_t nx = offset; nx < nframes + offset; ++nx) {
417 /* ----------------------------------------------------------------------------------------------------
419 -------------------------------------------------------------------------------------------------- */
421 if (with_processors) {
422 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
424 if (mute_gain > 0 || !_mute_affects_pre_fader) {
425 for (i = _processors.begin(); i != _processors.end(); ++i) {
426 switch ((*i)->placement()) {
428 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
431 post_fader_work = true;
436 for (i = _processors.begin(); i != _processors.end(); ++i) {
437 switch ((*i)->placement()) {
439 (*i)->silence (nframes, offset);
442 post_fader_work = true;
450 // This really should already be true...
451 bufs.set_count(pre_fader_streams());
453 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader) {
454 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
456 mute_declick_applied = true;
459 /* ----------------------------------------------------------------------------------------------------
460 PRE-FADER METERING & MONITORING
461 -------------------------------------------------------------------------------------------------- */
463 if (meter && (_meter_point == MeterPreFader)) {
464 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
468 if ((_meter_point == MeterPreFader) && co) {
470 solo_audible = dsg > 0;
471 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
473 if ( // muted by solo of another track
477 // muted by mute of this track
481 // rec-enabled but not s/w monitoring
483 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
487 co->silence (nframes, offset);
491 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
495 /* ----------------------------------------------------------------------------------------------------
497 -------------------------------------------------------------------------------------------------- */
499 /* if not recording or recording and requiring any monitor signal, then apply gain */
501 if ( // not recording
503 !(record_enabled() && _session.actively_recording()) ||
507 // AND software monitoring required
509 Config->get_monitoring_model() == SoftwareMonitoring) {
511 if (apply_gain_automation) {
514 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
515 Sample* const sp = i->data();
517 for (nframes_t nx = 0; nx < nframes; ++nx) {
522 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
523 Sample* const sp = i->data();
525 for (nframes_t nx = 0; nx < nframes; ++nx) {
531 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
532 _effective_gain = gab[nframes-1];
537 /* manual (scalar) gain */
541 Amp::run_in_place (bufs, nframes, _gain, dg, _phase_invert);
544 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
546 /* no need to interpolate current gain value,
547 but its non-unity, so apply it. if the gain
548 is zero, do nothing because we'll ship silence
560 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
561 Sample* const sp = i->data();
562 apply_gain_to_buffer(sp,nframes,this_gain);
565 } else if (_gain == 0) {
566 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
574 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
578 /* ----------------------------------------------------------------------------------------------------
580 -------------------------------------------------------------------------------------------------- */
582 /* note that post_fader_work cannot be true unless with_processors was also true, so don't test both */
584 if (post_fader_work) {
586 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
588 if (mute_gain > 0 || !_mute_affects_post_fader) {
589 for (i = _processors.begin(); i != _processors.end(); ++i) {
590 switch ((*i)->placement()) {
594 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
599 for (i = _processors.begin(); i != _processors.end(); ++i) {
600 switch ((*i)->placement()) {
604 (*i)->silence (nframes, offset);
612 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_control_outs) {
613 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
615 mute_declick_applied = true;
618 /* ----------------------------------------------------------------------------------------------------
620 -------------------------------------------------------------------------------------------------- */
622 if ((_meter_point == MeterPostFader) && co) {
624 solo_audible = solo_gain > 0;
625 mute_audible = dmg > 0 || !_mute_affects_control_outs;
627 if ( // silent anyway
629 (_gain == 0 && !apply_gain_automation) ||
631 // muted by solo of another track
635 // muted by mute of this track
639 // recording but not s/w monitoring
641 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
645 co->silence (nframes, offset);
649 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
653 /* ----------------------------------------------------------------------
655 ----------------------------------------------------------------------*/
657 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
658 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
660 mute_declick_applied = true;
663 /* ----------------------------------------------------------------------------------------------------
665 -------------------------------------------------------------------------------------------------- */
667 solo_audible = dsg > 0;
668 mute_audible = dmg > 0 || !_mute_affects_main_outs;
670 if (n_outputs().get(_default_type) == 0) {
674 } else if (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording())) {
676 IO::silence (nframes, offset);
680 if ( // silent anyway
682 (_gain == 0 && !apply_gain_automation) ||
684 // muted by solo of another track, but not using control outs for solo
686 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
688 // muted by mute of this track
694 /* don't use Route::silence() here, because that causes
695 all outputs (sends, port processors, etc. to be silent).
698 if (_meter_point == MeterPostFader) {
699 peak_meter().reset();
702 IO::silence (nframes, offset);
706 deliver_output(bufs, start_frame, end_frame, nframes, offset);
712 /* ----------------------------------------------------------------------------------------------------
714 -------------------------------------------------------------------------------------------------- */
716 if (meter && (_meter_point == MeterPostFader)) {
717 if ((_gain == 0 && !apply_gain_automation) || dmg == 0) {
720 _meter->run_in_place(output_buffers(), start_frame, end_frame, nframes, offset);
726 Route::n_process_buffers ()
728 return max (n_inputs(), processor_max_outs);
732 Route::passthru (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter_first)
734 BufferSet& bufs = _session.get_scratch_buffers(n_process_buffers());
738 collect_input (bufs, nframes, offset);
741 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
745 process_output_buffers (bufs, start_frame, end_frame, nframes, offset, true, declick, meter_first);
749 Route::passthru_silence (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter)
751 process_output_buffers (_session.get_silent_buffers (n_process_buffers()), start_frame, end_frame, nframes, offset, true, declick, meter);
755 Route::set_solo (bool yn, void *src)
761 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
762 _mix_group->apply (&Route::set_solo, yn, _mix_group);
768 solo_changed (src); /* EMIT SIGNAL */
769 _solo_control->Changed (); /* EMIT SIGNAL */
774 Route::set_solo_mute (bool yn)
776 Glib::Mutex::Lock lm (declick_lock);
778 /* Called by Session in response to another Route being soloed.
781 desired_solo_gain = (yn?0.0:1.0);
785 Route::set_solo_safe (bool yn, void *src)
787 if (_solo_safe != yn) {
789 solo_safe_changed (src); /* EMIT SIGNAL */
794 Route::set_mute (bool yn, void *src)
797 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
798 _mix_group->apply (&Route::set_mute, yn, _mix_group);
804 mute_changed (src); /* EMIT SIGNAL */
806 _mute_control->Changed (); /* EMIT SIGNAL */
808 Glib::Mutex::Lock lm (declick_lock);
809 desired_mute_gain = (yn?0.0f:1.0f);
814 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
816 ChanCount old_pmo = processor_max_outs;
818 if (!_session.engine().connected()) {
823 Glib::RWLock::WriterLock lm (_processor_lock);
825 boost::shared_ptr<PluginInsert> pi;
826 boost::shared_ptr<PortInsert> porti;
828 //processor->set_default_type(_default_type);
830 _processors.push_back (processor);
832 if (_reset_processor_counts (err)) {
833 _processors.pop_back ();
834 _reset_processor_counts (0); // it worked before we tried to add it ...
838 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
840 if (pi->natural_input_streams() == ChanCount::ZERO) {
841 /* generator plugin */
842 _have_internal_generator = true;
847 _processors.push_back (processor);
849 // Set up processor list channels. This will set processor->[input|output]_streams(),
850 // configure redirect ports properly, etc.
851 if (_reset_processor_counts (err)) {
852 _processors.pop_back ();
853 _reset_processor_counts (0); // it worked before we tried to add it ...
857 // Ensure peak vector sizes before the plugin is activated
859 ChanCount potential_max_streams;
861 potential_max_streams.set (DataType::AUDIO, max (processor->input_streams().n_audio(),
862 processor->output_streams().n_audio()));
863 potential_max_streams.set (DataType::MIDI, max (processor->input_streams().n_midi(),
864 processor->output_streams().n_midi()));
866 _meter->configure_io (potential_max_streams, potential_max_streams);
868 processor->activate ();
869 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
874 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
878 processors_changed (); /* EMIT SIGNAL */
884 Route::add_processors (const ProcessorList& others, ProcessorStreams* err)
886 ChanCount old_pmo = processor_max_outs;
888 if (!_session.engine().connected()) {
893 Glib::RWLock::WriterLock lm (_processor_lock);
895 ProcessorList::iterator existing_end = _processors.end();
898 ChanCount potential_max_streams;
900 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
902 boost::shared_ptr<PluginInsert> pi;
904 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
907 ChanCount m = max(pi->input_streams(), pi->output_streams());
908 if (m > potential_max_streams)
909 potential_max_streams = m;
912 // Ensure peak vector sizes before the plugin is activated
913 _meter->configure_io (potential_max_streams, potential_max_streams);
915 _processors.push_back (*i);
917 if (_reset_processor_counts (err)) {
919 _processors.erase (existing_end, _processors.end());
920 _reset_processor_counts (0); // it worked before we tried to add it ...
925 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
931 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
935 processors_changed (); /* EMIT SIGNAL */
939 /** Turn off all processors with a given placement
940 * @param p Placement of processors to disable
944 Route::disable_processors (Placement p)
946 Glib::RWLock::ReaderLock lm (_processor_lock);
948 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
949 if ((*i)->placement() == p) {
950 (*i)->set_active (false);
954 _session.set_dirty ();
957 /** Turn off all redirects
961 Route::disable_processors ()
963 Glib::RWLock::ReaderLock lm (_processor_lock);
965 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
966 (*i)->set_active (false);
969 _session.set_dirty ();
972 /** Turn off all redirects with a given placement
973 * @param p Placement of redirects to disable
977 Route::disable_plugins (Placement p)
979 Glib::RWLock::ReaderLock lm (_processor_lock);
981 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
982 if (boost::dynamic_pointer_cast<PluginInsert> (*i) && (*i)->placement() == p) {
983 (*i)->set_active (false);
987 _session.set_dirty ();
990 /** Turn off all plugins
994 Route::disable_plugins ()
996 Glib::RWLock::ReaderLock lm (_processor_lock);
998 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
999 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1000 (*i)->set_active (false);
1004 _session.set_dirty ();
1009 Route::ab_plugins (bool forward)
1011 Glib::RWLock::ReaderLock lm (_processor_lock);
1015 /* forward = turn off all active redirects, and mark them so that the next time
1016 we go the other way, we will revert them
1019 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1020 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1024 if ((*i)->active()) {
1025 (*i)->set_active (false);
1026 (*i)->set_next_ab_is_active (true);
1028 (*i)->set_next_ab_is_active (false);
1034 /* backward = if the redirect was marked to go active on the next ab, do so */
1036 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1038 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1042 if ((*i)->get_next_ab_is_active()) {
1043 (*i)->set_active (true);
1045 (*i)->set_active (false);
1050 _session.set_dirty ();
1054 /* Figure out the streams that will feed into PreFader */
1056 Route::pre_fader_streams() const
1058 boost::shared_ptr<Processor> processor;
1060 // Find the last pre-fader redirect
1061 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1062 if ((*i)->placement() == PreFader) {
1068 return processor->output_streams();
1075 /** Remove processors with a given placement.
1076 * @param p Placement of processors to remove.
1079 Route::clear_processors (Placement p)
1081 const ChanCount old_pmo = processor_max_outs;
1083 if (!_session.engine().connected()) {
1088 Glib::RWLock::WriterLock lm (_processor_lock);
1089 ProcessorList new_list;
1091 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1092 if ((*i)->placement() == p) {
1093 /* it's the placement we want to get rid of */
1094 (*i)->drop_references ();
1096 /* it's a different placement, so keep it */
1097 new_list.push_back (*i);
1101 _processors = new_list;
1104 /* FIXME: can't see how this test can ever fire */
1105 if (processor_max_outs != old_pmo) {
1109 processor_max_outs.reset();
1110 _have_internal_generator = false;
1111 processors_changed (); /* EMIT SIGNAL */
1115 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1117 ChanCount old_pmo = processor_max_outs;
1119 if (!_session.engine().connected()) {
1123 processor_max_outs.reset();
1126 Glib::RWLock::WriterLock lm (_processor_lock);
1127 ProcessorList::iterator i;
1128 bool removed = false;
1130 for (i = _processors.begin(); i != _processors.end(); ++i) {
1131 if (*i == processor) {
1133 ProcessorList::iterator tmp;
1135 /* move along, see failure case for reset_processor_counts()
1136 where we may need to reprocessor the processor.
1142 /* stop redirects that send signals to JACK ports
1143 from causing noise as a result of no longer being
1147 boost::shared_ptr<IOProcessor> redirect;
1149 if ((redirect = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1150 redirect->io()->disconnect_inputs (this);
1151 redirect->io()->disconnect_outputs (this);
1154 _processors.erase (i);
1169 if (_reset_processor_counts (err)) {
1170 /* get back to where we where */
1171 _processors.insert (i, processor);
1172 /* we know this will work, because it worked before :) */
1173 _reset_processor_counts (0);
1177 _have_internal_generator = false;
1179 for (i = _processors.begin(); i != _processors.end(); ++i) {
1180 boost::shared_ptr<PluginInsert> pi;
1182 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1183 if (pi->is_generator()) {
1184 _have_internal_generator = true;
1191 if (old_pmo != processor_max_outs) {
1195 processor->drop_references ();
1197 processors_changed (); /* EMIT SIGNAL */
1202 Route::reset_processor_counts (ProcessorStreams* err)
1204 Glib::RWLock::WriterLock lm (_processor_lock);
1205 return _reset_processor_counts (err);
1210 Route::_reset_processor_counts (ProcessorStreams* err)
1212 ProcessorList::iterator r;
1213 uint32_t insert_cnt = 0;
1214 uint32_t send_cnt = 0;
1215 map<Placement,list<ProcessorCount> > proc_map;
1216 ProcessorList::iterator prev;
1217 ChanCount initial_streams = n_inputs ();
1218 ChanCount previous_initial_streams = n_inputs ();
1220 uint32_t max_audio = 0;
1221 uint32_t max_midi = 0;
1223 processor_max_outs.reset ();
1225 /* Step 1: build a map that links each insert to an in/out channel count
1227 Divide inserts up by placement so we get the signal flow
1228 properly modelled. we need to do this because the _processors
1229 list is not sorted by placement, and because other reasons may
1230 exist now or in the future for this separate treatment.
1233 /* ... but it should/will be... */
1235 for (r = _processors.begin(); r != _processors.end(); ++r) {
1237 boost::shared_ptr<PluginInsert> plugin_insert;
1238 boost::shared_ptr<PortInsert> port_insert;
1240 if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert>(*r)) != 0) {
1243 proc_map[(*r)->placement()].push_back (ProcessorCount (*r));
1245 /* reset plugin counts back to one for now so
1246 that we have a predictable, controlled
1247 state to try to configure.
1250 plugin_insert->set_count (1);
1252 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert>(*r)) != 0) {
1255 proc_map[(*r)->placement()].push_back (ProcessorCount (*r));
1257 } else if (boost::dynamic_pointer_cast<Send> (*r) != 0) {
1262 if (insert_cnt == 0) {
1271 /* Now process each placement in order, checking to see if we
1272 can really do what has been requested.
1277 if (check_some_processor_counts (proc_map[PreFader], n_inputs (), err)) {
1281 if (!proc_map[PreFader].empty()) {
1282 previous_initial_streams = n_inputs ();
1283 for (list<ProcessorCount>::iterator i = proc_map[PreFader].begin(); i != proc_map[PreFader].end(); i++) {
1284 if (i->processor->can_support_io_configuration (previous_initial_streams, initial_streams) < 0) {
1287 previous_initial_streams = initial_streams;
1293 if (check_some_processor_counts (proc_map[PostFader], initial_streams, err)) {
1297 if (!proc_map[PostFader].empty()) {
1298 for (list<ProcessorCount>::iterator i = proc_map[PostFader].begin(); i != proc_map[PostFader].end(); i++) {
1299 if (i->processor->can_support_io_configuration (previous_initial_streams, initial_streams) < 0) {
1302 previous_initial_streams = initial_streams;
1306 /* OK, everything can be set up correctly, so lets do it */
1308 apply_some_processor_counts (proc_map[PreFader]);
1309 apply_some_processor_counts (proc_map[PostFader]);
1311 /* recompute max outs of any processor */
1317 processor_max_outs.reset ();
1318 prev = _processors.end();
1320 for (r = _processors.begin(); r != _processors.end(); prev = r, ++r) {
1321 boost::shared_ptr<Send> s;
1323 if ((s = boost::dynamic_pointer_cast<Send> (*r)) != 0) {
1324 if (r == _processors.begin()) {
1325 s->expect_inputs (n_inputs());
1327 s->expect_inputs ((*prev)->output_streams());
1332 /* don't pay any attention to send output configuration, since it doesn't
1336 max_audio = max ((*r)->output_streams ().n_audio(), max_audio);
1337 max_midi = max ((*r)->output_streams ().n_midi(), max_midi);
1341 processor_max_outs.set (DataType::AUDIO, max_audio);
1342 processor_max_outs.set (DataType::MIDI, max_midi);
1348 for (r = _processors.begin(); r != _processors.end(); ++r) {
1349 max_audio = max ((*r)->output_streams ().n_audio(), max_audio);
1350 max_midi = max ((*r)->output_streams ().n_midi(), max_midi);
1353 processor_max_outs.set (DataType::AUDIO, max_audio);
1354 processor_max_outs.set (DataType::MIDI, max_midi);
1360 Route::apply_some_processor_counts (list<ProcessorCount>& iclist)
1362 list<ProcessorCount>::iterator i;
1364 for (i = iclist.begin(); i != iclist.end(); ++i) {
1366 ProcessorCount& pc (*i);
1368 cerr << "now applying for " << (*i).processor->name() << " in = " << pc.in.n_audio() << " out = " << pc.out.n_audio() << endl;
1370 if (pc.processor->configure_io (pc.in, pc.out)) {
1374 /* make sure that however many we have, they are all active */
1376 pc.processor->activate ();
1382 /** Returns whether \a iclist can be configured and run starting with
1383 * \a required_inputs at the first processor's inputs.
1384 * If false is returned, \a iclist can not be run with \a required_inputs, and \a err is set.
1385 * Otherwise, \a err is set to the output of the list.
1388 Route::check_some_processor_counts (list<ProcessorCount>& iclist, ChanCount required_inputs, ProcessorStreams* err)
1390 list<ProcessorCount>::iterator i;
1395 err->count = required_inputs;
1398 for (i = iclist.begin(); i != iclist.end(); ++i, ++index) {
1400 cerr << "Checking whether " << (*i).processor->name() << " can support " << required_inputs.n_audio() << " inputs\n";
1402 if (!(*i).processor->can_support_io_configuration (required_inputs, (*i).out)) {
1405 err->count = required_inputs;
1410 (*i).in = required_inputs;
1411 required_inputs = (*i).out;
1418 Route::copy_processors (const Route& other, Placement placement, ProcessorStreams* err)
1420 ChanCount old_pmo = processor_max_outs;
1422 ProcessorList to_be_deleted;
1425 Glib::RWLock::WriterLock lm (_processor_lock);
1426 ProcessorList::iterator tmp;
1427 ProcessorList the_copy;
1429 the_copy = _processors;
1431 /* remove all relevant processors */
1433 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ) {
1437 if ((*i)->placement() == placement) {
1438 to_be_deleted.push_back (*i);
1439 _processors.erase (i);
1445 /* now copy the relevant ones from "other" */
1447 for (ProcessorList::const_iterator i = other._processors.begin(); i != other._processors.end(); ++i) {
1448 if ((*i)->placement() == placement) {
1449 _processors.push_back (IOProcessor::clone (*i));
1453 /* reset plugin stream handling */
1455 if (_reset_processor_counts (err)) {
1457 /* FAILED COPY ATTEMPT: we have to restore order */
1459 /* delete all cloned processors */
1461 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ) {
1466 if ((*i)->placement() == placement) {
1467 _processors.erase (i);
1473 /* restore the natural order */
1475 _processors = the_copy;
1476 processor_max_outs = old_pmo;
1478 /* we failed, even though things are OK again */
1484 /* SUCCESSFUL COPY ATTEMPT: delete the processors we removed pre-copy */
1485 to_be_deleted.clear ();
1490 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
1494 processors_changed (); /* EMIT SIGNAL */
1499 Route::all_processors_flip ()
1501 Glib::RWLock::ReaderLock lm (_processor_lock);
1503 if (_processors.empty()) {
1507 bool first_is_on = _processors.front()->active();
1509 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1510 (*i)->set_active (!first_is_on);
1513 _session.set_dirty ();
1516 /** Set all processors with a given placement to a given active state.
1517 * @param p Placement of processors to change.
1518 * @param state New active state for those processors.
1521 Route::all_processors_active (Placement p, bool state)
1523 Glib::RWLock::ReaderLock lm (_processor_lock);
1525 if (_processors.empty()) {
1529 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1530 if ((*i)->placement() == p) {
1531 (*i)->set_active (state);
1535 _session.set_dirty ();
1538 struct ProcessorSorter {
1539 bool operator() (boost::shared_ptr<const Processor> a, boost::shared_ptr<const Processor> b) {
1540 return a->sort_key() < b->sort_key();
1545 Route::sort_processors (ProcessorStreams* err)
1548 ProcessorSorter comparator;
1549 Glib::RWLock::WriterLock lm (_processor_lock);
1550 ChanCount old_pmo = processor_max_outs;
1552 /* the sweet power of C++ ... */
1554 ProcessorList as_it_was_before = _processors;
1556 _processors.sort (comparator);
1558 if (_reset_processor_counts (err)) {
1559 _processors = as_it_was_before;
1560 processor_max_outs = old_pmo;
1566 processors_changed (); /* EMIT SIGNAL */
1578 Route::get_template()
1580 return state(false);
1584 Route::state(bool full_state)
1586 XMLNode *node = new XMLNode("Route");
1587 ProcessorList::iterator i;
1591 node->add_property("flags", enum_2_string (_flags));
1594 node->add_property("default-type", _default_type.to_string());
1596 node->add_property("active", _active?"yes":"no");
1597 node->add_property("muted", _muted?"yes":"no");
1598 node->add_property("soloed", _soloed?"yes":"no");
1599 node->add_property("phase-invert", _phase_invert?"yes":"no");
1600 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1601 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1602 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1603 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1604 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1607 node->add_property("edit-group", _edit_group->name());
1610 node->add_property("mix-group", _mix_group->name());
1613 string order_string;
1614 OrderKeys::iterator x = order_keys.begin();
1616 while (x != order_keys.end()) {
1617 order_string += string ((*x).first);
1618 order_string += '=';
1619 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1620 order_string += buf;
1624 if (x == order_keys.end()) {
1628 order_string += ':';
1630 node->add_property ("order-keys", order_string);
1632 node->add_child_nocopy (IO::state (full_state));
1633 node->add_child_nocopy (_solo_control->get_state ());
1634 node->add_child_nocopy (_mute_control->get_state ());
1636 XMLNode* remote_control_node = new XMLNode (X_("remote_control"));
1637 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1638 remote_control_node->add_property (X_("id"), buf);
1639 node->add_child_nocopy (*remote_control_node);
1641 if (_control_outs) {
1642 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
1643 cnode->add_child_nocopy (_control_outs->state (full_state));
1644 node->add_child_nocopy (*cnode);
1647 if (_comment.length()) {
1648 XMLNode *cmt = node->add_child ("Comment");
1649 cmt->add_content (_comment);
1652 for (i = _processors.begin(); i != _processors.end(); ++i) {
1653 node->add_child_nocopy((*i)->state (full_state));
1657 node->add_child_copy (*_extra_xml);
1664 Route::get_processor_state ()
1666 XMLNode* root = new XMLNode (X_("redirects"));
1667 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1668 root->add_child_nocopy ((*i)->state (true));
1675 Route::set_processor_state (const XMLNode& root)
1677 if (root.name() != X_("redirects")) {
1683 XMLNodeConstIterator iter;
1684 XMLNodeConstIterator niter;
1685 Glib::RWLock::ReaderLock lm (_processor_lock);
1687 nlist = root.children();
1689 for (iter = nlist.begin(); iter != nlist.end(); ++iter){
1691 /* iter now points to a IOProcessor state node */
1693 nnlist = (*iter)->children ();
1695 for (niter = nnlist.begin(); niter != nnlist.end(); ++niter) {
1697 /* find the IO child node, since it contains the ID we need */
1699 /* XXX OOP encapsulation violation, ugh */
1701 if ((*niter)->name() == IO::state_node_name) {
1703 XMLProperty* prop = (*niter)->property (X_("id"));
1706 warning << _("IOProcessor node has no ID, ignored") << endmsg;
1710 ID id = prop->value ();
1712 /* now look for a processor with that ID */
1714 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1715 if ((*i)->id() == id) {
1716 (*i)->set_state (**iter);
1732 Route::set_deferred_state ()
1735 XMLNodeConstIterator niter;
1737 if (!deferred_state) {
1741 nlist = deferred_state->children();
1743 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1744 add_processor_from_xml (**niter);
1747 delete deferred_state;
1752 Route::add_processor_from_xml (const XMLNode& node)
1754 const XMLProperty *prop;
1756 // legacy sessions use a different node name for sends
1757 if (node.name() == "Send") {
1760 boost::shared_ptr<Send> send (new Send (_session, node));
1761 add_processor (send);
1764 catch (failed_constructor &err) {
1765 error << _("Send construction failed") << endmsg;
1769 // use "Processor" in XML?
1770 } else if (node.name() == "Processor") {
1773 if ((prop = node.property ("type")) != 0) {
1775 boost::shared_ptr<Processor> processor;
1776 bool have_insert = false;
1778 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1779 prop->value() == "lv2" ||
1780 prop->value() == "vst" ||
1781 prop->value() == "audiounit") {
1783 processor.reset (new PluginInsert(_session, node));
1786 } else if (prop->value() == "port") {
1788 processor.reset (new PortInsert (_session, node));
1790 } else if (prop->value() == "send") {
1792 processor.reset (new Send (_session, node));
1797 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
1800 add_processor (processor);
1803 error << _("Processor XML node has no type property") << endmsg;
1807 catch (failed_constructor &err) {
1808 warning << _("processor could not be created. Ignored.") << endmsg;
1815 Route::set_state (const XMLNode& node)
1817 return _set_state (node, true);
1821 Route::_set_state (const XMLNode& node, bool call_base)
1824 XMLNodeConstIterator niter;
1826 XMLPropertyList plist;
1827 const XMLProperty *prop;
1829 if (node.name() != "Route"){
1830 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1834 if ((prop = node.property (X_("flags"))) != 0) {
1835 _flags = Flag (string_2_enum (prop->value(), _flags));
1840 if ((prop = node.property (X_("default-type"))) != 0) {
1841 _default_type = DataType(prop->value());
1842 assert(_default_type != DataType::NIL);
1845 if ((prop = node.property (X_("phase-invert"))) != 0) {
1846 set_phase_invert (prop->value()=="yes"?true:false, this);
1849 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1850 set_denormal_protection (prop->value()=="yes"?true:false, this);
1854 if ((prop = node.property (X_("active"))) != 0) {
1855 set_active (prop->value() == "yes");
1858 if ((prop = node.property (X_("muted"))) != 0) {
1859 bool yn = prop->value()=="yes"?true:false;
1861 /* force reset of mute status */
1865 mute_gain = desired_mute_gain;
1868 if ((prop = node.property (X_("soloed"))) != 0) {
1869 bool yn = prop->value()=="yes"?true:false;
1871 /* force reset of solo status */
1874 set_solo (yn, this);
1875 solo_gain = desired_solo_gain;
1878 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
1879 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
1882 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
1883 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
1886 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
1887 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
1890 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
1891 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
1894 if ((prop = node.property (X_("edit-group"))) != 0) {
1895 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
1896 if(edit_group == 0) {
1897 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1899 set_edit_group(edit_group, this);
1903 if ((prop = node.property (X_("order-keys"))) != 0) {
1907 string::size_type colon, equal;
1908 string remaining = prop->value();
1910 while (remaining.length()) {
1912 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1913 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1916 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1917 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1920 set_order_key (remaining.substr (0, equal).c_str(), n);
1924 colon = remaining.find_first_of (':');
1926 if (colon != string::npos) {
1927 remaining = remaining.substr (colon+1);
1934 nlist = node.children();
1936 if (deferred_state) {
1937 delete deferred_state;
1940 deferred_state = new XMLNode(X_("deferred state"));
1942 /* set parent class properties before anything else */
1944 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1948 if (child->name() == IO::state_node_name && call_base) {
1950 IO::set_state (*child);
1955 XMLNodeList processor_nodes;
1957 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1961 if (child->name() == X_("Send") || child->name() == X_("Processor")) {
1962 processor_nodes.push_back(child);
1967 _set_processor_states(processor_nodes);
1970 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1972 // All processors have been applied already
1974 if (child->name() == X_("Automation")) {
1976 if ((prop = child->property (X_("path"))) != 0) {
1977 load_automation (prop->value());
1980 } else if (child->name() == X_("ControlOuts")) {
1982 string coutname = _name;
1983 coutname += _("[control]");
1985 _control_outs = new IO (_session, coutname);
1986 _control_outs->set_state (**(child->children().begin()));
1988 } else if (child->name() == X_("Comment")) {
1990 /* XXX this is a terrible API design in libxml++ */
1992 XMLNode *cmt = *(child->children().begin());
1993 _comment = cmt->content();
1995 } else if (child->name() == X_("extra")) {
1997 _extra_xml = new XMLNode (*child);
1999 } else if (child->name() == X_("controllable") && (prop = child->property("name")) != 0) {
2001 if (prop->value() == "solo") {
2002 _solo_control->set_state (*child);
2003 _session.add_controllable (_solo_control);
2005 else if (prop->value() == "mute") {
2006 _mute_control->set_state (*child);
2007 _session.add_controllable (_mute_control);
2010 else if (child->name() == X_("remote_control")) {
2011 if ((prop = child->property (X_("id"))) != 0) {
2013 sscanf (prop->value().c_str(), "%d", &x);
2014 set_remote_control_id (x);
2019 if ((prop = node.property (X_("mix-group"))) != 0) {
2020 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
2021 if (mix_group == 0) {
2022 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2024 set_mix_group(mix_group, this);
2032 Route::_set_processor_states(const XMLNodeList &nlist)
2034 XMLNodeConstIterator niter;
2037 ProcessorList::iterator i, o;
2039 // Iterate through existing processors, remove those which are not in the state list
2040 for (i = _processors.begin(); i != _processors.end(); ) {
2041 ProcessorList::iterator tmp = i;
2044 bool processorInStateList = false;
2046 (*i)->id().print (buf, sizeof (buf));
2049 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2051 // legacy sessions (IOProcessor as a child of Processor, both is-a IO)
2052 if (strncmp(buf,(*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2053 processorInStateList = true;
2055 } else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2056 processorInStateList = true;
2061 if (!processorInStateList) {
2062 remove_processor (*i);
2070 // Iterate through state list and make sure all processors are on the track and in the correct order,
2071 // set the state of existing processors according to the new state on the same go
2072 i = _processors.begin();
2073 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
2075 // Check whether the next processor in the list
2078 while (o != _processors.end()) {
2079 (*o)->id().print (buf, sizeof (buf));
2080 if ( strncmp(buf, (*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2082 else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2088 if (o == _processors.end()) {
2089 // If the processor (*niter) is not on the route, we need to create it
2090 // and move it to the correct location
2092 ProcessorList::iterator prev_last = _processors.end();
2093 --prev_last; // We need this to check whether adding succeeded
2095 add_processor_from_xml (**niter);
2097 ProcessorList::iterator last = _processors.end();
2100 if (prev_last == last) {
2101 cerr << "Could not fully restore state as some processors were not possible to create" << endl;
2106 boost::shared_ptr<Processor> tmp = (*last);
2107 // remove the processor from the wrong location
2108 _processors.erase(last);
2109 // processor the new processor at the current location
2110 _processors.insert(i, tmp);
2112 --i; // move pointer to the newly processored processor
2116 // We found the processor (*niter) on the route, first we must make sure the processor
2117 // is at the location provided in the XML state
2119 boost::shared_ptr<Processor> tmp = (*o);
2120 // remove the old copy
2121 _processors.erase(o);
2122 // processor the processor at the correct location
2123 _processors.insert(i, tmp);
2125 --i; // move pointer so it points to the right processor
2128 (*i)->set_state( (**niter) );
2131 processors_changed ();
2135 Route::curve_reallocate ()
2137 // _gain_automation_curve.finish_resize ();
2138 // _pan_automation_curve.finish_resize ();
2142 Route::silence (nframes_t nframes, nframes_t offset)
2146 IO::silence (nframes, offset);
2148 if (_control_outs) {
2149 _control_outs->silence (nframes, offset);
2153 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2156 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2157 boost::shared_ptr<PluginInsert> pi;
2158 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2159 // skip plugins, they don't need anything when we're not active
2163 (*i)->silence (nframes, offset);
2166 if (nframes == _session.get_block_size() && offset == 0) {
2176 Route::set_control_outs (const vector<string>& ports)
2178 Glib::Mutex::Lock lm (_control_outs_lock);
2179 vector<string>::const_iterator i;
2182 if (_control_outs) {
2183 delete _control_outs;
2187 if (is_control() || is_master()) {
2188 /* no control outs for these two special busses */
2192 if (ports.empty()) {
2196 string coutname = _name;
2197 coutname += _("[control]");
2199 _control_outs = new IO (_session, coutname);
2201 /* our control outs need as many outputs as we
2202 have audio outputs. we track the changes in ::output_change_handler().
2205 // XXX its stupid that we have to get this value twice
2207 limit = n_outputs().n_audio();
2209 if (_control_outs->ensure_io (ChanCount::ZERO, ChanCount (DataType::AUDIO, n_outputs().get (DataType::AUDIO)), true, this)) {
2213 /* now connect to the named ports */
2215 for (size_t n = 0; n < limit; ++n) {
2216 if (_control_outs->connect_output (_control_outs->output (n), ports[n % ports.size()], this)) {
2217 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
2226 Route::set_edit_group (RouteGroup *eg, void *src)
2229 if (eg == _edit_group) {
2234 _edit_group->remove (this);
2237 if ((_edit_group = eg) != 0) {
2238 _edit_group->add (this);
2241 _session.set_dirty ();
2242 edit_group_changed (src); /* EMIT SIGNAL */
2246 Route::drop_edit_group (void *src)
2249 _session.set_dirty ();
2250 edit_group_changed (src); /* EMIT SIGNAL */
2254 Route::set_mix_group (RouteGroup *mg, void *src)
2257 if (mg == _mix_group) {
2262 _mix_group->remove (this);
2265 if ((_mix_group = mg) != 0) {
2266 _mix_group->add (this);
2269 _session.set_dirty ();
2270 mix_group_changed (src); /* EMIT SIGNAL */
2274 Route::drop_mix_group (void *src)
2277 _session.set_dirty ();
2278 mix_group_changed (src); /* EMIT SIGNAL */
2282 Route::set_comment (string cmt, void *src)
2285 comment_changed (src);
2286 _session.set_dirty ();
2290 Route::feeds (boost::shared_ptr<Route> other)
2295 uint32_t no = self.n_outputs().n_total();
2296 uint32_t ni = other->n_inputs ().n_total();
2298 for (i = 0; i < no; ++i) {
2299 for (j = 0; j < ni; ++j) {
2300 if (self.output(i)->connected_to (other->input(j)->name())) {
2306 /* check IOProcessors which may also interconnect Routes */
2308 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2310 boost::shared_ptr<IOProcessor> redirect = boost::dynamic_pointer_cast<IOProcessor>(*r);
2315 // TODO: support internal redirects here
2317 no = redirect->io()->n_outputs().n_total();
2319 for (i = 0; i < no; ++i) {
2320 for (j = 0; j < ni; ++j) {
2321 if (redirect->io()->output(i)->connected_to (other->input (j)->name())) {
2328 /* check for control room outputs which may also interconnect Routes */
2330 if (_control_outs) {
2332 no = _control_outs->n_outputs().n_total();
2334 for (i = 0; i < no; ++i) {
2335 for (j = 0; j < ni; ++j) {
2336 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2347 Route::set_mute_config (mute_type t, bool onoff, void *src)
2351 _mute_affects_pre_fader = onoff;
2352 pre_fader_changed(src); /* EMIT SIGNAL */
2356 _mute_affects_post_fader = onoff;
2357 post_fader_changed(src); /* EMIT SIGNAL */
2361 _mute_affects_control_outs = onoff;
2362 control_outs_changed(src); /* EMIT SIGNAL */
2366 _mute_affects_main_outs = onoff;
2367 main_outs_changed(src); /* EMIT SIGNAL */
2373 Route::get_mute_config (mute_type t)
2379 onoff = _mute_affects_pre_fader;
2382 onoff = _mute_affects_post_fader;
2385 onoff = _mute_affects_control_outs;
2388 onoff = _mute_affects_main_outs;
2396 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_processors)
2398 nframes_t now = _session.transport_frame();
2401 Glib::RWLock::ReaderLock lm (_processor_lock);
2404 automation_snapshot (now, true);
2407 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2409 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2410 (*i)->deactivate ();
2414 (*i)->transport_stopped (now);
2418 IO::transport_stopped (now);
2420 _roll_delay = _initial_delay;
2424 Route::input_change_handler (IOChange change, void *ignored)
2426 if (change & ConfigurationChanged) {
2427 reset_processor_counts (0);
2432 Route::output_change_handler (IOChange change, void *ignored)
2434 if (change & ConfigurationChanged) {
2435 if (_control_outs) {
2436 _control_outs->ensure_io (ChanCount::ZERO, ChanCount(DataType::AUDIO, n_outputs().n_audio()), true, this);
2439 reset_processor_counts (0);
2444 Route::pans_required () const
2446 if (n_outputs().n_audio() < 2) {
2450 return max (n_inputs ().n_audio(), processor_max_outs.n_audio());
2454 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2455 bool session_state_changing, bool can_record, bool rec_monitors_input)
2457 if (n_outputs().n_total() == 0) {
2461 if (session_state_changing || !_active) {
2462 silence (nframes, offset);
2466 apply_gain_automation = false;
2468 if (n_inputs().n_total()) {
2469 passthru (start_frame, end_frame, nframes, offset, 0, false);
2471 silence (nframes, offset);
2478 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2480 if (_roll_delay > nframes) {
2482 _roll_delay -= nframes;
2483 silence (nframes, offset);
2484 /* transport frame is not legal for caller to use */
2487 } else if (_roll_delay > 0) {
2489 nframes -= _roll_delay;
2491 silence (_roll_delay, offset);
2493 offset += _roll_delay;
2494 transport_frame += _roll_delay;
2503 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2504 bool can_record, bool rec_monitors_input)
2507 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2509 // automation snapshot can also be called from the non-rt context
2510 // and it uses the processor list, so we take the lock out here
2511 automation_snapshot (_session.transport_frame(), false);
2515 if ((n_outputs().n_total() == 0 && _processors.empty()) || n_inputs().n_total() == 0 || !_active) {
2516 silence (nframes, offset);
2520 nframes_t unused = 0;
2522 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2528 apply_gain_automation = false;
2531 Glib::Mutex::Lock am (data().control_lock(), Glib::TRY_LOCK);
2533 if (am.locked() && _session.transport_rolling()) {
2535 if (_gain_control->alist()->automation_playback()) {
2536 apply_gain_automation = _gain_control->list()->curve().rt_safe_get_vector (
2537 start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2542 passthru (start_frame, end_frame, nframes, offset, declick, false);
2548 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2549 bool can_record, bool rec_monitors_input)
2551 silence (nframes, offset);
2556 Route::toggle_monitor_input ()
2558 for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2559 i->ensure_monitor_input( ! i->monitoring_input());
2564 Route::has_external_redirects () const
2566 // FIXME: what about sends?
2568 boost::shared_ptr<const PortInsert> pi;
2570 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2571 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2573 for (PortSet::const_iterator port = pi->io()->outputs().begin();
2574 port != pi->io()->outputs().end(); ++port) {
2576 string port_name = port->name();
2577 string client_name = port_name.substr (0, port_name.find(':'));
2579 /* only say "yes" if the redirect is actually in use */
2581 if (client_name != "ardour" && pi->active()) {
2592 Route::flush_processors ()
2594 /* XXX shouldn't really try to take this lock, since
2595 this is called from the RT audio thread.
2598 Glib::RWLock::ReaderLock lm (_processor_lock);
2600 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2601 (*i)->deactivate ();
2607 Route::set_meter_point (MeterPoint p, void *src)
2609 if (_meter_point != p) {
2611 meter_change (src); /* EMIT SIGNAL */
2612 _session.set_dirty ();
2617 Route::update_total_latency ()
2619 nframes_t old = _own_latency;
2621 if (_user_latency) {
2622 _own_latency = _user_latency;
2626 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2627 if ((*i)->active ()) {
2628 _own_latency += (*i)->signal_latency ();
2633 #undef DEBUG_LATENCY
2634 #ifdef DEBUG_LATENCY
2635 cerr << _name << ": internal redirect latency = " << _own_latency << endl;
2638 set_port_latency (_own_latency);
2640 if (!_user_latency) {
2641 /* this (virtual) function is used for pure Routes,
2642 not derived classes like AudioTrack. this means
2643 that the data processed here comes from an input
2644 port, not prerecorded material, and therefore we
2645 have to take into account any input latency.
2649 _own_latency += input_latency ();
2652 if (old != _own_latency) {
2653 signal_latency_changed (); /* EMIT SIGNAL */
2656 #ifdef DEBUG_LATENCY
2657 cerr << _name << ": input latency = " << input_latency() << " total = "
2658 << _own_latency << endl;
2661 return _own_latency;
2665 Route::set_user_latency (nframes_t nframes)
2667 Latent::set_user_latency (nframes);
2668 _session.update_latency_compensation (false, false);
2672 Route::set_latency_delay (nframes_t longest_session_latency)
2674 nframes_t old = _initial_delay;
2676 if (_own_latency < longest_session_latency) {
2677 _initial_delay = longest_session_latency - _own_latency;
2682 if (_initial_delay != old) {
2683 initial_delay_changed (); /* EMIT SIGNAL */
2686 if (_session.transport_stopped()) {
2687 _roll_delay = _initial_delay;
2692 Route::automation_snapshot (nframes_t now, bool force)
2694 if (!force && !should_snapshot(now)) {
2698 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2699 // IO::automation_snapshot (now, force); ?
2700 (*i)->automation_snapshot (now, force);
2704 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
2705 : Controllable (name), route (s), type(tp)
2711 Route::ToggleControllable::set_value (float val)
2713 bool bval = ((val >= 0.5f) ? true: false);
2717 route.set_mute (bval, this);
2720 route.set_solo (bval, this);
2728 Route::ToggleControllable::get_value (void) const
2734 val = route.muted() ? 1.0f : 0.0f;
2737 val = route.soloed() ? 1.0f : 0.0f;
2747 Route::set_block_size (nframes_t nframes)
2749 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2750 (*i)->set_block_size (nframes);
2755 Route::protect_automation ()
2757 Automatable::protect_automation();
2759 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
2760 (*i)->protect_automation();
2764 Route::set_pending_declick (int declick)
2767 /* this call is not allowed to turn off a pending declick unless "force" is true */
2769 _pending_declick = declick;
2771 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2773 _pending_declick = 0;