1b8ff3f87a7af535356cf2e6e424d0838317b6ce
[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/libardour_visibility.h"
25 #include "ardour/types.h"
26 #include "ardour/chan_count.h"
27 #include "ardour/io_processor.h"
28
29 namespace ARDOUR {
30
31 class BufferSet;
32 class IO;
33 class MuteMaster;
34 class PannerShell;
35 class Panner;
36 class Pannable;
37 class Amp;
38
39 class LIBARDOUR_API Delivery : public IOProcessor
40 {
41 public:
42         enum Role {
43                 /* main outputs - delivers out-of-place to port buffers, and cannot be removed */
44                 Main   = 0x1,
45                 /* send - delivers to port buffers, leaves input buffers untouched */
46                 Send   = 0x2,
47                 /* insert - delivers to port buffers and receives in-place from port buffers */
48                 Insert = 0x4,
49                 /* listen - internal send used only to deliver to control/monitor bus */
50                 Listen = 0x8,
51                 /* aux - internal send used to deliver to any bus, by user request */
52                 Aux    = 0x10
53         };
54
55         static bool role_requires_output_ports (Role r) { return r == Main || r == Send || r == Insert; }
56
57         bool does_routing() const { return true; }
58
59         /* Delivery to an existing output */
60
61         Delivery (Session& s, boost::shared_ptr<IO> io, boost::shared_ptr<Pannable>, boost::shared_ptr<MuteMaster> mm, const std::string& name, Role);
62
63         /* Delivery to a new output owned by this object */
64
65         Delivery (Session& s, boost::shared_ptr<Pannable>, boost::shared_ptr<MuteMaster> mm, const std::string& name, Role);
66         ~Delivery ();
67
68         bool set_name (const std::string& name);
69         std::string display_name() const;
70
71         boost::shared_ptr<Amp> amp() const { return _amp; }
72
73         Role role() const { return _role; }
74         bool can_support_io_configuration (const ChanCount& in, ChanCount& out);
75         bool configure_io (ChanCount in, ChanCount out);
76
77         void run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, bool);
78
79         /* supplemental method used with MIDI */
80
81         void flush_buffers (framecnt_t nframes);
82         void no_outs_cuz_we_no_monitor(bool);
83         void transport_stopped (framepos_t frame);
84         void realtime_locate ();
85
86         BufferSet& output_buffers() { return *_output_buffers; }
87
88         PBD::Signal0<void> MuteChange;
89
90         XMLNode& state (bool full);
91         int set_state (const XMLNode&, int version);
92
93         /* Panning */
94
95         static int  disable_panners (void);
96         static void reset_panners ();
97
98         boost::shared_ptr<PannerShell> panner_shell() const { return _panshell; }
99         boost::shared_ptr<Panner> panner() const;
100
101         void unpan ();
102         void reset_panner ();
103         void defer_pan_reset ();
104         void allow_pan_reset ();
105
106         uint32_t pans_required() const { return _configured_input.n_audio(); }
107         virtual uint32_t pan_outs() const;
108
109   protected:
110         Role        _role;
111         BufferSet*  _output_buffers;
112         boost::shared_ptr<PannerShell> _panshell;
113         boost::shared_ptr<Amp> _amp;
114
115         gain_t target_gain ();
116
117   private:
118         bool        _no_outs_cuz_we_no_monitor;
119         boost::shared_ptr<MuteMaster> _mute_master;
120         
121         static bool panners_legal;
122         static PBD::Signal0<void> PannersLegal;
123
124         void panners_became_legal ();
125         PBD::ScopedConnection panner_legal_c;
126         void output_changed (IOChange, void*);
127
128         bool _no_panner_reset;
129 };
130
131
132 } // namespace ARDOUR
133
134 #endif // __ardour__h__
135