rework MIDI [processor|plugin] chain
[ardour.git] / libs / ardour / ardour / delivery.h
1 /*
2     Copyright (C) 2006 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify it
5     under the terms of the GNU General Public License as published by the Free
6     Software Foundation; either version 2 of the License, or (at your option)
7     any later version.
8
9     This program is distributed in the hope that it will be useful, but WITHOUT
10     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12     for more details.
13
14     You should have received a copy of the GNU General Public License along
15     with this program; if not, write to the Free Software Foundation, Inc.,
16     675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #ifndef __ardour_delivery_h__
20 #define __ardour_delivery_h__
21
22 #include <string>
23
24 #include "ardour/types.h"
25 #include "ardour/chan_count.h"
26 #include "ardour/io_processor.h"
27
28 namespace ARDOUR {
29
30 class BufferSet;
31 class IO;
32 class MuteMaster;
33 class PannerShell;
34 class Panner;
35 class Pannable;
36
37 class Delivery : public IOProcessor
38 {
39 public:
40         enum Role {
41                 /* main outputs - delivers out-of-place to port buffers, and cannot be removed */
42                 Main   = 0x1,
43                 /* send - delivers to port buffers, leaves input buffers untouched */
44                 Send   = 0x2,
45                 /* insert - delivers to port buffers and receives in-place from port buffers */
46                 Insert = 0x4,
47                 /* listen - internal send used only to deliver to control/monitor bus */
48                 Listen = 0x8,
49                 /* aux - internal send used to deliver to any bus, by user request */
50                 Aux    = 0x10
51         };
52
53         static bool role_requires_output_ports (Role r) { return r == Main || r == Send || r == Insert; }
54
55         bool does_routing() const { return true; }
56
57         /* Delivery to an existing output */
58
59         Delivery (Session& s, boost::shared_ptr<IO> io, boost::shared_ptr<Pannable>, boost::shared_ptr<MuteMaster> mm, const std::string& name, Role);
60
61         /* Delivery to a new output owned by this object */
62
63         Delivery (Session& s, boost::shared_ptr<Pannable>, boost::shared_ptr<MuteMaster> mm, const std::string& name, Role);
64         ~Delivery ();
65
66         bool set_name (const std::string& name);
67         std::string display_name() const;
68
69         Role role() const { return _role; }
70         bool can_support_io_configuration (const ChanCount& in, ChanCount& out);
71         bool configure_io (ChanCount in, ChanCount out);
72
73         void run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, bool);
74
75         /* supplemental method used with MIDI */
76
77         void flush_buffers (framecnt_t nframes);
78         void no_outs_cuz_we_no_monitor(bool);
79         void transport_stopped (framepos_t frame);
80         void realtime_locate ();
81
82         BufferSet& output_buffers() { return *_output_buffers; }
83
84         PBD::Signal0<void> MuteChange;
85
86         XMLNode& state (bool full);
87         int set_state (const XMLNode&, int version);
88
89         /* Panning */
90
91         static int  disable_panners (void);
92         static void reset_panners ();
93
94         boost::shared_ptr<PannerShell> panner_shell() const { return _panshell; }
95         boost::shared_ptr<Panner> panner() const;
96
97         void unpan ();
98         void reset_panner ();
99         void defer_pan_reset ();
100         void allow_pan_reset ();
101
102         uint32_t pans_required() const { return _configured_input.n_audio(); }
103         virtual uint32_t pan_outs() const;
104
105   protected:
106         Role        _role;
107         BufferSet*  _output_buffers;
108         gain_t      _current_gain;
109         boost::shared_ptr<PannerShell> _panshell;
110
111         gain_t target_gain ();
112
113   private:
114         bool        _no_outs_cuz_we_no_monitor;
115         boost::shared_ptr<MuteMaster> _mute_master;
116         
117         static bool panners_legal;
118         static PBD::Signal0<void> PannersLegal;
119
120         void panners_became_legal ();
121         PBD::ScopedConnection panner_legal_c;
122         void output_changed (IOChange, void*);
123
124         bool _no_panner_reset;
125 };
126
127
128 } // namespace ARDOUR
129
130 #endif // __ardour__h__
131