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.

carla_native.hpp 10KB

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