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.

517 lines
15KB

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