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.

323 lines
8.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 uiShow(bool show)
  116. {
  117. Q_UNUSED(show);
  118. }
  119. virtual void uiIdle()
  120. {
  121. }
  122. virtual void uiSetParameterValue(uint32_t index, double value)
  123. {
  124. CARLA_ASSERT(index < getParameterCount());
  125. Q_UNUSED(value);
  126. }
  127. virtual void uiSetMidiProgram(uint32_t bank, uint32_t program)
  128. {
  129. Q_UNUSED(bank);
  130. Q_UNUSED(program);
  131. }
  132. virtual void uiSetCustomData(const char* key, const char* value)
  133. {
  134. CARLA_ASSERT(key);
  135. CARLA_ASSERT(value);
  136. }
  137. // -------------------------------------------------------------------
  138. // Plugin process calls
  139. virtual void activate()
  140. {
  141. }
  142. virtual void deactivate()
  143. {
  144. }
  145. virtual void process(float** inBuffer, float** outBuffer, const uint32_t frames, uint32_t midiEventCount, MidiEvent* midiEvents) = 0;
  146. // -------------------------------------------------------------------
  147. private:
  148. const HostDescriptor* host;
  149. // -------------------------------------------------------------------
  150. #ifndef DOXYGEN
  151. public:
  152. static uint32_t _get_parameter_count(PluginHandle handle)
  153. {
  154. return ((PluginDescriptorClass*)handle)->getParameterCount();
  155. }
  156. static const Parameter* _get_parameter_info(PluginHandle handle, uint32_t index)
  157. {
  158. return ((PluginDescriptorClass*)handle)->getParameterInfo(index);
  159. }
  160. static float _get_parameter_value(PluginHandle handle, uint32_t index)
  161. {
  162. return ((PluginDescriptorClass*)handle)->getParameterValue(index);
  163. }
  164. static const char* _get_parameter_text(PluginHandle handle, uint32_t index)
  165. {
  166. return ((PluginDescriptorClass*)handle)->getParameterText(index);
  167. }
  168. static uint32_t _get_midi_program_count(PluginHandle handle)
  169. {
  170. return ((PluginDescriptorClass*)handle)->getMidiProgramCount();
  171. }
  172. static const MidiProgram* _get_midi_program_info(PluginHandle handle, uint32_t index)
  173. {
  174. return ((PluginDescriptorClass*)handle)->getMidiProgramInfo(index);
  175. }
  176. static void _set_parameter_value(PluginHandle handle, uint32_t index, float value)
  177. {
  178. return ((PluginDescriptorClass*)handle)->setParameterValue(index, value);
  179. }
  180. static void _set_midi_program(PluginHandle handle, uint32_t bank, uint32_t program)
  181. {
  182. return ((PluginDescriptorClass*)handle)->setMidiProgram(bank, program);
  183. }
  184. static void _set_custom_data(PluginHandle handle, const char* key, const char* value)
  185. {
  186. return ((PluginDescriptorClass*)handle)->setCustomData(key, value);
  187. }
  188. static void _ui_show(PluginHandle handle, bool show)
  189. {
  190. return ((PluginDescriptorClass*)handle)->uiShow(show);
  191. }
  192. static void _ui_idle(PluginHandle handle)
  193. {
  194. return ((PluginDescriptorClass*)handle)->uiIdle();
  195. }
  196. static void _ui_set_parameter_value(PluginHandle handle, uint32_t index, float value)
  197. {
  198. return ((PluginDescriptorClass*)handle)->uiSetParameterValue(index, value);
  199. }
  200. static void _ui_set_midi_program(PluginHandle handle, uint32_t bank, uint32_t program)
  201. {
  202. return ((PluginDescriptorClass*)handle)->uiSetMidiProgram(bank, program);
  203. }
  204. static void _ui_set_custom_data(PluginHandle handle, const char* key, const char* value)
  205. {
  206. return ((PluginDescriptorClass*)handle)->uiSetCustomData(key, value);
  207. }
  208. static void _activate(PluginHandle handle)
  209. {
  210. ((PluginDescriptorClass*)handle)->activate();
  211. }
  212. static void _deactivate(PluginHandle handle)
  213. {
  214. ((PluginDescriptorClass*)handle)->deactivate();
  215. }
  216. static void _process(PluginHandle handle, float** inBuffer, float** outBuffer, const uint32_t frames, uint32_t midiEventCount, MidiEvent* midiEvents)
  217. {
  218. return ((PluginDescriptorClass*)handle)->process(inBuffer, outBuffer, frames, midiEventCount, midiEvents);
  219. }
  220. #endif
  221. };
  222. /**@}*/
  223. // -----------------------------------------------------------------------
  224. #define PluginDescriptorClassEND(CLASS) \
  225. public: \
  226. static PluginHandle _instantiate(struct _PluginDescriptor*, HostDescriptor* host) \
  227. { \
  228. return new CLASS(host); \
  229. } \
  230. static void _cleanup(PluginHandle handle) \
  231. { \
  232. delete (CLASS*)handle; \
  233. }
  234. #define PluginDescriptorFILL(CLASS) \
  235. CLASS::_instantiate, \
  236. CLASS::_get_parameter_count, \
  237. CLASS::_get_parameter_info, \
  238. CLASS::_get_parameter_value, \
  239. CLASS::_get_parameter_text, \
  240. CLASS::_get_midi_program_count, \
  241. CLASS::_get_midi_program_info, \
  242. CLASS::_set_parameter_value, \
  243. CLASS::_set_midi_program, \
  244. CLASS::_set_custom_data, \
  245. CLASS::_ui_show, \
  246. CLASS::_ui_idle, \
  247. CLASS::_ui_set_parameter_value, \
  248. CLASS::_ui_set_midi_program, \
  249. CLASS::_ui_set_custom_data, \
  250. CLASS::_activate, \
  251. CLASS::_deactivate, \
  252. CLASS::_cleanup, \
  253. CLASS::_process
  254. #endif // CARLA_NATIVE_HPP