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.

339 lines
9.1KB

  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. void uiParameterChanged(uint32_t index, float value)
  64. {
  65. CARLA_ASSERT(host);
  66. if (host)
  67. host->ui_parameter_changed(host->handle, index, value);
  68. }
  69. void uiCustomDataChanged(const char* key, const char* value)
  70. {
  71. CARLA_ASSERT(host);
  72. if (host)
  73. host->ui_custom_data_changed(host->handle, key, value);
  74. }
  75. protected:
  76. // -------------------------------------------------------------------
  77. // Plugin parameter calls
  78. virtual uint32_t getParameterCount()
  79. {
  80. return 0;
  81. }
  82. virtual const Parameter* getParameterInfo(uint32_t index)
  83. {
  84. CARLA_ASSERT(index < getParameterCount());
  85. return nullptr;
  86. }
  87. virtual float getParameterValue(uint32_t index)
  88. {
  89. CARLA_ASSERT(index < getParameterCount());
  90. return 0.0f;
  91. }
  92. virtual const char* getParameterText(uint32_t index)
  93. {
  94. CARLA_ASSERT(index < getParameterCount());
  95. return nullptr;
  96. }
  97. // -------------------------------------------------------------------
  98. // Plugin midi-program calls
  99. virtual uint32_t getMidiProgramCount()
  100. {
  101. return 0;
  102. }
  103. virtual const MidiProgram* getMidiProgramInfo(uint32_t index)
  104. {
  105. CARLA_ASSERT(index < getMidiProgramCount());
  106. return nullptr;
  107. }
  108. // -------------------------------------------------------------------
  109. // Plugin state calls
  110. virtual void setParameterValue(uint32_t index, float value)
  111. {
  112. CARLA_ASSERT(index < getParameterCount());
  113. Q_UNUSED(value);
  114. }
  115. virtual void setMidiProgram(uint32_t bank, uint32_t program)
  116. {
  117. Q_UNUSED(bank);
  118. Q_UNUSED(program);
  119. }
  120. virtual void setCustomData(const char* key, const char* value)
  121. {
  122. CARLA_ASSERT(key);
  123. CARLA_ASSERT(value);
  124. }
  125. // -------------------------------------------------------------------
  126. // Plugin UI calls
  127. virtual void uiShow(bool show)
  128. {
  129. Q_UNUSED(show);
  130. }
  131. virtual void uiIdle()
  132. {
  133. }
  134. virtual void uiSetParameterValue(uint32_t index, float value)
  135. {
  136. CARLA_ASSERT(index < getParameterCount());
  137. Q_UNUSED(value);
  138. }
  139. virtual void uiSetMidiProgram(uint32_t bank, uint32_t program)
  140. {
  141. Q_UNUSED(bank);
  142. Q_UNUSED(program);
  143. }
  144. virtual void uiSetCustomData(const char* key, const char* value)
  145. {
  146. CARLA_ASSERT(key);
  147. CARLA_ASSERT(value);
  148. }
  149. // -------------------------------------------------------------------
  150. // Plugin process calls
  151. virtual void activate()
  152. {
  153. }
  154. virtual void deactivate()
  155. {
  156. }
  157. virtual void process(float** inBuffer, float** outBuffer, const uint32_t frames, uint32_t midiEventCount, MidiEvent* midiEvents) = 0;
  158. // -------------------------------------------------------------------
  159. private:
  160. const HostDescriptor* host;
  161. // -------------------------------------------------------------------
  162. #ifndef DOXYGEN
  163. public:
  164. static uint32_t _get_parameter_count(PluginHandle handle)
  165. {
  166. return ((PluginDescriptorClass*)handle)->getParameterCount();
  167. }
  168. static const Parameter* _get_parameter_info(PluginHandle handle, uint32_t index)
  169. {
  170. return ((PluginDescriptorClass*)handle)->getParameterInfo(index);
  171. }
  172. static float _get_parameter_value(PluginHandle handle, uint32_t index)
  173. {
  174. return ((PluginDescriptorClass*)handle)->getParameterValue(index);
  175. }
  176. static const char* _get_parameter_text(PluginHandle handle, uint32_t index)
  177. {
  178. return ((PluginDescriptorClass*)handle)->getParameterText(index);
  179. }
  180. static uint32_t _get_midi_program_count(PluginHandle handle)
  181. {
  182. return ((PluginDescriptorClass*)handle)->getMidiProgramCount();
  183. }
  184. static const MidiProgram* _get_midi_program_info(PluginHandle handle, uint32_t index)
  185. {
  186. return ((PluginDescriptorClass*)handle)->getMidiProgramInfo(index);
  187. }
  188. static void _set_parameter_value(PluginHandle handle, uint32_t index, float value)
  189. {
  190. return ((PluginDescriptorClass*)handle)->setParameterValue(index, value);
  191. }
  192. static void _set_midi_program(PluginHandle handle, uint32_t bank, uint32_t program)
  193. {
  194. return ((PluginDescriptorClass*)handle)->setMidiProgram(bank, program);
  195. }
  196. static void _set_custom_data(PluginHandle handle, const char* key, const char* value)
  197. {
  198. return ((PluginDescriptorClass*)handle)->setCustomData(key, value);
  199. }
  200. static void _ui_show(PluginHandle handle, bool show)
  201. {
  202. return ((PluginDescriptorClass*)handle)->uiShow(show);
  203. }
  204. static void _ui_idle(PluginHandle handle)
  205. {
  206. return ((PluginDescriptorClass*)handle)->uiIdle();
  207. }
  208. static void _ui_set_parameter_value(PluginHandle handle, uint32_t index, float value)
  209. {
  210. return ((PluginDescriptorClass*)handle)->uiSetParameterValue(index, value);
  211. }
  212. static void _ui_set_midi_program(PluginHandle handle, uint32_t bank, uint32_t program)
  213. {
  214. return ((PluginDescriptorClass*)handle)->uiSetMidiProgram(bank, program);
  215. }
  216. static void _ui_set_custom_data(PluginHandle handle, const char* key, const char* value)
  217. {
  218. return ((PluginDescriptorClass*)handle)->uiSetCustomData(key, value);
  219. }
  220. static void _activate(PluginHandle handle)
  221. {
  222. ((PluginDescriptorClass*)handle)->activate();
  223. }
  224. static void _deactivate(PluginHandle handle)
  225. {
  226. ((PluginDescriptorClass*)handle)->deactivate();
  227. }
  228. static void _process(PluginHandle handle, float** inBuffer, float** outBuffer, const uint32_t frames, uint32_t midiEventCount, MidiEvent* midiEvents)
  229. {
  230. return ((PluginDescriptorClass*)handle)->process(inBuffer, outBuffer, frames, midiEventCount, midiEvents);
  231. }
  232. #endif
  233. };
  234. /**@}*/
  235. // -----------------------------------------------------------------------
  236. #define PluginDescriptorClassEND(CLASS) \
  237. public: \
  238. static PluginHandle _instantiate(struct _PluginDescriptor*, HostDescriptor* host) \
  239. { \
  240. return new CLASS(host); \
  241. } \
  242. static void _cleanup(PluginHandle handle) \
  243. { \
  244. delete (CLASS*)handle; \
  245. }
  246. #define PluginDescriptorFILL(CLASS) \
  247. CLASS::_instantiate, \
  248. CLASS::_get_parameter_count, \
  249. CLASS::_get_parameter_info, \
  250. CLASS::_get_parameter_value, \
  251. CLASS::_get_parameter_text, \
  252. CLASS::_get_midi_program_count, \
  253. CLASS::_get_midi_program_info, \
  254. CLASS::_set_parameter_value, \
  255. CLASS::_set_midi_program, \
  256. CLASS::_set_custom_data, \
  257. CLASS::_ui_show, \
  258. CLASS::_ui_idle, \
  259. CLASS::_ui_set_parameter_value, \
  260. CLASS::_ui_set_midi_program, \
  261. CLASS::_ui_set_custom_data, \
  262. CLASS::_activate, \
  263. CLASS::_deactivate, \
  264. CLASS::_cleanup, \
  265. CLASS::_process
  266. #endif // CARLA_NATIVE_HPP