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.

409 lines
10KB

  1. /*
  2. * Carla Native Plugin API
  3. * Copyright (C) 2012-2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or 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 GPL.txt 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. {
  27. public:
  28. PluginDescriptorClass(const HostDescriptor* const host)
  29. : m_host(host)
  30. {
  31. }
  32. virtual ~PluginDescriptorClass()
  33. {
  34. }
  35. // -------------------------------------------------------------------
  36. // Host calls
  37. const HostDescriptor* getHostHandle() const
  38. {
  39. return m_host;
  40. }
  41. uint32_t getBufferSize() const
  42. {
  43. CARLA_ASSERT(m_host);
  44. if (m_host)
  45. return m_host->get_buffer_size(m_host->handle);
  46. return 0;
  47. }
  48. double getSampleRate() const
  49. {
  50. CARLA_ASSERT(m_host);
  51. if (m_host)
  52. return m_host->get_sample_rate(m_host->handle);
  53. return 0.0;
  54. }
  55. const TimeInfo* getTimeInfo() const
  56. {
  57. CARLA_ASSERT(m_host);
  58. if (m_host)
  59. return m_host->get_time_info(m_host->handle);
  60. return nullptr;
  61. }
  62. void writeMidiEvent(const MidiEvent* const event)
  63. {
  64. CARLA_ASSERT(m_host);
  65. if (m_host)
  66. m_host->write_midi_event(m_host->handle, event);
  67. }
  68. void uiParameterChanged(const uint32_t index, const float value)
  69. {
  70. CARLA_ASSERT(m_host);
  71. if (m_host)
  72. m_host->ui_parameter_changed(m_host->handle, index, value);
  73. }
  74. void uiMidiProgramChanged(const uint32_t bank, const uint32_t program)
  75. {
  76. CARLA_ASSERT(m_host);
  77. if (m_host)
  78. m_host->ui_midi_program_changed(m_host->handle, bank, program);
  79. }
  80. void uiCustomDataChanged(const char* const key, const char* const value)
  81. {
  82. CARLA_ASSERT(m_host);
  83. if (m_host)
  84. m_host->ui_custom_data_changed(m_host->handle, key, value);
  85. }
  86. void uiClosed()
  87. {
  88. CARLA_ASSERT(m_host);
  89. if (m_host)
  90. m_host->ui_closed(m_host->handle);
  91. }
  92. protected:
  93. // -------------------------------------------------------------------
  94. // Plugin parameter calls
  95. virtual uint32_t getParameterCount()
  96. {
  97. return 0;
  98. }
  99. virtual const Parameter* getParameterInfo(const uint32_t index)
  100. {
  101. CARLA_ASSERT(index < getParameterCount());
  102. return nullptr;
  103. // unused
  104. Q_UNUSED(index);
  105. }
  106. virtual float getParameterValue(const uint32_t index)
  107. {
  108. CARLA_ASSERT(index < getParameterCount());
  109. return 0.0f;
  110. // unused
  111. Q_UNUSED(index);
  112. }
  113. virtual const char* getParameterText(const uint32_t index)
  114. {
  115. CARLA_ASSERT(index < getParameterCount());
  116. return nullptr;
  117. // unused
  118. Q_UNUSED(index);
  119. }
  120. // -------------------------------------------------------------------
  121. // Plugin midi-program calls
  122. virtual uint32_t getMidiProgramCount()
  123. {
  124. return 0;
  125. }
  126. virtual const MidiProgram* getMidiProgramInfo(const uint32_t index)
  127. {
  128. CARLA_ASSERT(index < getMidiProgramCount());
  129. return nullptr;
  130. // unused
  131. Q_UNUSED(index);
  132. }
  133. // -------------------------------------------------------------------
  134. // Plugin state calls
  135. virtual void setParameterValue(const uint32_t index, const float value)
  136. {
  137. CARLA_ASSERT(index < getParameterCount());
  138. return;
  139. // unused
  140. Q_UNUSED(index);
  141. Q_UNUSED(value);
  142. }
  143. virtual void setMidiProgram(const uint32_t bank, const uint32_t program)
  144. {
  145. return;
  146. // unused
  147. Q_UNUSED(bank);
  148. Q_UNUSED(program);
  149. }
  150. virtual void setCustomData(const char* const key, const char* const value)
  151. {
  152. CARLA_ASSERT(key);
  153. CARLA_ASSERT(value);
  154. return;
  155. // unused
  156. CARLA_ASSERT(key);
  157. CARLA_ASSERT(value);
  158. }
  159. // -------------------------------------------------------------------
  160. // Plugin process calls
  161. virtual void activate()
  162. {
  163. }
  164. virtual void deactivate()
  165. {
  166. }
  167. virtual void process(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t midiEventCount, const MidiEvent* const midiEvents) = 0;
  168. // -------------------------------------------------------------------
  169. // Plugin UI calls
  170. virtual void uiShow(const bool show)
  171. {
  172. return;
  173. // unused
  174. Q_UNUSED(show);
  175. }
  176. virtual void uiIdle()
  177. {
  178. }
  179. virtual void uiSetParameterValue(const uint32_t index, const float value)
  180. {
  181. CARLA_ASSERT(index < getParameterCount());
  182. return;
  183. // unused
  184. Q_UNUSED(value);
  185. }
  186. virtual void uiSetMidiProgram(const uint32_t bank, const uint32_t program)
  187. {
  188. return;
  189. // unused
  190. Q_UNUSED(bank);
  191. Q_UNUSED(program);
  192. }
  193. virtual void uiSetCustomData(const char* const key, const char* const value)
  194. {
  195. CARLA_ASSERT(key);
  196. CARLA_ASSERT(value);
  197. return;
  198. // unused
  199. Q_UNUSED(key);
  200. Q_UNUSED(value);
  201. }
  202. // -------------------------------------------------------------------
  203. private:
  204. const HostDescriptor* const m_host;
  205. // -------------------------------------------------------------------
  206. #ifndef DOXYGEN
  207. public:
  208. #define handlePtr ((PluginDescriptorClass*)handle)
  209. static uint32_t _get_parameter_count(PluginHandle handle)
  210. {
  211. return handlePtr->getParameterCount();
  212. }
  213. static const Parameter* _get_parameter_info(PluginHandle handle, uint32_t index)
  214. {
  215. return handlePtr->getParameterInfo(index);
  216. }
  217. static float _get_parameter_value(PluginHandle handle, uint32_t index)
  218. {
  219. return handlePtr->getParameterValue(index);
  220. }
  221. static const char* _get_parameter_text(PluginHandle handle, uint32_t index)
  222. {
  223. return handlePtr->getParameterText(index);
  224. }
  225. static uint32_t _get_midi_program_count(PluginHandle handle)
  226. {
  227. return handlePtr->getMidiProgramCount();
  228. }
  229. static const MidiProgram* _get_midi_program_info(PluginHandle handle, uint32_t index)
  230. {
  231. return handlePtr->getMidiProgramInfo(index);
  232. }
  233. static void _set_parameter_value(PluginHandle handle, uint32_t index, float value)
  234. {
  235. return handlePtr->setParameterValue(index, value);
  236. }
  237. static void _set_midi_program(PluginHandle handle, uint32_t bank, uint32_t program)
  238. {
  239. return handlePtr->setMidiProgram(bank, program);
  240. }
  241. static void _set_custom_data(PluginHandle handle, const char* key, const char* value)
  242. {
  243. return handlePtr->setCustomData(key, value);
  244. }
  245. static void _ui_show(PluginHandle handle, bool show)
  246. {
  247. return handlePtr->uiShow(show);
  248. }
  249. static void _ui_idle(PluginHandle handle)
  250. {
  251. return handlePtr->uiIdle();
  252. }
  253. static void _ui_set_parameter_value(PluginHandle handle, uint32_t index, float value)
  254. {
  255. return handlePtr->uiSetParameterValue(index, value);
  256. }
  257. static void _ui_set_midi_program(PluginHandle handle, uint32_t bank, uint32_t program)
  258. {
  259. return handlePtr->uiSetMidiProgram(bank, program);
  260. }
  261. static void _ui_set_custom_data(PluginHandle handle, const char* key, const char* value)
  262. {
  263. return handlePtr->uiSetCustomData(key, value);
  264. }
  265. static void _activate(PluginHandle handle)
  266. {
  267. handlePtr->activate();
  268. }
  269. static void _deactivate(PluginHandle handle)
  270. {
  271. handlePtr->deactivate();
  272. }
  273. static void _process(PluginHandle handle, float** inBuffer, float** outBuffer, const uint32_t frames, uint32_t midiEventCount, const MidiEvent* midiEvents)
  274. {
  275. return handlePtr->process(inBuffer, outBuffer, frames, midiEventCount, midiEvents);
  276. }
  277. #undef handlePtr
  278. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginDescriptorClass)
  279. #endif
  280. };
  281. /**@}*/
  282. // -----------------------------------------------------------------------
  283. #define PluginDescriptorClassEND(className) \
  284. public: \
  285. static PluginHandle _instantiate(const PluginDescriptor*, HostDescriptor* host) \
  286. { \
  287. return new className(host); \
  288. } \
  289. static void _cleanup(PluginHandle handle) \
  290. { \
  291. delete (className*)handle; \
  292. }
  293. #define PluginDescriptorFILL(className) \
  294. className::_instantiate, \
  295. className::_cleanup, \
  296. className::_get_parameter_count, \
  297. className::_get_parameter_info, \
  298. className::_get_parameter_value, \
  299. className::_get_parameter_text, \
  300. className::_get_midi_program_count, \
  301. className::_get_midi_program_info, \
  302. className::_set_parameter_value, \
  303. className::_set_midi_program, \
  304. className::_set_custom_data, \
  305. className::_ui_show, \
  306. className::_ui_idle, \
  307. className::_ui_set_parameter_value, \
  308. className::_ui_set_midi_program, \
  309. className::_ui_set_custom_data, \
  310. className::_activate, \
  311. className::_deactivate, \
  312. className::_process
  313. #endif // __CARLA_NATIVE_HPP__