LadspaManager.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. #ifndef LADSPA_MANAGER_H
  27. #define LADSPA_MANAGER_H
  28. #include <ladspa.h>
  29. #include <QtCore/QMap>
  30. #include <QtCore/QPair>
  31. #include <QtCore/QString>
  32. #include <QtCore/QStringList>
  33. #include "lmms_export.h"
  34. #include "lmms_basics.h"
  35. const float NOHINT = -99342.2243f;
  36. typedef QPair<QString, QString> ladspa_key_t;
  37. typedef QPair<QString, ladspa_key_t> sortable_plugin_t;
  38. typedef QList<sortable_plugin_t> l_sortable_plugin_t;
  39. typedef QList<ladspa_key_t> l_ladspa_key_t;
  40. /* ladspaManager provides a database of LADSPA plug-ins. Upon instantiation,
  41. it loads all of the plug-ins found in the LADSPA_PATH environmental variable
  42. and stores their access descriptors according in a dictionary keyed on
  43. the filename the plug-in was loaded from and the label of the plug-in.
  44. The can be retrieved by using ladspa_key_t. For example, to get the
  45. "Phase Modulated Voice" plug-in from the cmt library, you would perform the
  46. calls using:
  47. ladspa_key_t key( "cmt.so", "phasemod" )
  48. as the plug-in key. */
  49. enum ladspaPluginType
  50. {
  51. SOURCE,
  52. TRANSFER,
  53. VALID,
  54. INVALID,
  55. SINK,
  56. OTHER
  57. };
  58. typedef struct ladspaManagerStorage
  59. {
  60. LADSPA_Descriptor_Function descriptorFunction;
  61. uint32_t index;
  62. ladspaPluginType type;
  63. uint16_t inputChannels;
  64. uint16_t outputChannels;
  65. } ladspaManagerDescription;
  66. class LMMS_EXPORT LadspaManager
  67. {
  68. public:
  69. LadspaManager();
  70. virtual ~LadspaManager();
  71. l_sortable_plugin_t getSortedPlugins();
  72. ladspaManagerDescription * getDescription( const ladspa_key_t &
  73. _plugin );
  74. /* This identifier can be used as a unique, case-sensitive
  75. identifier for the plugin type within the plugin file. Plugin
  76. types should be identified by file and label rather than by index
  77. or plugin name, which may be changed in new plugin
  78. versions. Labels must not contain white-space characters. */
  79. QString getLabel( const ladspa_key_t & _plugin );
  80. /* Indicates that the plugin has a real-time dependency
  81. (e.g. listens to a MIDI device) and so its output must not
  82. be cached or subject to significant latency. */
  83. bool hasRealTimeDependency( const ladspa_key_t & _plugin );
  84. /* Indicates that the plugin may cease to work correctly if the
  85. host elects to use the same data location for both input and output
  86. (see connectPort). */
  87. bool isInplaceBroken( const ladspa_key_t & _plugin );
  88. /* Indicates that the plugin is capable of running not only in a
  89. conventional host but also in a 'hard real-time' environment. */
  90. bool isRealTimeCapable( const ladspa_key_t & _plugin );
  91. /* Returns the name of the plug-in */
  92. QString getName( const ladspa_key_t & _plugin );
  93. /* Returns the the plug-in's author */
  94. QString getMaker( const ladspa_key_t & _plugin );
  95. /* Returns the copyright for the plug-in */
  96. QString getCopyright( const ladspa_key_t & _plugin );
  97. /* This indicates the number of ports (input AND output) present on
  98. the plugin. */
  99. uint32_t getPortCount( const ladspa_key_t & _plugin );
  100. /* Indicates that the port is an input. */
  101. bool isPortInput( const ladspa_key_t & _plugin, uint32_t _port );
  102. /* Indicates that the port is an output. */
  103. bool isPortOutput( const ladspa_key_t & _plugin, uint32_t _port );
  104. /* Indicates that the port is an audio. */
  105. bool isPortAudio( const ladspa_key_t & _plugin, uint32_t _port );
  106. /* Indicates that the port is an control. */
  107. bool isPortControl( const ladspa_key_t & _plugin, uint32_t _port );
  108. /* Indicates that any bounds specified should be interpreted as
  109. multiples of the sample rate. For instance, a frequency range from
  110. 0Hz to the Nyquist frequency (half the sample rate) could be requested
  111. by this hint in conjunction with LowerBound = 0 and UpperBound = 0.5.
  112. Hosts that support bounds at all must support this hint to retain
  113. meaning. */
  114. bool areHintsSampleRateDependent( const ladspa_key_t & _plugin,
  115. uint32_t _port );
  116. /* Returns the lower boundary value for the given port. If
  117. no lower bound is provided by the plug-in, returns -999e-99. When
  118. areHintsSampleRateDependent() is also true then this value should be
  119. multiplied by the relevant sample rate. */
  120. float getLowerBound( const ladspa_key_t & _plugin, uint32_t _port );
  121. /* Returns the upper boundary value for the given port. If
  122. no upper bound is provided by the plug-in, returns -999e-99. When
  123. areHintsSampleRateDependent() is also true then this value should be
  124. multiplied by the relevant sample rate. */
  125. float getUpperBound( const ladspa_key_t & _plugin, uint32_t _port );
  126. /* Indicates whether the given port should be considered 0 or 1
  127. boolean switch. */
  128. bool isPortToggled( const ladspa_key_t & _plugin, uint32_t _port );
  129. /* Retrieves any default setting hints offered by the plug-in for
  130. the given port. */
  131. float getDefaultSetting( const ladspa_key_t & _plugin, uint32_t _port );
  132. /* Indicates that it is likely that the user will find it more
  133. intuitive to view values using a logarithmic scale. This is
  134. particularly useful for frequencies and gains. */
  135. bool isLogarithmic( const ladspa_key_t & _plugin, uint32_t _port );
  136. /* Indicates that a user interface would probably wish to provide a
  137. stepped control taking only integer values. Any bounds set should be
  138. slightly wider than the actual integer range required to avoid floating
  139. point rounding errors. For instance, the integer set {0,1,2,3} might
  140. be described as [-0.1, 3.1]. */
  141. bool isInteger( const ladspa_key_t & _plugin, uint32_t _port );
  142. /* Indicates that a user interface would probably wish to provide a
  143. stepped control taking only integer values. This is equal to isInteger,
  144. but the number of values is usually small and may be better depicted
  145. with a combo box. */
  146. bool isEnum( const ladspa_key_t & _plugin, uint32_t _port );
  147. /* Returns the name of the port. */
  148. QString getPortName( const ladspa_key_t & _plugin, uint32_t _port );
  149. /* This may be used by the plugin developer to pass any custom
  150. implementation data into an instantiate call. It must not be used
  151. or interpreted by the host. It is expected that most plugin
  152. writers will not use this facility as LADSPA_Handle should be
  153. used to hold instance data. */
  154. const void * getImplementationData(
  155. const ladspa_key_t & _plugin );
  156. /* Returns a pointer to the plug-in's descriptor from which control
  157. of the plug-in is accessible */
  158. const LADSPA_Descriptor * getDescriptor(
  159. const ladspa_key_t & _plugin );
  160. /* The following methods are convenience functions for use during
  161. development. A real instrument should use the getDescriptor()
  162. method and implement the plug-in manipulations internally to avoid
  163. the overhead associated with QMap lookups. */
  164. /* Returns a handle to an instantiation of the given plug-in. */
  165. LADSPA_Handle instantiate( const ladspa_key_t & _plugin,
  166. uint32_t _sample_rate );
  167. /* This method calls a function pointer that connects a port on an
  168. instantiated plugin to a memory location at which a block of data
  169. for the port will be read/written. The data location is expected
  170. to be an array of LADSPA_Data for audio ports or a single
  171. LADSPA_Data value for control ports. Memory issues will be
  172. managed by the host. The plugin must read/write the data at these
  173. locations every time run() or runAdding() is called and the data
  174. present at the time of this connection call should not be
  175. considered meaningful.
  176. connectPort() may be called more than once for a plugin instance
  177. to allow the host to change the buffers that the plugin is
  178. reading or writing. These calls may be made before or after
  179. activate() or deactivate() calls.
  180. connectPort() must be called at least once for each port before
  181. run() or runAdding() is called. */
  182. bool connectPort( const ladspa_key_t & _plugin,
  183. LADSPA_Handle _instance,
  184. uint32_t _port,
  185. LADSPA_Data * _data_location );
  186. /* This method calls a function pointer that initialises a plugin
  187. instance and activates it for use. This is separated from
  188. instantiate() to aid real-time support and so that hosts can
  189. reinitialise a plugin instance by calling deactivate() and then
  190. activate(). In this case the plugin instance must reset all state
  191. information dependent on the history of the plugin instance
  192. except for any data locations provided by connectPort() and any
  193. gain set by setRunAddingGain(). If there is nothing for
  194. activate() to do then the plugin writer may provide a NULL rather
  195. than an empty function.
  196. When present, hosts must call this function once before run() (or
  197. runAdding()) is called for the first time. This call should be
  198. made as close to the run() call as possible and indicates to
  199. real-time plugins that they are now live. Plugins should not rely
  200. on a prompt call to run() after activate(). activate() may not be
  201. called again unless deactivate() is called first. Note that
  202. connectPort() may be called before or after a call to
  203. activate(). */
  204. bool activate( const ladspa_key_t & _plugin,
  205. LADSPA_Handle _instance );
  206. /* This method calls a function pointer that runs an instance of a
  207. plugin for a block. Two parameters are required: the first is a
  208. handle to the particular instance to be run and the second
  209. indicates the block size (in samples) for which the plugin
  210. instance may run.
  211. Note that if an activate() function exists then it must be called
  212. before run() or run_adding(). If deactivate() is called for a
  213. plugin instance then the plugin instance may not be reused until
  214. activate() has been called again. */
  215. bool run( const ladspa_key_t & _plugin,
  216. LADSPA_Handle _instance,
  217. uint32_t _sample_count );
  218. /* This method calls a function pointer that runs an instance of a
  219. plugin for a block. This has identical behaviour to run() except
  220. in the way data is output from the plugin. When run() is used,
  221. values are written directly to the memory areas associated with
  222. the output ports. However when runAdding() is called, values
  223. must be added to the values already present in the memory
  224. areas. Furthermore, output values written must be scaled by the
  225. current gain set by setRunAddingGain() (see below) before
  226. addition.
  227. runAdding() is optional. When it is not provided by a plugin,
  228. this function pointer must be set to NULL. When it is provided,
  229. the function setRunAddingGain() must be provided also. */
  230. bool runAdding( const ladspa_key_t & _plugin,
  231. LADSPA_Handle _instance,
  232. uint32_t _sample_count );
  233. /* This method calls a function pointer that sets the output gain for
  234. use when runAdding() is called (see above). If this function is
  235. never called the gain is assumed to default to 1. Gain
  236. information should be retained when activate() or deactivate()
  237. are called.
  238. This function should be provided by the plugin if and only if the
  239. runAdding() function is provided. When it is absent this
  240. function pointer must be set to NULL. */
  241. bool setRunAddingGain( const ladspa_key_t & _plugin,
  242. LADSPA_Handle _instance,
  243. LADSPA_Data _gain );
  244. /* This is the counterpart to activate() (see above). If there is
  245. nothing for deactivate() to do then the plugin writer may provide
  246. a NULL rather than an empty function.
  247. Hosts must deactivate all activated units after they have been
  248. run() (or run_adding()) for the last time. This call should be
  249. made as close to the last run() call as possible and indicates to
  250. real-time plugins that they are no longer live. Plugins should
  251. not rely on prompt deactivation. Note that connect_port() may be
  252. called before or after a call to deactivate().
  253. Deactivation is not similar to pausing as the plugin instance
  254. will be reinitialised when activate() is called to reuse it. */
  255. bool deactivate( const ladspa_key_t & _plugin,
  256. LADSPA_Handle _instance );
  257. /* Once an instance of a plugin has been finished with it can be
  258. deleted using the following function. The instance handle passed
  259. ceases to be valid after this call.
  260. If activate() was called for a plugin instance then a
  261. corresponding call to deactivate() must be made before cleanup()
  262. is called. */
  263. bool cleanup( const ladspa_key_t & _plugin,
  264. LADSPA_Handle _instance );
  265. private:
  266. void addPlugins( LADSPA_Descriptor_Function _descriptor_func,
  267. const QString & _file );
  268. uint16_t getPluginInputs( const LADSPA_Descriptor * _descriptor );
  269. uint16_t getPluginOutputs( const LADSPA_Descriptor * _descriptor );
  270. const LADSPA_PortDescriptor* getPortDescriptor( const ladspa_key_t& _plugin,
  271. uint32_t _port );
  272. const LADSPA_PortRangeHint* getPortRangeHint( const ladspa_key_t& _plugin,
  273. uint32_t _port );
  274. typedef QMap<ladspa_key_t, ladspaManagerDescription *>
  275. ladspaManagerMapType;
  276. ladspaManagerMapType m_ladspaManagerMap;
  277. l_sortable_plugin_t m_sortedPlugins;
  278. } ;
  279. #endif