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