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