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.

345 lines
9.2KB

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