Strip trailing whitespace and fix other whitespace errors (e.g. space/tab mixing...
[ardour.git] / libs / ardour / ardour / plugin.h
1 /*
2     Copyright (C) 2000-2006 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_plugin_h__
21 #define __ardour_plugin_h__
22
23 #include <boost/shared_ptr.hpp>
24 #include <sigc++/signal.h>
25 #include <glibmm/ustring.h>
26
27 #include "pbd/statefuldestructible.h"
28 #include "pbd/controllable.h"
29
30 #include <jack/types.h>
31 #include "ardour/chan_count.h"
32 #include "ardour/chan_mapping.h"
33 #include "ardour/cycles.h"
34 #include "ardour/latent.h"
35 #include "ardour/plugin_insert.h"
36 #include "ardour/types.h"
37
38 #include <vector>
39 #include <set>
40 #include <map>
41
42 namespace ARDOUR {
43
44 class AudioEngine;
45 class Session;
46 class BufferSet;
47
48 class Plugin;
49
50 typedef boost::shared_ptr<Plugin> PluginPtr;
51
52 class PluginInfo {
53   public:
54         PluginInfo () { }
55         PluginInfo (const PluginInfo &o)
56                 : name(o.name),
57                 category (o.category),
58                 creator (o.creator),
59                 path (o.path),
60                 n_inputs(o.n_inputs),
61                 n_outputs(o.n_outputs),
62                 unique_id(o.unique_id),
63                 index(o.index) {}
64         virtual ~PluginInfo () { }
65
66         std::string name;
67         std::string category;
68         Glib::ustring creator;
69         Glib::ustring path;
70         ChanCount n_inputs;
71         ChanCount n_outputs;
72         ARDOUR::PluginType type;
73
74         std::string unique_id;
75
76         virtual PluginPtr load (Session& session) = 0;
77
78   protected:
79         friend class PluginManager;
80         uint32_t index;
81 };
82
83 typedef boost::shared_ptr<PluginInfo> PluginInfoPtr;
84 typedef std::list<PluginInfoPtr> PluginInfoList;
85
86 class Plugin : public PBD::StatefulDestructible, public Latent
87 {
88   public:
89         Plugin (ARDOUR::AudioEngine&, ARDOUR::Session&);
90         Plugin (const Plugin&);
91         virtual ~Plugin ();
92
93         struct ParameterDescriptor {
94
95                 /* essentially a union of LADSPA and VST info */
96
97                 bool integer_step;
98                 bool toggled;
99                 bool logarithmic;
100                 bool sr_dependent;
101                 std::string label;
102                 float lower;
103                 float upper;
104                 float step;
105                 float smallstep;
106                 float largestep;
107                 bool min_unbound;
108                 bool max_unbound;
109         };
110
111         virtual std::string unique_id() const = 0;
112         virtual const char * label() const = 0;
113         virtual const char * name() const = 0;
114         virtual const char * maker() const = 0;
115         virtual uint32_t parameter_count () const = 0;
116         virtual float default_value (uint32_t port) = 0;
117         virtual float get_parameter(uint32_t which) const = 0;
118
119         virtual int get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const = 0;
120         virtual uint32_t nth_parameter (uint32_t which, bool& ok) const = 0;
121         virtual void activate () = 0;
122         virtual void deactivate () = 0;
123         virtual void set_block_size (nframes_t nframes) = 0;
124
125         virtual int connect_and_run (BufferSet& bufs,
126                         ChanMapping in, ChanMapping out,
127                         nframes_t nframes, nframes_t offset) = 0;
128
129         virtual std::set<Evoral::Parameter> automatable() const = 0;
130         virtual std::string describe_parameter (Evoral::Parameter) = 0;
131         virtual std::string state_node_name() const = 0;
132         virtual void print_parameter (uint32_t, char*, uint32_t len) const = 0;
133
134         virtual bool parameter_is_audio(uint32_t) const = 0;
135         virtual bool parameter_is_control(uint32_t) const = 0;
136         virtual bool parameter_is_input(uint32_t) const = 0;
137         virtual bool parameter_is_output(uint32_t) const = 0;
138
139         virtual bool save_preset (std::string uri) = 0;
140         virtual bool load_preset (const std::string uri);
141
142         struct PresetRecord {
143                 PresetRecord(const std::string& u, const std::string& l) : uri(u), label(l) {}
144                 std::string uri;
145                 std::string label;
146         };
147
148         virtual std::vector<PresetRecord> get_presets();
149
150         const PresetRecord* preset_by_label(const std::string& label);
151         const PresetRecord* preset_by_uri(const std::string& uri);
152
153         virtual bool has_editor() const = 0;
154
155         sigc::signal<void,uint32_t,float> ParameterChanged;
156
157         /* NOTE: this block of virtual methods looks like the interface
158            to a Processor, but Plugin does not inherit from Processor.
159            It is therefore not required that these precisely match
160            the interface, but it is likely that they will evolve together.
161         */
162
163         /* this returns true if the plugin can change its inputs or outputs on demand.
164            LADSPA, LV2 and VST plugins cannot do this. AudioUnits can.
165         */
166
167         virtual bool reconfigurable_io() const { return false; }
168
169         /* this is only called if reconfigurable_io() returns true */
170         virtual bool configure_io (ChanCount /*in*/, ChanCount /*out*/) { return true; }
171
172         /* specific types of plugins can overload this. As of September 2008, only
173            AUPlugin does this.
174         */
175         virtual bool can_support_io_configuration (const ChanCount& /*in*/, ChanCount& /*out*/) const { return false; }
176         virtual ChanCount output_streams() const;
177         virtual ChanCount input_streams() const;
178
179         PBD::Controllable *get_nth_control (uint32_t, bool do_not_create = false);
180         void make_nth_control (uint32_t, const XMLNode&);
181
182         PluginInfoPtr get_info() { return _info; }
183         void set_info (const PluginInfoPtr inf) { _info = inf; }
184
185         ARDOUR::AudioEngine& engine() const { return _engine; }
186         ARDOUR::Session& session() const { return _session; }
187
188         void set_cycles (uint32_t c) { _cycles = c; }
189         cycles_t cycles() const { return _cycles; }
190
191   protected:
192         friend class PluginInsert;
193         friend struct PluginInsert::PluginControl;
194
195         virtual void set_parameter (uint32_t which, float val) = 0;
196
197         bool save_preset (std::string uri, std::string domain /* vst, ladspa etc. */);
198
199         ARDOUR::AudioEngine&     _engine;
200         ARDOUR::Session&         _session;
201         PluginInfoPtr            _info;
202         uint32_t                 _cycles;
203         std::map<std::string,PresetRecord>  presets;
204 };
205
206 PluginPtr find_plugin(ARDOUR::Session&, std::string unique_id, ARDOUR::PluginType);
207
208 } // namespace ARDOUR
209
210 #endif /* __ardour_plugin_h__ */