Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
6.4KB

  1. /*
  2. Copyright 2006-2011 David Robillard <d@drobilla.net>
  3. Copyright 2006 Steve Harris <steve@plugin.org.uk>
  4. Permission to use, copy, modify, and/or distribute this software for any
  5. purpose with or without fee is hereby granted, provided that the above
  6. copyright notice and this permission notice appear in all copies.
  7. THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. */
  15. /** Include standard C headers */
  16. #include <math.h>
  17. #include <stdlib.h>
  18. /**
  19. LV2 headers are based on the URI of the specification they come from, so a
  20. consistent convention can be used even for unofficial extensions. The URI
  21. of the core LV2 specification is <http://lv2plug.in/ns/lv2core>, by
  22. replacing `http:/` with `lv2` any header in the specification bundle can be
  23. included, in this case `lv2.h`.
  24. */
  25. #include "lv2/lv2plug.in/ns/lv2core/lv2.h"
  26. /**
  27. The URI is the identifier for a plugin, and how the host associates this
  28. implementation in code with its description in data. In this plugin it is
  29. only used once in the code, but defining the plugin URI at the top of the
  30. file is a good convention to follow. If this URI does not match that used
  31. in the data files, the host will fail to load the plugin.
  32. */
  33. #define TEST_URI "http://example.org/lilv-bindings-test-plugin"
  34. /**
  35. In code, ports are referred to by index. An enumeration of port indices
  36. should be defined for readability.
  37. */
  38. typedef enum {
  39. TEST_CONTROL_IN = 0,
  40. TEST_CONTROL_OUT = 1,
  41. TEST_AUDIO_IN = 2,
  42. TEST_AUDIO_OUT = 3
  43. } PortIndex;
  44. /**
  45. Every plugin defines a private structure for the plugin instance. All data
  46. associated with a plugin instance is stored here, and is available to
  47. every instance method. In this simple plugin, only port buffers need to be
  48. stored, since there is no additional instance data. */
  49. typedef struct {
  50. // Port buffers
  51. } Test;
  52. /**
  53. The instantiate() function is called by the host to create a new plugin
  54. instance. The host passes the plugin descriptor, sample rate, and bundle
  55. path for plugins that need to load additional resources (e.g. waveforms).
  56. The features parameter contains host-provided features defined in LV2
  57. extensions, but this simple plugin does not use any.
  58. This function is in the ``instantiation'' threading class, so no other
  59. methods on this instance will be called concurrently with it.
  60. */
  61. static LV2_Handle
  62. instantiate(const LV2_Descriptor* descriptor,
  63. double rate,
  64. const char* bundle_path,
  65. const LV2_Feature* const* features)
  66. {
  67. Test* test = (Test*)malloc(sizeof(Test));
  68. return (LV2_Handle)test;
  69. }
  70. /**
  71. The connect_port() method is called by the host to connect a particular port
  72. to a buffer. The plugin must store the data location, but data may not be
  73. accessed except in run().
  74. This method is in the ``audio'' threading class, and is called in the same
  75. context as run().
  76. */
  77. static void
  78. connect_port(LV2_Handle instance,
  79. uint32_t port,
  80. void* data)
  81. {
  82. }
  83. /**
  84. The activate() method is called by the host to initialise and prepare the
  85. plugin instance for running. The plugin must reset all internal state
  86. except for buffer locations set by connect_port(). Since this plugin has
  87. no other internal state, this method does nothing.
  88. This method is in the ``instantiation'' threading class, so no other
  89. methods on this instance will be called concurrently with it.
  90. */
  91. static void
  92. activate(LV2_Handle instance)
  93. {
  94. }
  95. /** Process a block of audio (audio thread, must be RT safe). */
  96. static void
  97. run(LV2_Handle instance, uint32_t n_samples)
  98. {
  99. }
  100. /**
  101. The deactivate() method is the counterpart to activate() called by the host
  102. after running the plugin. It indicates that the host will not call run()
  103. again until another call to activate() and is mainly useful for more
  104. advanced plugins with ``live'' characteristics such as those with auxiliary
  105. processing threads. As with activate(), this plugin has no use for this
  106. information so this method does nothing.
  107. This method is in the ``instantiation'' threading class, so no other
  108. methods on this instance will be called concurrently with it.
  109. */
  110. static void
  111. deactivate(LV2_Handle instance)
  112. {
  113. }
  114. /**
  115. Destroy a plugin instance (counterpart to instantiate()).
  116. This method is in the ``instantiation'' threading class, so no other
  117. methods on this instance will be called concurrently with it.
  118. */
  119. static void
  120. cleanup(LV2_Handle instance)
  121. {
  122. free(instance);
  123. }
  124. /**
  125. The extension_data function returns any extension data supported by the
  126. plugin. Note that this is not an instance method, but a function on the
  127. plugin descriptor. It is usually used by plugins to implement additional
  128. interfaces. This plugin does not have any extension data, so this function
  129. returns NULL.
  130. This method is in the ``discovery'' threading class, so no other functions
  131. or methods in this plugin library will be called concurrently with it.
  132. */
  133. static const void*
  134. extension_data(const char* uri)
  135. {
  136. return NULL;
  137. }
  138. /**
  139. Define the LV2_Descriptor for this plugin. It is best to define descriptors
  140. statically to avoid leaking memory and non-portable shared library
  141. constructors and destructors to clean up properly.
  142. */
  143. static const LV2_Descriptor descriptor = {
  144. TEST_URI,
  145. instantiate,
  146. connect_port,
  147. activate,
  148. run,
  149. deactivate,
  150. cleanup,
  151. extension_data
  152. };
  153. /**
  154. The lv2_descriptor() function is the entry point to the plugin library. The
  155. host will load the library and call this function repeatedly with increasing
  156. indices to find all the plugins defined in the library. The index is not an
  157. indentifier, the URI of the returned descriptor is used to determine the
  158. identify of the plugin.
  159. This method is in the ``discovery'' threading class, so no other functions
  160. or methods in this plugin library will be called concurrently with it.
  161. */
  162. LV2_SYMBOL_EXPORT
  163. const LV2_Descriptor*
  164. lv2_descriptor(uint32_t index)
  165. {
  166. switch (index) {
  167. case 0:
  168. return &descriptor;
  169. default:
  170. return NULL;
  171. }
  172. }