Add Processor API for global session-transport alignment
[ardour.git] / libs / ardour / ardour / processor.h
1 /*
2     Copyright (C) 2009-2010 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
20 #ifndef __ardour_processor_h__
21 #define __ardour_processor_h__
22
23 #include <vector>
24 #include <string>
25 #include <exception>
26
27 #include "pbd/statefuldestructible.h"
28
29 #include "ardour/ardour.h"
30 #include "ardour/buffer_set.h"
31 #include "ardour/latent.h"
32 #include "ardour/session_object.h"
33 #include "ardour/libardour_visibility.h"
34 #include "ardour/types.h"
35 #include "ardour/automatable.h"
36
37 class XMLNode;
38 class ProcessorWindowProxy;
39 class PluginPinWindowProxy;
40
41 namespace ARDOUR {
42
43 class Session;
44 class Route;
45
46 /** A mixer strip element - plugin, send, meter, etc */
47 class LIBARDOUR_API Processor : public SessionObject, public Automatable, public Latent
48 {
49   public:
50         static const std::string state_node_name;
51
52         Processor(Session&, const std::string& name);
53         Processor (const Processor& other);
54
55         virtual ~Processor();
56
57         virtual std::string display_name() const { return SessionObject::name(); }
58
59         virtual bool display_to_user() const { return _display_to_user; }
60         virtual void set_display_to_user (bool);
61
62         bool active () const { return _pending_active; } ///< ardour hard bypass
63         virtual bool enabled () const { return _pending_active; } ///< processor enabled/bypass
64         virtual bool bypassable () const { return true; } ///< enable is not automated or locked
65
66         virtual bool does_routing() const { return false; }
67
68         bool get_next_ab_is_active () const { return _next_ab_is_active; }
69         void set_next_ab_is_active (bool yn) { _next_ab_is_active = yn; }
70
71         virtual samplecnt_t signal_latency() const { return 0; }
72
73         virtual void set_input_latency (samplecnt_t cnt) { _input_latency = cnt; }
74         samplecnt_t input_latency () const               { return _input_latency; }
75
76         virtual void set_output_latency (samplecnt_t cnt) { _output_latency = cnt; }
77         samplecnt_t output_latency () const               { return _output_latency; }
78
79         virtual void set_capture_offset (samplecnt_t cnt) { _capture_offset = cnt; }
80         samplecnt_t capture_offset () const               { return _capture_offset; }
81
82         virtual void set_playback_offset (samplecnt_t cnt) { _playback_offset = cnt; }
83         samplecnt_t playback_offset () const               { return _playback_offset; }
84
85         virtual int set_block_size (pframes_t /*nframes*/) { return 0; }
86         virtual bool requires_fixed_sized_buffers() const { return false; }
87
88         /** @param result_required true if, on return from this method, @a bufs is required to contain valid data;
89          *  if false, the method need not bother writing to @a bufs if it doesn't want to.
90          */
91         virtual void run (BufferSet& /*bufs*/, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, double speed, pframes_t /*nframes*/, bool /*result_required*/) {}
92         virtual void silence (samplecnt_t nframes, samplepos_t start_sample) { automation_run (start_sample, nframes); }
93
94         virtual void activate ()   { _pending_active = true; ActiveChanged(); }
95         virtual void deactivate () { _pending_active = false; ActiveChanged(); }
96         virtual void flush() {}
97
98         virtual void enable (bool yn) { if (yn) { activate (); } else { deactivate (); } }
99
100         virtual bool configure_io (ChanCount in, ChanCount out);
101
102         /* Derived classes should override these, or processor appears as an in-place pass-through */
103
104         virtual bool can_support_io_configuration (const ChanCount& in, ChanCount& out) = 0;
105         virtual ChanCount input_streams () const { return _configured_input; }
106         virtual ChanCount output_streams() const { return _configured_output; }
107
108         virtual void realtime_handle_transport_stopped () {}
109         virtual void realtime_locate () {}
110
111         /* most processors won't care about this, but plugins that
112            receive MIDI or similar data from an input source that
113            may suddenly go "quiet" because of monitoring changes
114            need to know about it.
115         */
116         virtual void monitoring_changed() {}
117
118         /* note: derived classes should implement state(), NOT get_state(), to allow
119            us to merge C++ inheritance and XML lack-of-inheritance reasonably
120            smoothly.
121          */
122
123         virtual XMLNode& state (bool full);
124         XMLNode& get_state (void);
125         int set_state (const XMLNode&, int version);
126
127         virtual void set_pre_fader (bool);
128
129         PBD::Signal0<void>                     ActiveChanged;
130         PBD::Signal0<void>                     BypassableChanged;
131         PBD::Signal2<void,ChanCount,ChanCount> ConfigurationChanged;
132
133         /* cross-thread signals.
134          * This allows control-surfaces to show/hide a plugin GUI.
135          */
136         PBD::Signal0<void> ToggleUI;
137         PBD::Signal0<void> ShowUI;
138         PBD::Signal0<void> HideUI;
139
140         ProcessorWindowProxy * window_proxy () const { return _window_proxy; }
141         void set_window_proxy (ProcessorWindowProxy* wp) { _window_proxy = wp; }
142
143         PluginPinWindowProxy * pinmgr_proxy () const { return _pinmgr_proxy; }
144         void set_pingmgr_proxy (PluginPinWindowProxy* wp) { _pinmgr_proxy = wp ; }
145
146         virtual void set_owner (SessionObject*);
147         SessionObject* owner() const;
148
149 protected:
150         virtual int set_state_2X (const XMLNode&, int version);
151
152         int       _pending_active;
153         bool      _active;
154         bool      _next_ab_is_active;
155         bool      _configured;
156         ChanCount _configured_input;
157         ChanCount _configured_output;
158         bool      _display_to_user;
159         bool      _pre_fader; ///< true if this processor is currently placed before the Amp, otherwise false
160         void*     _ui_pointer;
161         ProcessorWindowProxy *_window_proxy;
162         PluginPinWindowProxy *_pinmgr_proxy;
163         SessionObject* _owner;
164         // relative to route
165         samplecnt_t _input_latency;
166         samplecnt_t _output_latency;
167         // absolute alignment to session i/o
168         samplecnt_t _capture_offset;
169         samplecnt_t _playback_offset;
170 };
171
172 } // namespace ARDOUR
173
174 #endif /* __ardour_processor_h__ */