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