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.

443 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_PARAMETER_VALUE_CHANGED:
  223. return "CALLBACK_PARAMETER_VALUE_CHANGED";
  224. case CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED:
  225. return "CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED";
  226. case CALLBACK_PARAMETER_MIDI_CC_CHANGED:
  227. return "CALLBACK_PARAMETER_MIDI_CC_CHANGED";
  228. case CALLBACK_PROGRAM_CHANGED:
  229. return "CALLBACK_PROGRAM_CHANGED";
  230. case CALLBACK_MIDI_PROGRAM_CHANGED:
  231. return "CALLBACK_MIDI_PROGRAM_CHANGED";
  232. case CALLBACK_NOTE_ON:
  233. return "CALLBACK_NOTE_ON";
  234. case CALLBACK_NOTE_OFF:
  235. return "CALLBACK_NOTE_OFF";
  236. case CALLBACK_SHOW_GUI:
  237. return "CALLBACK_SHOW_GUI";
  238. case CALLBACK_UPDATE:
  239. return "CALLBACK_UPDATE";
  240. case CALLBACK_RELOAD_INFO:
  241. return "CALLBACK_RELOAD_INFO";
  242. case CALLBACK_RELOAD_PARAMETERS:
  243. return "CALLBACK_RELOAD_PARAMETERS";
  244. case CALLBACK_RELOAD_PROGRAMS:
  245. return "CALLBACK_RELOAD_PROGRAMS";
  246. case CALLBACK_RELOAD_ALL:
  247. return "CALLBACK_RELOAD_ALL";
  248. case CALLBACK_NSM_ANNOUNCE:
  249. return "CALLBACK_NSM_ANNOUNCE";
  250. case CALLBACK_NSM_OPEN1:
  251. return "CALLBACK_NSM_OPEN1";
  252. case CALLBACK_NSM_OPEN2:
  253. return "CALLBACK_NSM_OPEN2";
  254. case CALLBACK_NSM_SAVE:
  255. return "CALLBACK_NSM_SAVE";
  256. case CALLBACK_ERROR:
  257. return "CALLBACK_ERROR";
  258. case CALLBACK_QUIT:
  259. return "CALLBACK_QUIT";
  260. }
  261. qWarning("CarlaBackend::CallbackType2Str(%i) - invalid type", type);
  262. return nullptr;
  263. }
  264. static inline
  265. const char* ProcessMode2Str(const ProcessMode& mode)
  266. {
  267. switch (mode)
  268. {
  269. case PROCESS_MODE_SINGLE_CLIENT:
  270. return "PROCESS_MODE_SINGLE_CLIENT";
  271. case PROCESS_MODE_MULTIPLE_CLIENTS:
  272. return "PROCESS_MODE_MULTIPLE_CLIENTS";
  273. case PROCESS_MODE_CONTINUOUS_RACK:
  274. return "PROCESS_MODE_CONTINUOUS_RACK";
  275. case PROCESS_MODE_PATCHBAY:
  276. return "PROCESS_MODE_PATCHBAY";
  277. }
  278. qWarning("CarlaBackend::ProcessModeType2Str(%i) - invalid type", mode);
  279. return nullptr;
  280. }
  281. // -------------------------------------------------
  282. static inline
  283. uintptr_t getAddressFromPointer(void* ptr)
  284. {
  285. qDebug("CarlaBackend::getAddressFromPointer(%p)", ptr);
  286. CARLA_ASSERT(ptr != nullptr);
  287. uintptr_t* addr = (uintptr_t*)&ptr;
  288. return *addr;
  289. }
  290. static inline
  291. void* getPointerFromAddress(uintptr_t& addr)
  292. {
  293. CARLA_ASSERT(addr != 0);
  294. uintptr_t** const ptr = (uintptr_t**)&addr;
  295. return *ptr;
  296. }
  297. // -------------------------------------------------
  298. static inline
  299. const char* getPluginTypeString(const PluginType& type)
  300. {
  301. qDebug("CarlaBackend::getPluginTypeString(%s)", PluginType2Str(type));
  302. switch (type)
  303. {
  304. case PLUGIN_NONE:
  305. return "NONE";
  306. #ifndef BUILD_BRIDGE
  307. case PLUGIN_INTERNAL:
  308. return "INTERNAL";
  309. #endif
  310. case PLUGIN_LADSPA:
  311. return "LADSPA";
  312. case PLUGIN_DSSI:
  313. return "DSSI";
  314. case PLUGIN_LV2:
  315. return "LV2";
  316. case PLUGIN_VST:
  317. return "VST";
  318. #ifndef BUILD_BRIDGE
  319. case PLUGIN_GIG:
  320. return "GIG";
  321. case PLUGIN_SF2:
  322. return "SF2";
  323. case PLUGIN_SFZ:
  324. return "SFZ";
  325. #endif
  326. }
  327. return "NONE";
  328. }
  329. // -------------------------------------------------
  330. static inline
  331. PluginCategory getPluginCategoryFromName(const char* const name)
  332. {
  333. qDebug("CarlaBackend::getPluginCategoryFromName(\"%s\")", name);
  334. CARLA_ASSERT(name);
  335. if (! name)
  336. return PLUGIN_CATEGORY_NONE;
  337. CarlaString sname(name);
  338. if (sname.isEmpty())
  339. return PLUGIN_CATEGORY_NONE;
  340. sname.toLower();
  341. // generic tags first
  342. if (sname.contains("delay"))
  343. return PLUGIN_CATEGORY_DELAY;
  344. if (sname.contains("reverb"))
  345. return PLUGIN_CATEGORY_DELAY;
  346. // filter
  347. if (sname.contains("filter"))
  348. return PLUGIN_CATEGORY_FILTER;
  349. // dynamics
  350. if (sname.contains("dynamics"))
  351. return PLUGIN_CATEGORY_DYNAMICS;
  352. if (sname.contains("amplifier"))
  353. return PLUGIN_CATEGORY_DYNAMICS;
  354. if (sname.contains("compressor"))
  355. return PLUGIN_CATEGORY_DYNAMICS;
  356. if (sname.contains("enhancer"))
  357. return PLUGIN_CATEGORY_DYNAMICS;
  358. if (sname.contains("exciter"))
  359. return PLUGIN_CATEGORY_DYNAMICS;
  360. if (sname.contains("gate"))
  361. return PLUGIN_CATEGORY_DYNAMICS;
  362. if (sname.contains("limiter"))
  363. return PLUGIN_CATEGORY_DYNAMICS;
  364. // modulator
  365. if (sname.contains("modulator"))
  366. return PLUGIN_CATEGORY_MODULATOR;
  367. if (sname.contains("chorus"))
  368. return PLUGIN_CATEGORY_MODULATOR;
  369. if (sname.contains("flanger"))
  370. return PLUGIN_CATEGORY_MODULATOR;
  371. if (sname.contains("phaser"))
  372. return PLUGIN_CATEGORY_MODULATOR;
  373. if (sname.contains("saturator"))
  374. return PLUGIN_CATEGORY_MODULATOR;
  375. // utility
  376. if (sname.contains("utility"))
  377. return PLUGIN_CATEGORY_UTILITY;
  378. if (sname.contains("analyzer"))
  379. return PLUGIN_CATEGORY_UTILITY;
  380. if (sname.contains("converter"))
  381. return PLUGIN_CATEGORY_UTILITY;
  382. if (sname.contains("deesser"))
  383. return PLUGIN_CATEGORY_UTILITY;
  384. if (sname.contains("mixer"))
  385. return PLUGIN_CATEGORY_UTILITY;
  386. // common tags
  387. if (sname.contains("verb"))
  388. return PLUGIN_CATEGORY_DELAY;
  389. if (sname.contains("eq"))
  390. return PLUGIN_CATEGORY_EQ;
  391. if (sname.contains("tool"))
  392. return PLUGIN_CATEGORY_UTILITY;
  393. return PLUGIN_CATEGORY_NONE;
  394. }
  395. CARLA_BACKEND_END_NAMESPACE
  396. #endif // __CARLA_BACKEND_UTILS_HPP__