Merge with 2.0-ongoing R2885.
[ardour.git] / libs / vamp-sdk / vamp-sdk / PluginBase.h
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2
3 /*
4     Vamp
5
6     An API for audio analysis and feature extraction plugins.
7
8     Centre for Digital Music, Queen Mary, University of London.
9     Copyright 2006 Chris Cannam.
10   
11     Permission is hereby granted, free of charge, to any person
12     obtaining a copy of this software and associated documentation
13     files (the "Software"), to deal in the Software without
14     restriction, including without limitation the rights to use, copy,
15     modify, merge, publish, distribute, sublicense, and/or sell copies
16     of the Software, and to permit persons to whom the Software is
17     furnished to do so, subject to the following conditions:
18
19     The above copyright notice and this permission notice shall be
20     included in all copies or substantial portions of the Software.
21
22     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
26     ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
27     CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28     WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30     Except as contained in this notice, the names of the Centre for
31     Digital Music; Queen Mary, University of London; and Chris Cannam
32     shall not be used in advertising or otherwise to promote the sale,
33     use or other dealings in this Software without prior written
34     authorization.
35 */
36
37 #ifndef _VAMP_PLUGIN_BASE_H_
38 #define _VAMP_PLUGIN_BASE_H_
39
40 #include <string>
41 #include <vector>
42
43 #define VAMP_SDK_VERSION "1.1"
44
45 namespace Vamp {
46
47 /**
48  * A base class for plugins with optional configurable parameters,
49  * programs, etc.  The Vamp::Plugin is derived from this, and
50  * individual Vamp plugins should derive from that.
51  *
52  * This class does not provide the necessary interfaces to instantiate
53  * or run a plugin.  It only specifies an interface for retrieving
54  * those controls that the host may wish to show to the user for
55  * editing.  It could meaningfully be subclassed by real-time plugins
56  * or other sorts of plugin as well as Vamp plugins.
57  */
58
59 class PluginBase 
60 {
61 public:
62     virtual ~PluginBase() { }
63
64     /**
65      * Get the Vamp API compatibility level of the plugin.
66      */
67     virtual unsigned int getVampApiVersion() const { return 1; }
68
69     /**
70      * Get the computer-usable name of the plugin.  This should be
71      * reasonably short and contain no whitespace or punctuation
72      * characters.  It may only contain the characters [a-zA-Z0-9_].
73      * This is the authoritative way for a program to identify a
74      * plugin within a given library.
75      *
76      * This text may be visible to the user, but it should not be the
77      * main text used to identify a plugin to the user (that will be
78      * the name, below).
79      *
80      * Example: "zero_crossings"
81      */
82     virtual std::string getIdentifier() const = 0;
83
84     /**
85      * Get a human-readable name or title of the plugin.  This
86      * should be brief and self-contained, as it may be used to
87      * identify the plugin to the user in isolation (i.e. without also
88      * showing the plugin's "identifier").
89      *
90      * Example: "Zero Crossings"
91      */
92     virtual std::string getName() const = 0;
93
94     /**
95      * Get a human-readable description for the plugin, typically
96      * a line of text that may optionally be displayed in addition
97      * to the plugin's "name".  May be empty if the name has said
98      * it all already.
99      *
100      * Example: "Detect and count zero crossing points"
101      */
102     virtual std::string getDescription() const = 0;
103     
104     /**
105      * Get the name of the author or vendor of the plugin in
106      * human-readable form.  This should be a short identifying text,
107      * as it may be used to label plugins from the same source in a
108      * menu or similar.
109      */
110     virtual std::string getMaker() const = 0;
111
112     /**
113      * Get the copyright statement or licensing summary for the
114      * plugin.  This can be an informative text, without the same
115      * presentation constraints as mentioned for getMaker above.
116      */
117     virtual std::string getCopyright() const = 0;
118
119     /**
120      * Get the version number of the plugin.
121      */
122     virtual int getPluginVersion() const = 0;
123
124
125     struct ParameterDescriptor
126     {
127         /**
128          * The name of the parameter, in computer-usable form.  Should
129          * be reasonably short, and may only contain the characters
130          * [a-zA-Z0-9_].
131          */
132         std::string identifier;
133
134         /**
135          * The human-readable name of the parameter.
136          */
137         std::string name;
138
139         /**
140          * A human-readable short text describing the parameter.  May be
141          * empty if the name has said it all already.
142          */
143         std::string description;
144
145         /**
146          * The unit of the parameter, in human-readable form.
147          */
148         std::string unit;
149
150         /**
151          * The minimum value of the parameter.
152          */
153         float minValue;
154
155         /**
156          * The maximum value of the parameter.
157          */
158         float maxValue;
159
160         /**
161          * The default value of the parameter.  The plugin should
162          * ensure that parameters have this value on initialisation
163          * (i.e. the host is not required to explicitly set parameters
164          * if it wants to use their default values).
165          */
166         float defaultValue;
167         
168         /**
169          * True if the parameter values are quantized to a particular
170          * resolution.
171          */
172         bool isQuantized;
173
174         /**
175          * Quantization resolution of the parameter values (e.g. 1.0
176          * if they are all integers).  Undefined if isQuantized is
177          * false.
178          */
179         float quantizeStep;
180
181         /**
182          * Names for the quantized values.  If isQuantized is true,
183          * this may either be empty or contain one string for each of
184          * the quantize steps from minValue up to maxValue inclusive.
185          * Undefined if isQuantized is false.
186          *
187          * If these names are provided, they should be shown to the
188          * user in preference to the values themselves.  The user may
189          * never see the actual numeric values unless they are also
190          * encoded in the names.
191          */
192         std::vector<std::string> valueNames;
193     };
194
195     typedef std::vector<ParameterDescriptor> ParameterList;
196
197     /**
198      * Get the controllable parameters of this plugin.
199      */
200     virtual ParameterList getParameterDescriptors() const {
201         return ParameterList();
202     }
203
204     /**
205      * Get the value of a named parameter.  The argument is the identifier
206      * field from that parameter's descriptor.
207      */
208     virtual float getParameter(std::string) const { return 0.0; }
209
210     /**
211      * Set a named parameter.  The first argument is the identifier field
212      * from that parameter's descriptor.
213      */
214     virtual void setParameter(std::string, float) { } 
215
216     
217     typedef std::vector<std::string> ProgramList;
218
219     /**
220      * Get the program settings available in this plugin.  A program
221      * is a named shorthand for a set of parameter values; changing
222      * the program may cause the plugin to alter the values of its
223      * published parameters (and/or non-public internal processing
224      * parameters).  The host should re-read the plugin's parameter
225      * values after setting a new program.
226      *
227      * The programs must have unique names.
228      */
229     virtual ProgramList getPrograms() const { return ProgramList(); }
230
231     /**
232      * Get the current program.
233      */
234     virtual std::string getCurrentProgram() const { return ""; }
235
236     /**
237      * Select a program.  (If the given program name is not one of the
238      * available programs, do nothing.)
239      */
240     virtual void selectProgram(std::string) { }
241
242     /**
243      * Get the type of plugin.  This is to be implemented by the
244      * immediate subclass, not by actual plugins.  Do not attempt to
245      * implement this in plugin code.
246      */
247     virtual std::string getType() const = 0;
248 };
249
250 }
251
252 #endif