Collection of tools useful for audio production
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.

287 lines
7.7KB

  1. /*
  2. * Carla Native Plugin API
  3. * Copyright (C) 2012 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the COPYING file
  16. */
  17. #ifndef CARLA_NATIVE_HPP
  18. #define CARLA_NATIVE_HPP
  19. #include "carla_native.h"
  20. #include "carla_utils.hpp"
  21. /*!
  22. * @defgroup CarlaNativeAPI Carla Native API
  23. * @{
  24. */
  25. class PluginDescriptorClass {
  26. public:
  27. PluginDescriptorClass(const HostDescriptor* host)
  28. {
  29. this->host = host;
  30. }
  31. virtual ~PluginDescriptorClass()
  32. {
  33. }
  34. // -------------------------------------------------------------------
  35. // Host calls
  36. uint32_t getBufferSize() const
  37. {
  38. CARLA_ASSERT(host);
  39. if (host)
  40. return host->get_buffer_size(host->handle);
  41. return 0;
  42. }
  43. double getSampleRate() const
  44. {
  45. CARLA_ASSERT(host);
  46. if (host)
  47. return host->get_sample_rate(host->handle);
  48. return 0.0;
  49. }
  50. const TimeInfo* getTimeInfo() const
  51. {
  52. CARLA_ASSERT(host);
  53. if (host)
  54. return host->get_time_info(host->handle);
  55. return nullptr;
  56. }
  57. void writeMidiEvent(MidiEvent* event)
  58. {
  59. CARLA_ASSERT(host);
  60. if (host)
  61. host->write_midi_event(host->handle, event);
  62. }
  63. protected:
  64. // -------------------------------------------------------------------
  65. // Plugin parameter calls
  66. virtual uint32_t getParameterCount()
  67. {
  68. return 0;
  69. }
  70. virtual const Parameter* getParameterInfo(uint32_t index)
  71. {
  72. CARLA_ASSERT(index < getParameterCount());
  73. return nullptr;
  74. }
  75. virtual float getParameterValue(uint32_t index)
  76. {
  77. CARLA_ASSERT(index < getParameterCount());
  78. return 0.0f;
  79. }
  80. virtual const char* getParameterText(uint32_t index)
  81. {
  82. CARLA_ASSERT(index < getParameterCount());
  83. return nullptr;
  84. }
  85. // -------------------------------------------------------------------
  86. // Plugin midi-program calls
  87. virtual uint32_t getMidiProgramCount()
  88. {
  89. return 0;
  90. }
  91. virtual const MidiProgram* getMidiProgramInfo(uint32_t index)
  92. {
  93. CARLA_ASSERT(index < getMidiProgramCount());
  94. return nullptr;
  95. }
  96. // -------------------------------------------------------------------
  97. // Plugin state calls
  98. virtual void setParameterValue(uint32_t index, double value)
  99. {
  100. CARLA_ASSERT(index < getParameterCount());
  101. Q_UNUSED(value);
  102. }
  103. virtual void setMidiProgram(uint32_t bank, uint32_t program)
  104. {
  105. Q_UNUSED(bank);
  106. Q_UNUSED(program);
  107. }
  108. virtual void setCustomData(const char* key, const char* value)
  109. {
  110. CARLA_ASSERT(key);
  111. CARLA_ASSERT(value);
  112. }
  113. // -------------------------------------------------------------------
  114. // Plugin UI calls
  115. virtual void showGui(bool show)
  116. {
  117. Q_UNUSED(show);
  118. }
  119. virtual void idleGui()
  120. {
  121. }
  122. // -------------------------------------------------------------------
  123. // Plugin process calls
  124. virtual void activate()
  125. {
  126. }
  127. virtual void deactivate()
  128. {
  129. }
  130. virtual void process(float** inBuffer, float** outBuffer, const uint32_t frames, uint32_t midiEventCount, MidiEvent* midiEvents) = 0;
  131. // -------------------------------------------------------------------
  132. private:
  133. const HostDescriptor* host;
  134. // -------------------------------------------------------------------
  135. #ifndef DOXYGEN
  136. public:
  137. static uint32_t _get_parameter_count(PluginHandle handle)
  138. {
  139. return ((PluginDescriptorClass*)handle)->getParameterCount();
  140. }
  141. static const Parameter* _get_parameter_info(PluginHandle handle, uint32_t index)
  142. {
  143. return ((PluginDescriptorClass*)handle)->getParameterInfo(index);
  144. }
  145. static float _get_parameter_value(PluginHandle handle, uint32_t index)
  146. {
  147. return ((PluginDescriptorClass*)handle)->getParameterValue(index);
  148. }
  149. static const char* _get_parameter_text(PluginHandle handle, uint32_t index)
  150. {
  151. return ((PluginDescriptorClass*)handle)->getParameterText(index);
  152. }
  153. static uint32_t _get_midi_program_count(PluginHandle handle)
  154. {
  155. return ((PluginDescriptorClass*)handle)->getMidiProgramCount();
  156. }
  157. static const MidiProgram* _get_midi_program_info(PluginHandle handle, uint32_t index)
  158. {
  159. return ((PluginDescriptorClass*)handle)->getMidiProgramInfo(index);
  160. }
  161. static void _set_parameter_value(PluginHandle handle, uint32_t index, float value)
  162. {
  163. return ((PluginDescriptorClass*)handle)->setParameterValue(index, value);
  164. }
  165. static void _set_midi_program(PluginHandle handle, uint32_t bank, uint32_t program)
  166. {
  167. return ((PluginDescriptorClass*)handle)->setMidiProgram(bank, program);
  168. }
  169. static void _set_custom_data(PluginHandle handle, const char* key, const char* value)
  170. {
  171. return ((PluginDescriptorClass*)handle)->setCustomData(key, value);
  172. }
  173. static void _show_gui(PluginHandle handle, bool show)
  174. {
  175. return ((PluginDescriptorClass*)handle)->showGui(show);
  176. }
  177. static void _idle_gui(PluginHandle handle)
  178. {
  179. return ((PluginDescriptorClass*)handle)->idleGui();
  180. }
  181. static void _activate(PluginHandle handle)
  182. {
  183. ((PluginDescriptorClass*)handle)->activate();
  184. }
  185. static void _deactivate(PluginHandle handle)
  186. {
  187. ((PluginDescriptorClass*)handle)->deactivate();
  188. }
  189. static void _process(PluginHandle handle, float** inBuffer, float** outBuffer, const uint32_t frames, uint32_t midiEventCount, MidiEvent* midiEvents)
  190. {
  191. return ((PluginDescriptorClass*)handle)->process(inBuffer, outBuffer, frames, midiEventCount, midiEvents);
  192. }
  193. #endif
  194. };
  195. /**@}*/
  196. // -----------------------------------------------------------------------
  197. #define PluginDescriptorClassEND(CLASS) \
  198. public: \
  199. static PluginHandle _instantiate(struct _PluginDescriptor*, HostDescriptor* host) \
  200. { \
  201. return new CLASS(host); \
  202. } \
  203. static void _cleanup(PluginHandle handle) \
  204. { \
  205. delete (CLASS*)handle; \
  206. }
  207. #define PluginDescriptorFILL(CLASS) \
  208. CLASS::_instantiate, \
  209. CLASS::_get_parameter_count, \
  210. CLASS::_get_parameter_info, \
  211. CLASS::_get_parameter_value, \
  212. CLASS::_get_parameter_text, \
  213. CLASS::_get_midi_program_count, \
  214. CLASS::_get_midi_program_info, \
  215. CLASS::_set_parameter_value, \
  216. CLASS::_set_midi_program, \
  217. CLASS::_set_custom_data, \
  218. CLASS::_show_gui, \
  219. CLASS::_idle_gui, \
  220. CLASS::_activate, \
  221. CLASS::_deactivate, \
  222. CLASS::_cleanup, \
  223. CLASS::_process
  224. #endif // CARLA_NATIVE_HPP