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.

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