LMMS
Loading...
Searching...
No Matches
LadspaManager.h
Go to the documentation of this file.
1/*
2 * LadspaManager.h - declaration of class LadspaManager
3 * a class to manage loading and instantiation
4 * of ladspa plugins
5 *
6 * Copyright (c) 2005-2008 Danny McRae <khjklujn@netscape.net>
7 *
8 * This file is part of LMMS - https://lmms.io
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public
21 * License along with this program (see COPYING); if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301 USA.
24 *
25 */
26
27#ifndef LMMS_LADSPA_MANAGER_H
28#define LMMS_LADSPA_MANAGER_H
29
30#include <ladspa.h>
31
32#include <QMap>
33#include <QPair>
34#include <QString>
35#include <QStringList>
36
37
38#include "lmms_export.h"
39#include "LmmsTypes.h"
40
41
42namespace lmms
43{
44
45const float NOHINT = -99342.2243f;
46
47using ladspa_key_t = QPair<QString, QString>;
48using sortable_plugin_t = QPair<QString, ladspa_key_t>;
49using l_sortable_plugin_t = QList<sortable_plugin_t>;
50using l_ladspa_key_t = QList<ladspa_key_t>;
51
52/* LadspaManager provides a database of LADSPA plug-ins. Upon instantiation,
53it loads all of the plug-ins found in the LADSPA_PATH environmental variable
54and stores their access descriptors according in a dictionary keyed on
55the filename the plug-in was loaded from and the label of the plug-in.
56
57The can be retrieved by using ladspa_key_t. For example, to get the
58"Phase Modulated Voice" plug-in from the cmt library, you would perform the
59calls using:
60
61 ladspa_key_t key( "cmt.so", "phasemod" )
62
63as the plug-in key. */
64
74
83
84class LMMS_EXPORT LadspaManager
85{
86public:
87
89 virtual ~LadspaManager();
90
93 _plugin );
94
95 /* This identifier can be used as a unique, case-sensitive
96 identifier for the plugin type within the plugin file. Plugin
97 types should be identified by file and label rather than by index
98 or plugin name, which may be changed in new plugin
99 versions. Labels must not contain white-space characters. */
100 QString getLabel( const ladspa_key_t & _plugin );
101
102 /* Indicates that the plugin has a real-time dependency
103 (e.g. listens to a MIDI device) and so its output must not
104 be cached or subject to significant latency. */
105 bool hasRealTimeDependency( const ladspa_key_t & _plugin );
106
107 /* Indicates that the plugin may cease to work correctly if the
108 host elects to use the same data location for both input and output
109 (see connectPort). */
110 bool isInplaceBroken( const ladspa_key_t & _plugin );
111
112 /* Indicates that the plugin is capable of running not only in a
113 conventional host but also in a 'hard real-time' environment. */
114 bool isRealTimeCapable( const ladspa_key_t & _plugin );
115
116 /* Returns the name of the plug-in */
117 QString getName( const ladspa_key_t & _plugin );
118
119 /* Returns the the plug-in's author */
120 QString getMaker( const ladspa_key_t & _plugin );
121
122 /* Returns the copyright for the plug-in */
123 QString getCopyright( const ladspa_key_t & _plugin );
124
125 /* This indicates the number of ports (input AND output) present on
126 the plugin. */
127 uint32_t getPortCount( const ladspa_key_t & _plugin );
128
129
130 /* Indicates that the port is an input. */
131 bool isPortInput( const ladspa_key_t & _plugin, uint32_t _port );
132
133 /* Indicates that the port is an output. */
134 bool isPortOutput( const ladspa_key_t & _plugin, uint32_t _port );
135
136 /* Indicates that the port is an audio. */
137 bool isPortAudio( const ladspa_key_t & _plugin, uint32_t _port );
138
139 /* Indicates that the port is an control. */
140 bool isPortControl( const ladspa_key_t & _plugin, uint32_t _port );
141
142 /* Indicates that any bounds specified should be interpreted as
143 multiples of the sample rate. For instance, a frequency range from
144 0Hz to the Nyquist frequency (half the sample rate) could be requested
145 by this hint in conjunction with LowerBound = 0 and UpperBound = 0.5.
146 Hosts that support bounds at all must support this hint to retain
147 meaning. */
148 bool areHintsSampleRateDependent( const ladspa_key_t & _plugin,
149 uint32_t _port );
150
151 /* Returns the lower boundary value for the given port. If
152 no lower bound is provided by the plug-in, returns -999e-99. When
153 areHintsSampleRateDependent() is also true then this value should be
154 multiplied by the relevant sample rate. */
155 float getLowerBound( const ladspa_key_t & _plugin, uint32_t _port );
156
157 /* Returns the upper boundary value for the given port. If
158 no upper bound is provided by the plug-in, returns -999e-99. When
159 areHintsSampleRateDependent() is also true then this value should be
160 multiplied by the relevant sample rate. */
161 float getUpperBound( const ladspa_key_t & _plugin, uint32_t _port );
162
163 /* Indicates whether the given port should be considered 0 or 1
164 boolean switch. */
165 bool isPortToggled( const ladspa_key_t & _plugin, uint32_t _port );
166
167 /* Retrieves any default setting hints offered by the plug-in for
168 the given port. */
169 float getDefaultSetting( const ladspa_key_t & _plugin, uint32_t _port );
170
171 /* Indicates that it is likely that the user will find it more
172 intuitive to view values using a logarithmic scale. This is
173 particularly useful for frequencies and gains. */
174 bool isLogarithmic( const ladspa_key_t & _plugin, uint32_t _port );
175
176 /* Indicates that a user interface would probably wish to provide a
177 stepped control taking only integer values. Any bounds set should be
178 slightly wider than the actual integer range required to avoid floating
179 point rounding errors. For instance, the integer set {0,1,2,3} might
180 be described as [-0.1, 3.1]. */
181 bool isInteger( const ladspa_key_t & _plugin, uint32_t _port );
182
183 /* Indicates that a user interface would probably wish to provide a
184 stepped control taking only integer values. This is equal to isInteger,
185 but the number of values is usually small and may be better depicted
186 with a combo box. */
187 bool isEnum( const ladspa_key_t & _plugin, uint32_t _port );
188
189 /* Returns the name of the port. */
190 QString getPortName( const ladspa_key_t & _plugin, uint32_t _port );
191
192
193 /* This may be used by the plugin developer to pass any custom
194 implementation data into an instantiate call. It must not be used
195 or interpreted by the host. It is expected that most plugin
196 writers will not use this facility as LADSPA_Handle should be
197 used to hold instance data. */
198 const void * getImplementationData(
199 const ladspa_key_t & _plugin );
200
201
202 /* Returns a pointer to the plug-in's descriptor from which control
203 of the plug-in is accessible */
205 const ladspa_key_t & _plugin );
206
207
208 /* The following methods are convenience functions for use during
209 development. A real instrument should use the getDescriptor()
210 method and implement the plug-in manipulations internally to avoid
211 the overhead associated with QMap lookups. */
212
213
214 /* Returns a handle to an instantiation of the given plug-in. */
215 LADSPA_Handle instantiate( const ladspa_key_t & _plugin,
216 uint32_t _sample_rate );
217
218 /* This method calls a function pointer that connects a port on an
219 instantiated plugin to a memory location at which a block of data
220 for the port will be read/written. The data location is expected
221 to be an array of LADSPA_Data for audio ports or a single
222 LADSPA_Data value for control ports. Memory issues will be
223 managed by the host. The plugin must read/write the data at these
224 locations every time run() or runAdding() is called and the data
225 present at the time of this connection call should not be
226 considered meaningful.
227
228 connectPort() may be called more than once for a plugin instance
229 to allow the host to change the buffers that the plugin is
230 reading or writing. These calls may be made before or after
231 activate() or deactivate() calls.
232
233 connectPort() must be called at least once for each port before
234 run() or runAdding() is called. */
235 bool connectPort( const ladspa_key_t & _plugin,
236 LADSPA_Handle _instance,
237 uint32_t _port,
238 LADSPA_Data * _data_location );
239
240 /* This method calls a function pointer that initialises a plugin
241 instance and activates it for use. This is separated from
242 instantiate() to aid real-time support and so that hosts can
243 reinitialise a plugin instance by calling deactivate() and then
244 activate(). In this case the plugin instance must reset all state
245 information dependent on the history of the plugin instance
246 except for any data locations provided by connectPort() and any
247 gain set by setRunAddingGain(). If there is nothing for
248 activate() to do then the plugin writer may provide a NULL rather
249 than an empty function.
250
251 When present, hosts must call this function once before run() (or
252 runAdding()) is called for the first time. This call should be
253 made as close to the run() call as possible and indicates to
254 real-time plugins that they are now live. Plugins should not rely
255 on a prompt call to run() after activate(). activate() may not be
256 called again unless deactivate() is called first. Note that
257 connectPort() may be called before or after a call to
258 activate(). */
259 bool activate( const ladspa_key_t & _plugin,
260 LADSPA_Handle _instance );
261
262 /* This method calls a function pointer that runs an instance of a
263 plugin for a block. Two parameters are required: the first is a
264 handle to the particular instance to be run and the second
265 indicates the block size (in samples) for which the plugin
266 instance may run.
267
268 Note that if an activate() function exists then it must be called
269 before run() or run_adding(). If deactivate() is called for a
270 plugin instance then the plugin instance may not be reused until
271 activate() has been called again. */
272 bool run( const ladspa_key_t & _plugin,
273 LADSPA_Handle _instance,
274 uint32_t _sample_count );
275
276 /* This method calls a function pointer that runs an instance of a
277 plugin for a block. This has identical behaviour to run() except
278 in the way data is output from the plugin. When run() is used,
279 values are written directly to the memory areas associated with
280 the output ports. However when runAdding() is called, values
281 must be added to the values already present in the memory
282 areas. Furthermore, output values written must be scaled by the
283 current gain set by setRunAddingGain() (see below) before
284 addition.
285
286 runAdding() is optional. When it is not provided by a plugin,
287 this function pointer must be set to NULL. When it is provided,
288 the function setRunAddingGain() must be provided also. */
289 bool runAdding( const ladspa_key_t & _plugin,
290 LADSPA_Handle _instance,
291 uint32_t _sample_count );
292
293 /* This method calls a function pointer that sets the output gain for
294 use when runAdding() is called (see above). If this function is
295 never called the gain is assumed to default to 1. Gain
296 information should be retained when activate() or deactivate()
297 are called.
298
299 This function should be provided by the plugin if and only if the
300 runAdding() function is provided. When it is absent this
301 function pointer must be set to NULL. */
302 bool setRunAddingGain( const ladspa_key_t & _plugin,
303 LADSPA_Handle _instance,
304 LADSPA_Data _gain );
305
306 /* This is the counterpart to activate() (see above). If there is
307 nothing for deactivate() to do then the plugin writer may provide
308 a NULL rather than an empty function.
309
310 Hosts must deactivate all activated units after they have been
311 run() (or run_adding()) for the last time. This call should be
312 made as close to the last run() call as possible and indicates to
313 real-time plugins that they are no longer live. Plugins should
314 not rely on prompt deactivation. Note that connect_port() may be
315 called before or after a call to deactivate().
316
317 Deactivation is not similar to pausing as the plugin instance
318 will be reinitialised when activate() is called to reuse it. */
319 bool deactivate( const ladspa_key_t & _plugin,
320 LADSPA_Handle _instance );
321
322 /* Once an instance of a plugin has been finished with it can be
323 deleted using the following function. The instance handle passed
324 ceases to be valid after this call.
325
326 If activate() was called for a plugin instance then a
327 corresponding call to deactivate() must be made before cleanup()
328 is called. */
329 bool cleanup( const ladspa_key_t & _plugin,
330 LADSPA_Handle _instance );
331
332private:
333 void addPlugins( LADSPA_Descriptor_Function _descriptor_func,
334 const QString & _file );
335 uint16_t getPluginInputs( const LADSPA_Descriptor * _descriptor );
336 uint16_t getPluginOutputs( const LADSPA_Descriptor * _descriptor );
337
339 uint32_t _port );
341 uint32_t _port );
342
343 using LadspaManagerMapType = QMap<ladspa_key_t, LadspaManagerDescription*>;
346
347} ;
348
349
350} // namespace lmms
351
352#endif // LMMS_LADSPA_MANAGER_H
static LV2_Handle instantiate(const LV2_Descriptor *descriptor, double rate, const char *path, const LV2_Feature *const *features)
Definition bad_syntax.c:57
static void run(LV2_Handle instance, uint32_t n_samples)
Definition bindings_test_plugin.c:112
static void deactivate(LV2_Handle instance)
Definition bindings_test_plugin.c:128
uint16_t getPluginInputs(const LADSPA_Descriptor *_descriptor)
Definition LadspaManager.cpp:189
bool isPortOutput(const ladspa_key_t &_plugin, uint32_t _port)
Definition LadspaManager.cpp:356
l_sortable_plugin_t getSortedPlugins()
Definition LadspaManager.cpp:261
bool isPortToggled(const ladspa_key_t &_plugin, uint32_t _port)
Definition LadspaManager.cpp:425
float getUpperBound(const ladspa_key_t &_plugin, uint32_t _port)
Definition LadspaManager.cpp:411
LadspaManagerMapType m_ladspaManagerMap
Definition LadspaManager.h:344
const LADSPA_Descriptor * getDescriptor(const ladspa_key_t &_plugin)
Definition LadspaManager.cpp:563
const void * getImplementationData(const ladspa_key_t &_plugin)
Definition LadspaManager.cpp:553
QString getMaker(const ladspa_key_t &_plugin)
Definition LadspaManager.cpp:319
bool connectPort(const ladspa_key_t &_plugin, LADSPA_Handle _instance, uint32_t _port, LADSPA_Data *_data_location)
Definition LadspaManager.cpp:595
QMap< ladspa_key_t, LadspaManagerDescription * > LadspaManagerMapType
Definition LadspaManager.h:343
bool isEnum(const ladspa_key_t &_plugin, uint32_t _port)
Definition LadspaManager.cpp:526
const LADSPA_PortRangeHint * getPortRangeHint(const ladspa_key_t &_plugin, uint32_t _port)
Definition LadspaManager.cpp:248
QString getName(const ladspa_key_t &_plugin)
Definition LadspaManager.cpp:310
bool isPortAudio(const ladspa_key_t &_plugin, uint32_t _port)
Definition LadspaManager.cpp:366
bool isRealTimeCapable(const ladspa_key_t &_plugin)
Definition LadspaManager.cpp:299
LadspaManagerDescription * getDescription(const ladspa_key_t &_plugin)
Definition LadspaManager.cpp:135
l_sortable_plugin_t m_sortedPlugins
Definition LadspaManager.h:345
bool hasRealTimeDependency(const ladspa_key_t &_plugin)
Definition LadspaManager.cpp:278
bool setRunAddingGain(const ladspa_key_t &_plugin, LADSPA_Handle _instance, LADSPA_Data _gain)
Definition LadspaManager.cpp:662
uint16_t getPluginOutputs(const LADSPA_Descriptor *_descriptor)
Definition LadspaManager.cpp:215
float getDefaultSetting(const ladspa_key_t &_plugin, uint32_t _port)
Definition LadspaManager.cpp:435
bool areHintsSampleRateDependent(const ladspa_key_t &_plugin, uint32_t _port)
Definition LadspaManager.cpp:386
const LADSPA_PortDescriptor * getPortDescriptor(const ladspa_key_t &_plugin, uint32_t _port)
Definition LadspaManager.cpp:238
bool isInplaceBroken(const ladspa_key_t &_plugin)
Definition LadspaManager.cpp:289
bool isPortControl(const ladspa_key_t &_plugin, uint32_t _port)
Definition LadspaManager.cpp:376
QString getPortName(const ladspa_key_t &_plugin, uint32_t _port)
Definition LadspaManager.cpp:543
QString getLabel(const ladspa_key_t &_plugin)
Definition LadspaManager.cpp:269
void addPlugins(LADSPA_Descriptor_Function _descriptor_func, const QString &_file)
Definition LadspaManager.cpp:145
uint32_t getPortCount(const ladspa_key_t &_plugin)
Definition LadspaManager.cpp:337
bool isInteger(const ladspa_key_t &_plugin, uint32_t _port)
Definition LadspaManager.cpp:516
bool isLogarithmic(const ladspa_key_t &_plugin, uint32_t _port)
Definition LadspaManager.cpp:506
bool runAdding(const ladspa_key_t &_plugin, LADSPA_Handle _instance, uint32_t _sample_count)
Definition LadspaManager.cpp:645
float getLowerBound(const ladspa_key_t &_plugin, uint32_t _port)
Definition LadspaManager.cpp:397
QString getCopyright(const ladspa_key_t &_plugin)
Definition LadspaManager.cpp:328
LadspaManager()
Definition LadspaManager.cpp:46
bool activate(const ladspa_key_t &_plugin, LADSPA_Handle _instance)
Definition LadspaManager.cpp:614
bool isPortInput(const ladspa_key_t &_plugin, uint32_t _port)
Definition LadspaManager.cpp:346
struct _LADSPA_PortRangeHint LADSPA_PortRangeHint
int LADSPA_PortDescriptor
Definition ladspa.h:152
float LADSPA_Data
Definition ladspa.h:84
const LADSPA_Descriptor *(* LADSPA_Descriptor_Function)(unsigned long Index)
Definition ladspa.h:593
void * LADSPA_Handle
Definition ladspa.h:363
struct _LADSPA_Descriptor LADSPA_Descriptor
static void cleanup(void)
Definition lilv_test.c:152
unsigned short uint16_t
Definition mid.cpp:99
unsigned int uint32_t
Definition mid.cpp:100
Definition AudioAlsa.cpp:35
QPair< QString, QString > ladspa_key_t
Definition LadspaManager.h:47
QPair< QString, ladspa_key_t > sortable_plugin_t
Definition LadspaManager.h:48
const float NOHINT
Definition LadspaManager.h:45
QList< sortable_plugin_t > l_sortable_plugin_t
Definition LadspaManager.h:49
QList< ladspa_key_t > l_ladspa_key_t
Definition LadspaManager.h:50
LadspaPluginType
Definition LadspaManager.h:66
@ Sink
Definition LadspaManager.h:71
@ Valid
Definition LadspaManager.h:69
@ Invalid
Definition LadspaManager.h:70
@ Other
Definition LadspaManager.h:72
@ Transfer
Definition LadspaManager.h:68
@ Source
Definition LadspaManager.h:67
Definition LadspaManager.h:76
LadspaPluginType type
Definition LadspaManager.h:79
uint32_t index
Definition LadspaManager.h:78
LADSPA_Descriptor_Function descriptorFunction
Definition LadspaManager.h:77
uint16_t outputChannels
Definition LadspaManager.h:81
uint16_t inputChannels
Definition LadspaManager.h:80