add implicit mute state to MuteMaster and use when a master of a mute control is...
[ardour.git] / libs / ardour / ardour / route.h
1 /*
2     Copyright (C) 2000-2002 Paul Davis
3
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.
8
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.
13
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.
17 */
18
19 #ifndef __ardour_route_h__
20 #define __ardour_route_h__
21
22 #include <cmath>
23 #include <cstring>
24 #include <list>
25 #include <map>
26 #include <set>
27 #include <string>
28
29 #include <boost/shared_ptr.hpp>
30 #include <boost/weak_ptr.hpp>
31 #include <boost/dynamic_bitset.hpp>
32 #include <boost/enable_shared_from_this.hpp>
33
34 #include <glibmm/threads.h>
35 #include "pbd/fastlog.h"
36 #include "pbd/xml++.h"
37 #include "pbd/undo.h"
38 #include "pbd/stateful.h"
39 #include "pbd/controllable.h"
40 #include "pbd/destructible.h"
41
42 #include "ardour/ardour.h"
43 #include "ardour/gain_control.h"
44 #include "ardour/instrument_info.h"
45 #include "ardour/io.h"
46 #include "ardour/io_vector.h"
47 #include "ardour/libardour_visibility.h"
48 #include "ardour/types.h"
49 #include "ardour/mute_master.h"
50 #include "ardour/route_group_member.h"
51 #include "ardour/stripable.h"
52 #include "ardour/graphnode.h"
53 #include "ardour/automatable.h"
54 #include "ardour/unknown_processor.h"
55
56 class RoutePinWindowProxy;
57
58 namespace ARDOUR {
59
60 class Amp;
61 class DelayLine;
62 class Delivery;
63 class IOProcessor;
64 class Panner;
65 class PannerShell;
66 class PortSet;
67 class Processor;
68 class PluginInsert;
69 class RouteGroup;
70 class Send;
71 class InternalReturn;
72 class MonitorProcessor;
73 class Pannable;
74 class CapturingProcessor;
75 class InternalSend;
76 class VCA;
77
78 class LIBARDOUR_API Route : public Stripable, public Automatable, public RouteGroupMember, public GraphNode, public boost::enable_shared_from_this<Route>
79 {
80 public:
81
82         typedef std::list<boost::shared_ptr<Processor> > ProcessorList;
83
84         enum Flag {
85                 Auditioner = 0x1,
86                 MasterOut = 0x2,
87                 MonitorOut = 0x4
88         };
89
90         Route (Session&, std::string name, Flag flags = Flag(0), DataType default_type = DataType::AUDIO);
91         virtual ~Route();
92
93         virtual int init ();
94
95         boost::shared_ptr<IO> input() const { return _input; }
96         boost::shared_ptr<IO> output() const { return _output; }
97         IOVector all_inputs () const;
98         IOVector all_outputs () const;
99
100         ChanCount n_inputs() const { return _input->n_ports(); }
101         ChanCount n_outputs() const { return _output->n_ports(); }
102
103         bool active() const { return _active; }
104         void set_active (bool yn, void *);
105
106         static std::string ensure_track_or_route_name(std::string, Session &);
107
108         std::string comment() { return _comment; }
109         void set_comment (std::string str, void *src);
110
111         bool set_name (const std::string& str);
112         static void set_name_in_state (XMLNode &, const std::string &, bool rename_playlist = true);
113
114         uint32_t order_key () const;
115         bool has_order_key () const;
116         void set_order_key (uint32_t);
117
118         bool is_auditioner() const { return _flags & Auditioner; }
119         bool is_master() const { return _flags & MasterOut; }
120         bool is_monitor() const { return _flags & MonitorOut; }
121
122         virtual MonitorState monitoring_state () const;
123         virtual MeterState metering_state () const;
124
125         /* these are the core of the API of a Route. see the protected sections as well */
126
127         virtual int roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
128                           int declick, bool& need_butler);
129
130         virtual int no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
131                              bool state_changing);
132
133         virtual int silent_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
134                                  bool& need_butler);
135
136         virtual bool can_record() { return false; }
137
138         virtual void set_record_enabled (bool /*yn*/, PBD::Controllable::GroupControlDisposition) {}
139         virtual bool record_enabled() const { return false; }
140         virtual void set_record_safe (bool /*yn*/, PBD::Controllable::GroupControlDisposition) {}
141         virtual bool record_safe () const {return false; }
142         virtual void nonrealtime_handle_transport_stopped (bool abort, bool did_locate, bool flush_processors);
143         virtual void realtime_handle_transport_stopped () {}
144         virtual void realtime_locate () {}
145         virtual void non_realtime_locate (framepos_t);
146         virtual void set_pending_declick (int);
147
148         /* end of vfunc-based API */
149
150         void shift (framepos_t, framecnt_t);
151
152         void set_gain (gain_t val, PBD::Controllable::GroupControlDisposition);
153         void inc_gain (gain_t delta);
154
155         void set_trim (gain_t val, PBD::Controllable::GroupControlDisposition);
156
157         void set_mute_points (MuteMaster::MutePoint);
158         MuteMaster::MutePoint mute_points () const;
159
160         bool muted () const;
161         void set_mute (bool yn, PBD::Controllable::GroupControlDisposition);
162
163         bool muted_by_others_soloing () const;
164         bool muted_by_others () const;
165
166         /* controls use set_solo() to modify this route's solo state
167          */
168
169         void set_solo (bool yn, PBD::Controllable::GroupControlDisposition group_override = PBD::Controllable::UseGroup);
170         bool soloed () const { return self_soloed () || soloed_by_others (); }
171         void clear_all_solo_state ();
172
173         bool soloed_by_others () const { return _soloed_by_others_upstream||_soloed_by_others_downstream; }
174         bool soloed_by_others_upstream () const { return _soloed_by_others_upstream; }
175         bool soloed_by_others_downstream () const { return _soloed_by_others_downstream; }
176         bool self_soloed () const { return _self_solo; }
177
178         void set_solo_isolated (bool yn, PBD::Controllable::GroupControlDisposition group_override = PBD::Controllable::UseGroup);
179         bool solo_isolated() const;
180
181         void set_solo_safe (bool yn, PBD::Controllable::GroupControlDisposition group_override = PBD::Controllable::UseGroup);
182         bool solo_safe() const;
183
184         void set_listen (bool yn, PBD::Controllable::GroupControlDisposition group_override = PBD::Controllable::UseGroup);
185         bool listening_via_monitor () const;
186         void enable_monitor_send ();
187
188         void set_phase_invert (uint32_t, bool yn);
189         void set_phase_invert (boost::dynamic_bitset<>);
190         bool phase_invert (uint32_t) const;
191         boost::dynamic_bitset<> phase_invert () const;
192
193         void set_denormal_protection (bool yn);
194         bool denormal_protection() const;
195
196         void         set_meter_point (MeterPoint, bool force = false);
197         bool         apply_processor_changes_rt ();
198         void         emit_pending_signals ();
199         MeterPoint   meter_point() const { return _pending_meter_point; }
200
201         void         set_meter_type (MeterType t) { _meter_type = t; }
202         MeterType    meter_type() const { return _meter_type; }
203
204         /* Processors */
205
206         boost::shared_ptr<Amp> amp() const  { return _amp; }
207         boost::shared_ptr<Amp> trim() const { return _trim; }
208         boost::shared_ptr<PeakMeter>       peak_meter()       { return _meter; }
209         boost::shared_ptr<const PeakMeter> peak_meter() const { return _meter; }
210         boost::shared_ptr<PeakMeter> shared_peak_meter() const { return _meter; }
211         boost::shared_ptr<DelayLine> delay_line() const  { return _delayline; }
212
213         void flush_processors ();
214
215         void foreach_processor (boost::function<void(boost::weak_ptr<Processor>)> method) {
216                 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
217                 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
218                         method (boost::weak_ptr<Processor> (*i));
219                 }
220         }
221
222         boost::shared_ptr<Processor> nth_processor (uint32_t n) {
223                 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
224                 ProcessorList::iterator i;
225                 for (i = _processors.begin(); i != _processors.end() && n; ++i, --n) {}
226                 if (i == _processors.end()) {
227                         return boost::shared_ptr<Processor> ();
228                 } else {
229                         return *i;
230                 }
231         }
232
233         boost::shared_ptr<Processor> processor_by_id (PBD::ID) const;
234
235         boost::shared_ptr<Processor> nth_plugin (uint32_t n) const;
236         boost::shared_ptr<Processor> nth_send (uint32_t n) const;
237
238         bool has_io_processor_named (const std::string&);
239         ChanCount max_processor_streams () const { return processor_max_streams; }
240
241         std::list<std::string> unknown_processors () const;
242
243         RoutePinWindowProxy * pinmgr_proxy () const { return _pinmgr_proxy; }
244         void set_pingmgr_proxy (RoutePinWindowProxy* wp) { _pinmgr_proxy = wp ; }
245
246         /* special processors */
247
248         boost::shared_ptr<InternalSend>     monitor_send() const { return _monitor_send; }
249         /** the signal processorat at end of the processing chain which produces output */
250         boost::shared_ptr<Delivery>         main_outs() const { return _main_outs; }
251         boost::shared_ptr<InternalReturn>   internal_return() const { return _intreturn; }
252         boost::shared_ptr<MonitorProcessor> monitor_control() const { return _monitor_control; }
253         boost::shared_ptr<Send>             internal_send_for (boost::shared_ptr<const Route> target) const;
254         void add_internal_return ();
255         void add_send_to_internal_return (InternalSend *);
256         void remove_send_from_internal_return (InternalSend *);
257         void listen_position_changed ();
258         boost::shared_ptr<CapturingProcessor> add_export_point(/* Add some argument for placement later */);
259
260         /** A record of the stream configuration at some point in the processor list.
261          * Used to return where and why an processor list configuration request failed.
262          */
263         struct ProcessorStreams {
264                 ProcessorStreams(size_t i=0, ChanCount c=ChanCount()) : index(i), count(c) {}
265
266                 uint32_t  index; ///< Index of processor where configuration failed
267                 ChanCount count; ///< Input requested of processor
268         };
269
270         int add_processor (boost::shared_ptr<Processor>, Placement placement, ProcessorStreams* err = 0, bool activation_allowed = true);
271         int add_processor_by_index (boost::shared_ptr<Processor>, int, ProcessorStreams* err = 0, bool activation_allowed = true);
272         int add_processor (boost::shared_ptr<Processor>, boost::shared_ptr<Processor>, ProcessorStreams* err = 0, bool activation_allowed = true);
273         int add_processors (const ProcessorList&, boost::shared_ptr<Processor>, ProcessorStreams* err = 0);
274         boost::shared_ptr<Processor> before_processor_for_placement (Placement);
275         boost::shared_ptr<Processor> before_processor_for_index (int);
276         bool processors_reorder_needs_configure (const ProcessorList& new_order);
277         /** remove plugin/processor
278          *
279          * @param proc processor to remove
280          * @param err error report (index where removal vailed, channel-count why it failed) may be nil
281          * @param need_process_lock if locking is required (set to true, unless called from RT context with lock)
282          * @returns 0 on success
283          */
284         int remove_processor (boost::shared_ptr<Processor> proc, ProcessorStreams* err = 0, bool need_process_lock = true);
285         /** replace plugin/processor with another
286          *
287          * @param old processor to remove
288          * @param sub processor to substitute the old one with
289          * @param err error report (index where removal vailed, channel-count why it failed) may be nil
290          * @returns 0 on success
291          */
292         int replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err = 0);
293         int remove_processors (const ProcessorList&, ProcessorStreams* err = 0);
294         int reorder_processors (const ProcessorList& new_order, ProcessorStreams* err = 0);
295         void disable_processors (Placement);
296         void disable_processors ();
297         void disable_plugins (Placement);
298         void disable_plugins ();
299         void ab_plugins (bool forward);
300         void clear_processors (Placement);
301         void all_visible_processors_active (bool);
302
303         bool strict_io () const { return _strict_io; }
304         bool set_strict_io (bool);
305         /** reset plugin-insert configuration to default, disable customizations.
306          *
307          * This is equivalent to calling
308          * @code
309          * customize_plugin_insert (proc, 0, unused)
310          * @endcode
311          *
312          * @param proc Processor to reset
313          * @returns true if successful
314          */
315         bool reset_plugin_insert (boost::shared_ptr<Processor> proc);
316         /** enable custom plugin-insert configuration
317          * @param proc Processor to customize
318          * @param count number of plugin instances to use (if zero, reset to default)
319          * @param outs output port customization
320          * @param sinks input pins for variable-I/O plugins
321          * @returns true if successful
322          */
323         bool customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks);
324         bool add_remove_sidechain (boost::shared_ptr<Processor> proc, bool);
325         bool plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs);
326
327         /* enable sidechain input for a given processor
328          *
329          * The sidechain itself is an IO port object with variable number of channels and configured independently.
330          * Adding/removing the port itself however requires reconfiguring the route and is hence
331          * not a plugin operation itself.
332          *
333          * @param proc the processor to add sidechain inputs to
334          * @returns true on success
335          */
336         bool add_sidechain (boost::shared_ptr<Processor> proc) { return add_remove_sidechain (proc, true); }
337         /* remove sidechain input from given processor
338          * @param proc the processor to remove the sidechain input from
339          * @returns true on success
340          */
341         bool remove_sidechain (boost::shared_ptr<Processor> proc) { return add_remove_sidechain (proc, false); }
342
343         framecnt_t set_private_port_latencies (bool playback) const;
344         void       set_public_port_latencies (framecnt_t, bool playback) const;
345
346         framecnt_t   update_signal_latency();
347         virtual void set_latency_compensation (framecnt_t);
348
349         void set_user_latency (framecnt_t);
350         framecnt_t initial_delay() const { return _initial_delay; }
351         framecnt_t signal_latency() const { return _signal_latency; }
352
353         PBD::Signal0<void>       active_changed;
354         PBD::Signal0<void>       denormal_protection_changed;
355         PBD::Signal0<void>       comment_changed;
356         PBD::Signal0<void>       mute_points_changed;
357
358         /** track numbers - assigned by session
359          * nubers > 0 indicate tracks (audio+midi)
360          * nubers < 0 indicate busses
361          * zero is reserved for unnumbered special busses.
362          * */
363         PBD::Signal0<void> track_number_changed;
364         int64_t track_number() const { return _track_number; }
365
366         void set_track_number(int64_t tn) {
367                 if (tn == _track_number) { return; }
368                 _track_number = tn;
369                 track_number_changed();
370                 PropertyChanged (ARDOUR::Properties::name);
371         }
372
373         enum PluginSetupOptions {
374                 None = 0x0,
375                 CanReplace = 0x1,
376                 MultiOut = 0x2,
377         };
378
379         static PBD::Signal3<int,boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, PluginSetupOptions > PluginSetup;
380
381         /** the processors have changed; the parameter indicates what changed */
382         PBD::Signal1<void,RouteProcessorChange> processors_changed;
383         PBD::Signal1<void,void*> record_enable_changed;
384         /** the metering point has changed */
385         PBD::Signal0<void>       meter_change;
386         PBD::Signal0<void>       signal_latency_changed;
387         PBD::Signal0<void>       initial_delay_changed;
388
389         /** Emitted with the process lock held */
390         PBD::Signal0<void>       io_changed;
391
392         /* gui's call this for their own purposes. */
393
394         PBD::Signal2<void,std::string,void*> gui_changed;
395
396         /* stateful */
397
398         XMLNode& get_state();
399         virtual int set_state (const XMLNode&, int version);
400         virtual XMLNode& get_template();
401
402         XMLNode& get_processor_state ();
403         virtual void set_processor_state (const XMLNode&);
404
405         int save_as_template (const std::string& path, const std::string& name);
406
407         PBD::Signal1<void,void*> SelectedChanged;
408
409         int add_aux_send (boost::shared_ptr<Route>, boost::shared_ptr<Processor>);
410         void remove_aux_or_listen (boost::shared_ptr<Route>);
411
412         /**
413          * return true if this route feeds the first argument via at least one
414          * (arbitrarily long) signal pathway.
415          */
416         bool feeds (boost::shared_ptr<Route>, bool* via_send_only = 0);
417
418         /**
419          * return true if this route feeds the first argument directly, via
420          * either its main outs or a send.  This is checked by the actual
421          * connections, rather than by what the graph is currently doing.
422          */
423         bool direct_feeds_according_to_reality (boost::shared_ptr<Route>, bool* via_send_only = 0);
424
425         /**
426          * return true if this route feeds the first argument directly, via
427          * either its main outs or a send, according to the graph that
428          * is currently being processed.
429          */
430         bool direct_feeds_according_to_graph (boost::shared_ptr<Route>, bool* via_send_only = 0);
431
432         bool feeds_according_to_graph (boost::shared_ptr<Route>);
433
434         struct FeedRecord {
435                 boost::weak_ptr<Route> r;
436                 bool sends_only;
437
438                 FeedRecord (boost::shared_ptr<Route> rp, bool sendsonly)
439                 : r (rp)
440                 , sends_only (sendsonly) {}
441         };
442
443         struct FeedRecordCompare {
444                 bool operator() (const FeedRecord& a, const FeedRecord& b) const {
445                         return a.r < b.r;
446                 }
447         };
448
449         typedef std::set<FeedRecord,FeedRecordCompare> FedBy;
450
451         const FedBy& fed_by() const { return _fed_by; }
452         void clear_fed_by ();
453         bool add_fed_by (boost::shared_ptr<Route>, bool sends_only);
454
455         /* Controls (not all directly owned by the Route) */
456
457         boost::shared_ptr<AutomationControl> get_control (const Evoral::Parameter& param);
458
459         class RouteAutomationControl : public AutomationControl {
460         public:
461                 RouteAutomationControl (const std::string& name,
462                                         AutomationType atype,
463                                         boost::shared_ptr<AutomationList> alist,
464                                         boost::shared_ptr<Route> route);
465         protected:
466                 friend class Route;
467
468                 void route_set_value (double val) {
469                         AutomationControl::set_value (val, Controllable::NoGroup);
470                 }
471
472                 boost::weak_ptr<Route> _route;
473         };
474
475         class BooleanRouteAutomationControl : public RouteAutomationControl {
476         public:
477                 BooleanRouteAutomationControl (const std::string& name,
478                                                AutomationType atype,
479                                                boost::shared_ptr<AutomationList> alist,
480                                                boost::shared_ptr<Route> route)
481                         : RouteAutomationControl (name, atype, alist, route) {}
482         protected:
483                 double get_masters_value_locked() const;
484
485         };
486
487         class GainControllable : public GainControl  {
488         public:
489                 GainControllable (Session& session,
490                                   AutomationType type,
491                                   boost::shared_ptr<Route> route);
492
493                 void set_value (double val, PBD::Controllable::GroupControlDisposition group_override) {
494                         boost::shared_ptr<Route> r = _route.lock();
495                         if (r) {
496                                 /* Route must mediate group control */
497                                 r->set_control ((AutomationType) parameter().type(), val, group_override);
498                         }
499                 }
500
501         protected:
502                 friend class Route;
503
504                 void route_set_value (double val) {
505                         GainControl::set_value (val, Controllable::NoGroup);
506                 }
507
508                 boost::weak_ptr<Route> _route;
509         };
510
511         class SoloControllable : public BooleanRouteAutomationControl {
512             public:
513                 SoloControllable (std::string name, boost::shared_ptr<Route>);
514                 void set_value (double, PBD::Controllable::GroupControlDisposition group_override);
515                 void set_value_unchecked (double);
516                 double get_value () const;
517
518                 /* Export additional API so that objects that only get access
519                  * to a Controllable/AutomationControl can do more fine-grained
520                  * operations with respect to solo. Obviously, they would need
521                  * to dynamic_cast<Route::SoloControllable> first.
522                  *
523                  * Solo state is not representable by a single scalar value,
524                  * so this AutomationControl maps set_value() and get_value()
525                  * to r->set_self_solo() and r->soloed() respectively. This
526                  * means that the Controllable is technically asymmetric. It is
527                  * possible to call ::set_value (0.0) to disable (self)solo,
528                  * and then call ::get_value() and get a return of 1.0 because
529                  * the Route owner is soloed by upstream/downstream.
530                  */
531
532                 void set_self_solo (bool yn) {
533                         boost::shared_ptr<Route> r(_route.lock()); if (r) r->set_self_solo (yn);
534                 }
535                 void mod_solo_by_others_upstream (int32_t delta) {
536                         boost::shared_ptr<Route> r(_route.lock()); if (r) r->mod_solo_by_others_upstream (delta);
537                 }
538                 void mod_solo_by_others_downstream (int32_t delta) {
539                         boost::shared_ptr<Route> r(_route.lock()); if (r) r->mod_solo_by_others_downstream (delta);
540                 }
541                 bool soloed_by_others () const {
542                         boost::shared_ptr<Route> r(_route.lock()); if (r) return r->soloed_by_others(); else return false;
543                 }
544                 bool soloed_by_others_upstream () const {
545                         boost::shared_ptr<Route> r(_route.lock()); if (r) return r->soloed_by_others_upstream(); else return false;
546                 }
547                 bool soloed_by_others_downstream () const {
548                         boost::shared_ptr<Route> r(_route.lock()); if (r) return r->soloed_by_others_downstream(); else return false;
549                 }
550                 bool self_soloed () const {
551                         boost::shared_ptr<Route> r(_route.lock()); if (r) return r->self_soloed(); else return false;
552                 }
553
554             protected:
555                 void master_changed (bool, PBD::Controllable::GroupControlDisposition);
556
557             private:
558                 void _set_value (double, PBD::Controllable::GroupControlDisposition group_override);
559         };
560
561         struct MuteControllable : public BooleanRouteAutomationControl {
562             public:
563                 MuteControllable (std::string name, boost::shared_ptr<Route>);
564                 void set_value (double, PBD::Controllable::GroupControlDisposition group_override);
565                 void set_value_unchecked (double);
566                 double get_value () const;
567
568                 /* Pretend to change value, but do not affect actual route mute. */
569                 void set_superficial_value(bool muted);
570             protected:
571                 void master_changed (bool, PBD::Controllable::GroupControlDisposition);
572
573             private:
574                 boost::weak_ptr<Route> _route;
575                 void _set_value (double, PBD::Controllable::GroupControlDisposition group_override);
576         };
577
578         class LIBARDOUR_API PhaseControllable : public BooleanRouteAutomationControl {
579         public:
580                 PhaseControllable (std::string name, boost::shared_ptr<Route>);
581                 void set_value (double, PBD::Controllable::GroupControlDisposition group_override);
582                 /* currently no automation, so no need for set_value_unchecked() */
583                 void set_channel (uint32_t);
584                 double get_value () const;
585                 uint32_t channel() const;
586         private:
587                 uint32_t _current_phase;
588                 void _set_value (double, PBD::Controllable::GroupControlDisposition group_override);
589         };
590
591         class LIBARDOUR_API SoloIsolateControllable : public BooleanRouteAutomationControl {
592         public:
593                 SoloIsolateControllable (std::string name, boost::shared_ptr<Route>);
594                 void set_value (double, PBD::Controllable::GroupControlDisposition group_override);
595                 /* currently no automation, so no need for set_value_unchecked() */
596                 double get_value () const;
597         private:
598                 void _set_value (double, PBD::Controllable::GroupControlDisposition group_override);
599         };
600
601         class LIBARDOUR_API SoloSafeControllable : public BooleanRouteAutomationControl {
602         public:
603                 SoloSafeControllable (std::string name, boost::shared_ptr<Route>);
604                 void set_value (double, PBD::Controllable::GroupControlDisposition group_override);
605                 /* currently no automation, so no need for set_value_unchecked() */
606                 double get_value () const;
607         private:
608                 void _set_value (double, PBD::Controllable::GroupControlDisposition group_override);
609         };
610
611         void set_control (AutomationType, double val, PBD::Controllable::GroupControlDisposition group_override);
612
613         boost::shared_ptr<AutomationControl> solo_control() const {
614                 return _solo_control;
615         }
616
617         boost::shared_ptr<AutomationControl> mute_control() const {
618                 return _mute_control;
619         }
620
621         boost::shared_ptr<MuteMaster> mute_master() const {
622                 return _mute_master;
623         }
624
625         boost::shared_ptr<AutomationControl> solo_isolate_control() const {
626                 return _solo_isolate_control;
627         }
628
629         boost::shared_ptr<AutomationControl> solo_safe_control() const {
630                 return _solo_safe_control;
631         }
632
633         boost::shared_ptr<AutomationControl> monitoring_control() const {
634                 /* tracks override this to provide actual monitoring control;
635                    busses have no possible choices except input monitoring.
636                 */
637                 return boost::shared_ptr<AutomationControl> ();
638         }
639
640         /* Route doesn't own these items, but sub-objects that it does own have them
641            and to make UI code a bit simpler, we provide direct access to them
642            here.
643         */
644
645         boost::shared_ptr<Panner> panner() const;  /* may return null */
646         boost::shared_ptr<PannerShell> panner_shell() const;
647         boost::shared_ptr<Pannable> pannable() const;
648
649         boost::shared_ptr<GainControl> gain_control() const;
650         boost::shared_ptr<AutomationControl> trim_control() const;
651         boost::shared_ptr<AutomationControl> phase_control() const;
652
653         /**
654            Return the first processor that accepts has at least one MIDI input
655            and at least one audio output. In the vast majority of cases, this
656            will be "the instrument". This does not preclude other MIDI->audio
657            processors later in the processing chain, but that would be a
658            special case not covered by this utility function.
659         */
660         boost::shared_ptr<Processor> the_instrument() const;
661         InstrumentInfo& instrument_info() { return _instrument_info; }
662
663         /* "well-known" controls for panning. Any or all of these may return
664          * null.
665          */
666
667         boost::shared_ptr<AutomationControl> pan_azimuth_control() const;
668         boost::shared_ptr<AutomationControl> pan_elevation_control() const;
669         boost::shared_ptr<AutomationControl> pan_width_control() const;
670         boost::shared_ptr<AutomationControl> pan_frontback_control() const;
671         boost::shared_ptr<AutomationControl> pan_lfe_control() const;
672
673         /* "well-known" controls for an EQ in this route. Any or all may
674          * be null. eq_band_cnt() must return 0 if there is no EQ present.
675          * Passing an @param band value >= eq_band_cnt() will guarantee the
676          * return of a null ptr (or an empty string for eq_band_name()).
677          */
678         uint32_t eq_band_cnt () const;
679         std::string eq_band_name (uint32_t) const;
680         boost::shared_ptr<AutomationControl> eq_gain_controllable (uint32_t band) const;
681         boost::shared_ptr<AutomationControl> eq_freq_controllable (uint32_t band) const;
682         boost::shared_ptr<AutomationControl> eq_q_controllable (uint32_t band) const;
683         boost::shared_ptr<AutomationControl> eq_shape_controllable (uint32_t band) const;
684         boost::shared_ptr<AutomationControl> eq_enable_controllable () const;
685         boost::shared_ptr<AutomationControl> eq_hpf_controllable () const;
686
687         /* "well-known" controls for a compressor in this route. Any or all may
688          * be null.
689          */
690         boost::shared_ptr<AutomationControl> comp_enable_controllable () const;
691         boost::shared_ptr<AutomationControl> comp_threshold_controllable () const;
692         boost::shared_ptr<AutomationControl> comp_speed_controllable () const;
693         boost::shared_ptr<AutomationControl> comp_mode_controllable () const;
694         boost::shared_ptr<AutomationControl> comp_makeup_controllable () const;
695         boost::shared_ptr<AutomationControl> comp_redux_controllable () const;
696
697         /* @param mode must be supplied by the comp_mode_controllable(). All other values
698          * result in undefined behaviour
699          */
700         std::string comp_mode_name (uint32_t mode) const;
701         /* @param mode - as for comp mode name. This returns the name for the
702          * parameter/control accessed via comp_speed_controllable(), which can
703          * be mode dependent.
704          */
705         std::string comp_speed_name (uint32_t mode) const;
706
707         /* "well-known" controls for sends to well-known busses in this route. Any or all may
708          * be null.
709          *
710          * In Mixbus, these are the sends that connect to the mixbusses.
711          * In Ardour, these are user-created sends that connect to user-created
712          * Aux busses.
713          */
714         boost::shared_ptr<AutomationControl> send_level_controllable (uint32_t n) const;
715         boost::shared_ptr<AutomationControl> send_enable_controllable (uint32_t n) const;
716         /* for the same value of @param n, this returns the name of the send
717          * associated with the pair of controllables returned by the above two methods.
718          */
719         std::string send_name (uint32_t n) const;
720
721         /* well known control that enables/disables sending to the master bus.
722          *
723          * In Ardour, this returns null.
724          * In Mixbus, it will return a suitable control, or null depending on
725          * the route.
726          */
727         boost::shared_ptr<AutomationControl> master_send_enable_controllable () const;
728
729         void protect_automation ();
730
731         enum {
732                 /* These numbers are taken from MIDI Machine Control,
733                    which can only control up to 317 tracks without
734                    doing sysex segmentation.
735                 */
736                 MasterBusRemoteControlID = 318,
737                 MonitorBusRemoteControlID = 319,
738         };
739
740         void     set_remote_control_id (uint32_t id, bool notify_class_listeners = true);
741         uint32_t remote_control_id () const;
742         void     set_remote_control_id_explicit (uint32_t order_key);
743
744         /* for things concerned about *this* route's RID */
745
746         PBD::Signal0<void> RemoteControlIDChanged;
747
748         /* for things concerned about *any* route's RID changes */
749
750         static PBD::Signal0<void> RemoteControlIDChange;
751         static PBD::Signal0<void> SyncOrderKeys;
752
753         bool has_external_redirects() const;
754
755         /* can only be executed by a route for which is_monitor() is true
756          *       (i.e. the monitor out)
757          */
758         void monitor_run (framepos_t start_frame, framepos_t end_frame,
759                         pframes_t nframes, int declick);
760
761         bool slaved_to (boost::shared_ptr<VCA>) const;
762         void vca_assign (boost::shared_ptr<VCA>);
763         void vca_unassign (boost::shared_ptr<VCA>);
764
765   protected:
766         friend class Session;
767
768         void catch_up_on_solo_mute_override ();
769         void mod_solo_by_others_upstream (int32_t);
770         void mod_solo_by_others_downstream (int32_t);
771         void curve_reallocate ();
772         virtual void set_block_size (pframes_t nframes);
773
774 protected:
775         virtual framecnt_t check_initial_delay (framecnt_t nframes, framepos_t&) { return nframes; }
776
777         void fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes);
778
779         void passthru (BufferSet&, framepos_t start_frame, framepos_t end_frame,
780                         pframes_t nframes, int declick);
781
782         virtual void write_out_of_band_data (BufferSet& /* bufs */, framepos_t /* start_frame */, framepos_t /* end_frame */,
783                                              framecnt_t /* nframes */) {}
784
785         virtual void process_output_buffers (BufferSet& bufs,
786                                              framepos_t start_frame, framepos_t end_frame,
787                                              pframes_t nframes, int declick,
788                                              bool gain_automation_ok);
789
790         virtual void bounce_process (BufferSet& bufs,
791                                      framepos_t start_frame, framecnt_t nframes,
792                                                                                                                          boost::shared_ptr<Processor> endpoint, bool include_endpoint,
793                                      bool for_export, bool for_freeze);
794
795         framecnt_t   bounce_get_latency (boost::shared_ptr<Processor> endpoint, bool include_endpoint, bool for_export, bool for_freeze) const;
796         ChanCount    bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint, bool include_endpoint, bool for_export, bool for_freeze) const;
797
798         boost::shared_ptr<IO> _input;
799         boost::shared_ptr<IO> _output;
800
801         bool           _active;
802         framecnt_t     _signal_latency;
803         framecnt_t     _signal_latency_at_amp_position;
804         framecnt_t     _signal_latency_at_trim_position;
805         framecnt_t     _initial_delay;
806         framecnt_t     _roll_delay;
807
808         ProcessorList  _processors;
809         mutable Glib::Threads::RWLock   _processor_lock;
810         boost::shared_ptr<Delivery> _main_outs;
811         boost::shared_ptr<InternalSend> _monitor_send;
812         boost::shared_ptr<InternalReturn> _intreturn;
813         boost::shared_ptr<MonitorProcessor> _monitor_control;
814         boost::shared_ptr<Pannable> _pannable;
815
816         enum {
817                 EmitNone = 0x00,
818                 EmitMeterChanged = 0x01,
819                 EmitMeterVisibilityChange = 0x02,
820                 EmitRtProcessorChange = 0x04
821         };
822
823         ProcessorList  _pending_processor_order;
824         gint           _pending_process_reorder; // atomic
825         gint           _pending_signals; // atomic
826
827         Flag           _flags;
828         int            _pending_declick;
829         MeterPoint     _meter_point;
830         MeterPoint     _pending_meter_point;
831         MeterType      _meter_type;
832         boost::dynamic_bitset<> _phase_invert;
833         bool           _self_solo;
834         uint32_t       _soloed_by_others_upstream;
835         uint32_t       _soloed_by_others_downstream;
836         bool           _solo_isolated;
837         uint32_t       _solo_isolated_by_upstream;
838
839         void mod_solo_isolated_by_upstream (bool);
840
841         bool           _denormal_protection;
842
843         bool _recordable : 1;
844         bool _silent : 1;
845         bool _declickable : 1;
846
847         boost::shared_ptr<SoloControllable> _solo_control;
848         boost::shared_ptr<MuteControllable> _mute_control;
849         boost::shared_ptr<MuteMaster> _mute_master;
850         boost::shared_ptr<PhaseControllable> _phase_control;
851         boost::shared_ptr<SoloIsolateControllable> _solo_isolate_control;
852         boost::shared_ptr<SoloSafeControllable> _solo_safe_control;
853
854         virtual void act_on_mute () {}
855
856         std::string    _comment;
857         bool           _have_internal_generator;
858         bool           _solo_safe;
859         DataType       _default_type;
860         FedBy          _fed_by;
861
862         InstrumentInfo _instrument_info;
863
864         virtual ChanCount input_streams () const;
865
866 protected:
867         virtual XMLNode& state(bool);
868
869         int configure_processors (ProcessorStreams*);
870
871         void passthru_silence (framepos_t start_frame, framepos_t end_frame,
872                                pframes_t nframes, int declick);
873
874         void silence (framecnt_t);
875         void silence_unlocked (framecnt_t);
876
877         ChanCount processor_max_streams;
878         ChanCount processor_out_streams;
879
880         uint32_t pans_required() const;
881         ChanCount n_process_buffers ();
882
883         virtual void maybe_declick (BufferSet&, framecnt_t, int);
884
885         boost::shared_ptr<GainControllable> _gain_control;
886         boost::shared_ptr<Amp>       _amp;
887         boost::shared_ptr<GainControllable> _trim_control;
888         boost::shared_ptr<Amp>       _trim;
889         boost::shared_ptr<PeakMeter> _meter;
890         boost::shared_ptr<DelayLine> _delayline;
891
892         boost::shared_ptr<Processor> the_instrument_unlocked() const;
893
894 private:
895         int set_state_2X (const XMLNode&, int);
896         void set_processor_state_2X (XMLNodeList const &, int);
897
898         uint32_t _order_key;
899         bool _has_order_key;
900         uint32_t _remote_control_id;
901
902         int64_t _track_number;
903
904         void input_change_handler (IOChange, void *src);
905         void output_change_handler (IOChange, void *src);
906         void sidechain_change_handler (IOChange, void *src);
907
908         void processor_selfdestruct (boost::weak_ptr<Processor>);
909         std::vector<boost::weak_ptr<Processor> > selfdestruct_sequence;
910         Glib::Threads::Mutex  selfdestruct_lock;
911
912         bool input_port_count_changing (ChanCount);
913         bool output_port_count_changing (ChanCount);
914
915         bool _in_configure_processors;
916         bool _initial_io_setup;
917         bool _in_sidechain_setup;
918
919         int configure_processors_unlocked (ProcessorStreams*, Glib::Threads::RWLock::WriterLock*);
920         bool set_meter_point_unlocked ();
921         void apply_processor_order (const ProcessorList& new_order);
922
923         std::list<std::pair<ChanCount, ChanCount> > try_configure_processors (ChanCount, ProcessorStreams *);
924         std::list<std::pair<ChanCount, ChanCount> > try_configure_processors_unlocked (ChanCount, ProcessorStreams *);
925
926         bool add_processor_from_xml_2X (const XMLNode&, int);
927
928         void placement_range (Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end);
929
930         void set_self_solo (bool yn);
931         void set_mute_master_solo ();
932
933         void set_processor_positions ();
934         framecnt_t update_port_latencies (PortSet& ports, PortSet& feeders, bool playback, framecnt_t) const;
935
936         void setup_invisible_processors ();
937         void unpan ();
938
939         void set_plugin_state_dir (boost::weak_ptr<Processor>, const std::string&);
940
941         boost::shared_ptr<CapturingProcessor> _capturing_processor;
942
943         /** A handy class to keep processor state while we attempt a reconfiguration
944          *  that may fail.
945          */
946         class ProcessorState {
947         public:
948                 ProcessorState (Route* r)
949                         : _route (r)
950                         , _processors (r->_processors)
951                         , _processor_max_streams (r->processor_max_streams)
952                 { }
953
954                 void restore () {
955                         _route->_processors = _processors;
956                         _route->processor_max_streams = _processor_max_streams;
957                 }
958
959         private:
960                 /* this should perhaps be a shared_ptr, but ProcessorStates will
961                    not hang around long enough for it to matter.
962                 */
963                 Route* _route;
964                 ProcessorList _processors;
965                 ChanCount _processor_max_streams;
966         };
967
968         friend class ProcessorState;
969
970         bool _strict_io;
971
972         /* no copy construction */
973         Route (Route const &);
974
975         void maybe_note_meter_position ();
976
977         /** true if we've made a note of a custom meter position in these variables */
978         bool _custom_meter_position_noted;
979         /** the processor that came after the meter when it was last set to a custom position,
980             or 0.
981         */
982         boost::weak_ptr<Processor> _processor_after_last_custom_meter;
983         RoutePinWindowProxy *_pinmgr_proxy;
984
985         void reset_instrument_info ();
986
987         void set_remote_control_id_internal (uint32_t id, bool notify_class_listeners = true);
988 };
989
990 } // namespace ARDOUR
991
992 #endif /* __ardour_route_h__ */