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.

453 lines
12KB

  1. /*
  2. * Carla Backend utils
  3. * Copyright (C) 2011-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_BACKEND_UTILS_HPP__
  18. #define __CARLA_BACKEND_UTILS_HPP__
  19. #include "carla_backend.hpp"
  20. #include "carla_utils.hpp"
  21. CARLA_BACKEND_START_NAMESPACE
  22. // -------------------------------------------------
  23. static inline
  24. const char* BinaryType2Str(const BinaryType& type)
  25. {
  26. switch (type)
  27. {
  28. case BINARY_NONE:
  29. return "BINARY_NONE";
  30. case BINARY_POSIX32:
  31. return "BINARY_POSIX32";
  32. case BINARY_POSIX64:
  33. return "BINARY_POSIX64";
  34. case BINARY_WIN32:
  35. return "BINARY_WIN32";
  36. case BINARY_WIN64:
  37. return "BINARY_WIN64";
  38. case BINARY_OTHER:
  39. return "BINARY_OTHER";
  40. }
  41. qWarning("CarlaBackend::BinaryType2Str(%i) - invalid type", type);
  42. return nullptr;
  43. }
  44. static inline
  45. const char* PluginType2Str(const PluginType& type)
  46. {
  47. switch (type)
  48. {
  49. case PLUGIN_NONE:
  50. return "PLUGIN_NONE";
  51. #ifndef BUILD_BRIDGE
  52. case PLUGIN_INTERNAL:
  53. return "PLUGIN_INTERNAL";
  54. #endif
  55. case PLUGIN_LADSPA:
  56. return "PLUGIN_LADSPA";
  57. case PLUGIN_DSSI:
  58. return "PLUGIN_DSSI";
  59. case PLUGIN_LV2:
  60. return "PLUGIN_LV2";
  61. case PLUGIN_VST:
  62. return "PLUGIN_VST";
  63. #ifndef BUILD_BRIDGE
  64. case PLUGIN_GIG:
  65. return "PLUGIN_GIG";
  66. case PLUGIN_SF2:
  67. return "PLUGIN_SF2";
  68. case PLUGIN_SFZ:
  69. return "PLUGIN_SFZ";
  70. #endif
  71. }
  72. qWarning("CarlaBackend::PluginType2Str(%i) - invalid type", type);
  73. return nullptr;
  74. }
  75. static inline
  76. const char* PluginCategory2Str(const PluginCategory& category)
  77. {
  78. switch (category)
  79. {
  80. case PLUGIN_CATEGORY_NONE:
  81. return "PLUGIN_CATEGORY_NONE";
  82. case PLUGIN_CATEGORY_SYNTH:
  83. return "PLUGIN_CATEGORY_SYNTH";
  84. case PLUGIN_CATEGORY_DELAY:
  85. return "PLUGIN_CATEGORY_DELAY";
  86. case PLUGIN_CATEGORY_EQ:
  87. return "PLUGIN_CATEGORY_EQ";
  88. case PLUGIN_CATEGORY_FILTER:
  89. return "PLUGIN_CATEGORY_FILTER";
  90. case PLUGIN_CATEGORY_DYNAMICS:
  91. return "PLUGIN_CATEGORY_DYNAMICS";
  92. case PLUGIN_CATEGORY_MODULATOR:
  93. return "PLUGIN_CATEGORY_MODULATOR";
  94. case PLUGIN_CATEGORY_UTILITY:
  95. return "PLUGIN_CATEGORY_UTILITY";
  96. case PLUGIN_CATEGORY_OTHER:
  97. return "PLUGIN_CATEGORY_OTHER";
  98. }
  99. qWarning("CarlaBackend::PluginCategory2Str(%i) - invalid category", category);
  100. return nullptr;
  101. }
  102. static inline
  103. const char* ParameterType2Str(const ParameterType& type)
  104. {
  105. switch (type)
  106. {
  107. case PARAMETER_UNKNOWN:
  108. return "PARAMETER_UNKNOWN";
  109. case PARAMETER_INPUT:
  110. return "PARAMETER_INPUT";
  111. case PARAMETER_OUTPUT:
  112. return "PARAMETER_OUTPUT";
  113. case PARAMETER_LATENCY:
  114. return "PARAMETER_LATENCY";
  115. case PARAMETER_SAMPLE_RATE:
  116. return "PARAMETER_SAMPLE_RATE";
  117. #ifdef WANT_LV2
  118. case PARAMETER_LV2_FREEWHEEL:
  119. return "PARAMETER_LV2_FREEWHEEL";
  120. case PARAMETER_LV2_TIME:
  121. return "PARAMETER_LV2_TIME";
  122. #endif
  123. }
  124. qWarning("CarlaBackend::ParameterType2Str(%i) - invalid type", type);
  125. return nullptr;
  126. }
  127. static inline
  128. const char* InternalParametersIndex2Str(const InternalParametersIndex& index)
  129. {
  130. switch (index)
  131. {
  132. case PARAMETER_NULL:
  133. return "PARAMETER_NULL";
  134. case PARAMETER_ACTIVE:
  135. return "PARAMETER_ACTIVE";
  136. case PARAMETER_DRYWET:
  137. return "PARAMETER_DRYWET";
  138. case PARAMETER_VOLUME:
  139. return "PARAMETER_VOLUME";
  140. case PARAMETER_BALANCE_LEFT:
  141. return "PARAMETER_BALANCE_LEFT";
  142. case PARAMETER_BALANCE_RIGHT:
  143. return "PARAMETER_BALANCE_RIGHT";
  144. case PARAMETER_PANNING:
  145. return "PARAMETER_PANNING";
  146. case PARAMETER_MAX:
  147. return "PARAMETER_MAX";
  148. }
  149. qWarning("CarlaBackend::InternalParametersIndex2Str(%i) - invalid index", index);
  150. return nullptr;
  151. }
  152. static inline
  153. const char* OptionsType2Str(const OptionsType& type)
  154. {
  155. switch (type)
  156. {
  157. case OPTION_PROCESS_NAME:
  158. return "OPTION_PROCESS_NAME";
  159. case OPTION_PROCESS_MODE:
  160. return "OPTION_PROCESS_MODE";
  161. case OPTION_FORCE_STEREO:
  162. return "OPTION_FORCE_STEREO";
  163. case OPTION_PREFER_PLUGIN_BRIDGES:
  164. return "OPTION_PREFER_PLUGIN_BRIDGES";
  165. case OPTION_PREFER_UI_BRIDGES:
  166. return "OPTION_PREFER_UI_BRIDGES";
  167. #ifdef WANT_DSSI
  168. case OPTION_USE_DSSI_VST_CHUNKS:
  169. return "OPTION_USE_DSSI_VST_CHUNKS";
  170. #endif
  171. case OPTION_MAX_PARAMETERS:
  172. return "OPTION_MAX_PARAMETERS";
  173. case OPTION_OSC_UI_TIMEOUT:
  174. return "OPTION_OSC_UI_TIMEOUT";
  175. case OPTION_PREFERRED_BUFFER_SIZE:
  176. return "OPTION_PREFERRED_BUFFER_SIZE";
  177. case OPTION_PREFERRED_SAMPLE_RATE:
  178. return "OPTION_PREFERRED_SAMPLE_RATE";
  179. #ifndef BUILD_BRIDGE
  180. case OPTION_PATH_BRIDGE_NATIVE:
  181. return "OPTION_PATH_BRIDGE_NATIVE";
  182. case OPTION_PATH_BRIDGE_POSIX32:
  183. return "OPTION_PATH_BRIDGE_POSIX32";
  184. case OPTION_PATH_BRIDGE_POSIX64:
  185. return "OPTION_PATH_BRIDGE_POSIX64";
  186. case OPTION_PATH_BRIDGE_WIN32:
  187. return "OPTION_PATH_BRIDGE_WIN32";
  188. case OPTION_PATH_BRIDGE_WIN64:
  189. return "OPTION_PATH_BRIDGE_WIN64";
  190. #endif
  191. #ifdef WANT_LV2
  192. case OPTION_PATH_BRIDGE_LV2_GTK2:
  193. return "OPTION_PATH_BRIDGE_LV2_GTK2";
  194. case OPTION_PATH_BRIDGE_LV2_GTK3:
  195. return "OPTION_PATH_BRIDGE_LV2_GTK3";
  196. case OPTION_PATH_BRIDGE_LV2_QT4:
  197. return "OPTION_PATH_BRIDGE_LV2_QT4";
  198. case OPTION_PATH_BRIDGE_LV2_QT5:
  199. return "OPTION_PATH_BRIDGE_LV2_QT5";
  200. case OPTION_PATH_BRIDGE_LV2_COCOA:
  201. return "OPTION_PATH_BRIDGE_LV2_COCOA";
  202. case OPTION_PATH_BRIDGE_LV2_WINDOWS:
  203. return "OPTION_PATH_BRIDGE_LV2_WINDOWS";
  204. case OPTION_PATH_BRIDGE_LV2_X11:
  205. return "OPTION_PATH_BRIDGE_LV2_X11";
  206. #endif
  207. #ifdef WANT_VST
  208. case OPTION_PATH_BRIDGE_VST_COCOA:
  209. return "OPTION_PATH_BRIDGE_VST_COCOA";
  210. case OPTION_PATH_BRIDGE_VST_HWND:
  211. return "OPTION_PATH_BRIDGE_VST_HWND";
  212. case OPTION_PATH_BRIDGE_VST_X11:
  213. return "OPTION_PATH_BRIDGE_VST_X11";
  214. #endif
  215. }
  216. qWarning("CarlaBackend::OptionsType2Str(%i) - invalid type", type);
  217. return nullptr;
  218. }
  219. static inline
  220. const char* CallbackType2Str(const CallbackType& type)
  221. {
  222. switch (type)
  223. {
  224. case CALLBACK_DEBUG:
  225. return "CALLBACK_DEBUG";
  226. case CALLBACK_PLUGIN_ADDED:
  227. return "CALLBACK_PLUGIN_ADDED";
  228. case CALLBACK_PLUGIN_REMOVED:
  229. return "CALLBACK_PLUGIN_REMOVED";
  230. case CALLBACK_PARAMETER_VALUE_CHANGED:
  231. return "CALLBACK_PARAMETER_VALUE_CHANGED";
  232. case CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED:
  233. return "CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED";
  234. case CALLBACK_PARAMETER_MIDI_CC_CHANGED:
  235. return "CALLBACK_PARAMETER_MIDI_CC_CHANGED";
  236. case CALLBACK_PROGRAM_CHANGED:
  237. return "CALLBACK_PROGRAM_CHANGED";
  238. case CALLBACK_MIDI_PROGRAM_CHANGED:
  239. return "CALLBACK_MIDI_PROGRAM_CHANGED";
  240. case CALLBACK_NOTE_ON:
  241. return "CALLBACK_NOTE_ON";
  242. case CALLBACK_NOTE_OFF:
  243. return "CALLBACK_NOTE_OFF";
  244. case CALLBACK_SHOW_GUI:
  245. return "CALLBACK_SHOW_GUI";
  246. case CALLBACK_UPDATE:
  247. return "CALLBACK_UPDATE";
  248. case CALLBACK_RELOAD_INFO:
  249. return "CALLBACK_RELOAD_INFO";
  250. case CALLBACK_RELOAD_PARAMETERS:
  251. return "CALLBACK_RELOAD_PARAMETERS";
  252. case CALLBACK_RELOAD_PROGRAMS:
  253. return "CALLBACK_RELOAD_PROGRAMS";
  254. case CALLBACK_RELOAD_ALL:
  255. return "CALLBACK_RELOAD_ALL";
  256. case CALLBACK_NSM_ANNOUNCE:
  257. return "CALLBACK_NSM_ANNOUNCE";
  258. case CALLBACK_NSM_OPEN1:
  259. return "CALLBACK_NSM_OPEN1";
  260. case CALLBACK_NSM_OPEN2:
  261. return "CALLBACK_NSM_OPEN2";
  262. case CALLBACK_NSM_SAVE:
  263. return "CALLBACK_NSM_SAVE";
  264. case CALLBACK_ERROR:
  265. return "CALLBACK_ERROR";
  266. case CALLBACK_QUIT:
  267. return "CALLBACK_QUIT";
  268. }
  269. qWarning("CarlaBackend::CallbackType2Str(%i) - invalid type", type);
  270. return nullptr;
  271. }
  272. static inline
  273. const char* ProcessMode2Str(const ProcessMode& mode)
  274. {
  275. switch (mode)
  276. {
  277. case PROCESS_MODE_SINGLE_CLIENT:
  278. return "PROCESS_MODE_SINGLE_CLIENT";
  279. case PROCESS_MODE_MULTIPLE_CLIENTS:
  280. return "PROCESS_MODE_MULTIPLE_CLIENTS";
  281. case PROCESS_MODE_CONTINUOUS_RACK:
  282. return "PROCESS_MODE_CONTINUOUS_RACK";
  283. case PROCESS_MODE_PATCHBAY:
  284. return "PROCESS_MODE_PATCHBAY";
  285. case PROCESS_MODE_BRIDGE:
  286. return "PROCESS_MODE_BRIDGE";
  287. }
  288. qWarning("CarlaBackend::ProcessModeType2Str(%i) - invalid type", mode);
  289. return nullptr;
  290. }
  291. // -------------------------------------------------
  292. static inline
  293. uintptr_t getAddressFromPointer(void* ptr)
  294. {
  295. qDebug("CarlaBackend::getAddressFromPointer(%p)", ptr);
  296. CARLA_ASSERT(ptr != nullptr);
  297. uintptr_t* addr = (uintptr_t*)&ptr;
  298. return *addr;
  299. }
  300. static inline
  301. void* getPointerFromAddress(uintptr_t& addr)
  302. {
  303. CARLA_ASSERT(addr != 0);
  304. uintptr_t** const ptr = (uintptr_t**)&addr;
  305. return *ptr;
  306. }
  307. // -------------------------------------------------
  308. static inline
  309. const char* getPluginTypeString(const PluginType& type)
  310. {
  311. qDebug("CarlaBackend::getPluginTypeString(%s)", PluginType2Str(type));
  312. switch (type)
  313. {
  314. case PLUGIN_NONE:
  315. return "NONE";
  316. #ifndef BUILD_BRIDGE
  317. case PLUGIN_INTERNAL:
  318. return "INTERNAL";
  319. #endif
  320. case PLUGIN_LADSPA:
  321. return "LADSPA";
  322. case PLUGIN_DSSI:
  323. return "DSSI";
  324. case PLUGIN_LV2:
  325. return "LV2";
  326. case PLUGIN_VST:
  327. return "VST";
  328. #ifndef BUILD_BRIDGE
  329. case PLUGIN_GIG:
  330. return "GIG";
  331. case PLUGIN_SF2:
  332. return "SF2";
  333. case PLUGIN_SFZ:
  334. return "SFZ";
  335. #endif
  336. }
  337. return "NONE";
  338. }
  339. // -------------------------------------------------
  340. static inline
  341. PluginCategory getPluginCategoryFromName(const char* const name)
  342. {
  343. qDebug("CarlaBackend::getPluginCategoryFromName(\"%s\")", name);
  344. CARLA_ASSERT(name);
  345. if (! name)
  346. return PLUGIN_CATEGORY_NONE;
  347. CarlaString sname(name);
  348. if (sname.isEmpty())
  349. return PLUGIN_CATEGORY_NONE;
  350. sname.toLower();
  351. // generic tags first
  352. if (sname.contains("delay"))
  353. return PLUGIN_CATEGORY_DELAY;
  354. if (sname.contains("reverb"))
  355. return PLUGIN_CATEGORY_DELAY;
  356. // filter
  357. if (sname.contains("filter"))
  358. return PLUGIN_CATEGORY_FILTER;
  359. // dynamics
  360. if (sname.contains("dynamics"))
  361. return PLUGIN_CATEGORY_DYNAMICS;
  362. if (sname.contains("amplifier"))
  363. return PLUGIN_CATEGORY_DYNAMICS;
  364. if (sname.contains("compressor"))
  365. return PLUGIN_CATEGORY_DYNAMICS;
  366. if (sname.contains("enhancer"))
  367. return PLUGIN_CATEGORY_DYNAMICS;
  368. if (sname.contains("exciter"))
  369. return PLUGIN_CATEGORY_DYNAMICS;
  370. if (sname.contains("gate"))
  371. return PLUGIN_CATEGORY_DYNAMICS;
  372. if (sname.contains("limiter"))
  373. return PLUGIN_CATEGORY_DYNAMICS;
  374. // modulator
  375. if (sname.contains("modulator"))
  376. return PLUGIN_CATEGORY_MODULATOR;
  377. if (sname.contains("chorus"))
  378. return PLUGIN_CATEGORY_MODULATOR;
  379. if (sname.contains("flanger"))
  380. return PLUGIN_CATEGORY_MODULATOR;
  381. if (sname.contains("phaser"))
  382. return PLUGIN_CATEGORY_MODULATOR;
  383. if (sname.contains("saturator"))
  384. return PLUGIN_CATEGORY_MODULATOR;
  385. // utility
  386. if (sname.contains("utility"))
  387. return PLUGIN_CATEGORY_UTILITY;
  388. if (sname.contains("analyzer"))
  389. return PLUGIN_CATEGORY_UTILITY;
  390. if (sname.contains("converter"))
  391. return PLUGIN_CATEGORY_UTILITY;
  392. if (sname.contains("deesser"))
  393. return PLUGIN_CATEGORY_UTILITY;
  394. if (sname.contains("mixer"))
  395. return PLUGIN_CATEGORY_UTILITY;
  396. // common tags
  397. if (sname.contains("verb"))
  398. return PLUGIN_CATEGORY_DELAY;
  399. if (sname.contains("eq"))
  400. return PLUGIN_CATEGORY_EQ;
  401. if (sname.contains("tool"))
  402. return PLUGIN_CATEGORY_UTILITY;
  403. return PLUGIN_CATEGORY_NONE;
  404. }
  405. CARLA_BACKEND_END_NAMESPACE
  406. #endif // __CARLA_BACKEND_UTILS_HPP__