1 /*
2  * Copyright (C) 2007-2014 David Robillard <d@drobilla.net>
3  * Copyright (C) 2007-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2013-2017 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #ifndef __ardour_processor_h__
23 #define __ardour_processor_h__
24 
25 #include <vector>
26 #include <string>
27 #include <exception>
28 
29 #include "pbd/statefuldestructible.h"
30 
31 #include "ardour/ardour.h"
32 #include "ardour/buffer_set.h"
33 #include "ardour/latent.h"
34 #include "ardour/session_object.h"
35 #include "ardour/libardour_visibility.h"
36 #include "ardour/types.h"
37 #include "ardour/automatable.h"
38 
39 class XMLNode;
40 class ProcessorWindowProxy;
41 class PluginPinWindowProxy;
42 
43 namespace ARDOUR {
44 
45 class Location;
46 class Session;
47 
48 /** A mixer strip element - plugin, send, meter, etc */
49 class LIBARDOUR_API Processor : public SessionObject, public Automatable, public Latent
50 {
51   public:
52 	static const std::string state_node_name;
53 
54 	Processor(Session&, const std::string& name);
55 	Processor (const Processor& other);
56 
57 	virtual ~Processor();
58 
display_name()59 	virtual std::string display_name() const { return SessionObject::name(); }
60 
display_to_user()61 	virtual bool display_to_user() const { return _display_to_user; }
62 	virtual void set_display_to_user (bool);
63 
active()64 	bool active () const { return _pending_active; } ///< ardour hard bypass
enabled()65 	virtual bool enabled () const { return _pending_active; } ///< processor enabled/bypass
bypassable()66 	virtual bool bypassable () const { return true; } ///< enable is not automated or locked
67 
does_routing()68 	virtual bool does_routing() const { return false; }
69 
get_next_ab_is_active()70 	bool get_next_ab_is_active () const { return _next_ab_is_active; }
set_next_ab_is_active(bool yn)71 	void set_next_ab_is_active (bool yn) { _next_ab_is_active = yn; }
72 
signal_latency()73 	virtual samplecnt_t signal_latency() const { return 0; }
74 
set_input_latency(samplecnt_t cnt)75 	virtual void set_input_latency (samplecnt_t cnt) { _input_latency = cnt; }
input_latency()76 	samplecnt_t input_latency () const               { return _input_latency; }
77 
set_output_latency(samplecnt_t cnt)78 	virtual void set_output_latency (samplecnt_t cnt) { _output_latency = cnt; }
output_latency()79 	samplecnt_t output_latency () const               { return _output_latency; }
80 
set_capture_offset(samplecnt_t cnt)81 	virtual void set_capture_offset (samplecnt_t cnt) { _capture_offset = cnt; }
capture_offset()82 	samplecnt_t capture_offset () const               { return _capture_offset; }
83 
set_playback_offset(samplecnt_t cnt)84 	virtual void set_playback_offset (samplecnt_t cnt) { _playback_offset = cnt; }
playback_offset()85 	samplecnt_t playback_offset () const               { return _playback_offset; }
86 
set_block_size(pframes_t)87 	virtual int set_block_size (pframes_t /*nframes*/) { return 0; }
requires_fixed_sized_buffers()88 	virtual bool requires_fixed_sized_buffers() const { return false; }
89 
90 	/** The main process function for processors
91 	 *
92 	 * @param bufs bufferset of data to process in-place
93 	 * @param start_sample absolute timeline position in audio-samples to commence processing (latency compensated)
94 	 * @param end_sample absolute timeline position in audio-samples, usually start_sample +/- \p nframes
95 	 * @param speed transport speed. usually -1, 0, +1
96 	 * @param nframes number of audio samples to process
97 	 * @param result_required true if, on return from this method, \p bufs is required to contain valid data;
98 	 *        if false, the method need not bother writing to @a bufs if it doesn't want to.
99 	 */
run(BufferSet & bufs,samplepos_t start_sample,samplepos_t end_sample,double speed,pframes_t nframes,bool result_required)100 	virtual void run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes, bool result_required) {}
silence(samplecnt_t nframes,samplepos_t start_sample)101 	virtual void silence (samplecnt_t nframes, samplepos_t start_sample) { automation_run (start_sample, nframes); }
102 
activate()103 	virtual void activate ()   { _pending_active = true; ActiveChanged(); }
deactivate()104 	virtual void deactivate () { _pending_active = false; ActiveChanged(); }
flush()105 	virtual void flush() {}
106 
enable(bool yn)107 	virtual void enable (bool yn) { if (yn) { activate (); } else { deactivate (); } }
108 
109 	virtual bool configure_io (ChanCount in, ChanCount out);
110 
111 	/* Derived classes should override these, or processor appears as an in-place pass-through */
112 
113 	virtual bool can_support_io_configuration (const ChanCount& in, ChanCount& out) = 0;
input_streams()114 	virtual ChanCount input_streams () const { return _configured_input; }
output_streams()115 	virtual ChanCount output_streams() const { return _configured_output; }
116 
realtime_handle_transport_stopped()117 	virtual void realtime_handle_transport_stopped () {}
realtime_locate(bool)118 	virtual void realtime_locate (bool) {}
119 
set_loop(Location * loc)120 	virtual void set_loop (Location *loc) { _loop_location = loc; }
121 
122 	/* most processors won't care about this, but plugins that
123 	   receive MIDI or similar data from an input source that
124 	   may suddenly go "quiet" because of monitoring changes
125 	   need to know about it.
126 	*/
monitoring_changed()127 	virtual void monitoring_changed() {}
128 
129 	/* note: derived classes should implement state(), NOT get_state(), to allow
130 	   us to merge C++ inheritance and XML lack-of-inheritance reasonably
131 	   smoothly.
132 	 */
133 
134 	XMLNode& get_state ();
135 	int set_state (const XMLNode&, int version);
136 
137 	virtual void set_pre_fader (bool);
get_pre_fader()138 	virtual bool get_pre_fader () const { return _pre_fader; }
139 
140 	PBD::Signal0<void>                     ActiveChanged;
141 	PBD::Signal0<void>                     BypassableChanged;
142 	PBD::Signal2<void,ChanCount,ChanCount> ConfigurationChanged;
143 
144 	/* cross-thread signals.
145 	 * This allows control-surfaces to show/hide a plugin GUI.
146 	 */
147 	PBD::Signal0<void> ToggleUI;
148 	PBD::Signal0<void> ShowUI;
149 	PBD::Signal0<void> HideUI;
150 
window_proxy()151 	ProcessorWindowProxy * window_proxy () const { return _window_proxy; }
set_window_proxy(ProcessorWindowProxy * wp)152 	void set_window_proxy (ProcessorWindowProxy* wp) { _window_proxy = wp; }
153 
pinmgr_proxy()154 	PluginPinWindowProxy * pinmgr_proxy () const { return _pinmgr_proxy; }
set_pingmgr_proxy(PluginPinWindowProxy * wp)155 	void set_pingmgr_proxy (PluginPinWindowProxy* wp) { _pinmgr_proxy = wp ; }
156 
157 	virtual void set_owner (SessionObject*);
158 	SessionObject* owner() const;
159 
160 protected:
161 	virtual XMLNode& state ();
162 	virtual int set_state_2X (const XMLNode&, int version);
163 
164 	bool map_loop_range (samplepos_t& start, samplepos_t& end) const;
165 
166 	int       _pending_active;
167 	bool      _active;
168 	bool      _next_ab_is_active;
169 	bool      _configured;
170 	ChanCount _configured_input;
171 	ChanCount _configured_output;
172 	bool      _display_to_user;
173 	bool      _pre_fader; ///< true if this processor is currently placed before the Amp, otherwise false
174 	void*     _ui_pointer;
175 	ProcessorWindowProxy *_window_proxy;
176 	PluginPinWindowProxy *_pinmgr_proxy;
177 	SessionObject* _owner;
178 	// relative to route
179 	samplecnt_t _input_latency;
180 	samplecnt_t _output_latency;
181 	// absolute alignment to session i/o
182 	samplecnt_t _capture_offset;
183 	samplecnt_t _playback_offset;
184 	Location*   _loop_location;
185 };
186 
187 } // namespace ARDOUR
188 
189 #endif /* __ardour_processor_h__ */
190