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.

535 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_PLUGIN_RENAMED:
  259. return "CALLBACK_PLUGIN_RENAMED";
  260. case CALLBACK_PARAMETER_VALUE_CHANGED:
  261. return "CALLBACK_PARAMETER_VALUE_CHANGED";
  262. case CALLBACK_PARAMETER_DEFAULT_CHANGED:
  263. return "CALLBACK_PARAMETER_DEFAULT_CHANGED";
  264. case CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED:
  265. return "CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED";
  266. case CALLBACK_PARAMETER_MIDI_CC_CHANGED:
  267. return "CALLBACK_PARAMETER_MIDI_CC_CHANGED";
  268. case CALLBACK_PROGRAM_CHANGED:
  269. return "CALLBACK_PROGRAM_CHANGED";
  270. case CALLBACK_MIDI_PROGRAM_CHANGED:
  271. return "CALLBACK_MIDI_PROGRAM_CHANGED";
  272. case CALLBACK_NOTE_ON:
  273. return "CALLBACK_NOTE_ON";
  274. case CALLBACK_NOTE_OFF:
  275. return "CALLBACK_NOTE_OFF";
  276. case CALLBACK_SHOW_GUI:
  277. return "CALLBACK_SHOW_GUI";
  278. case CALLBACK_UPDATE:
  279. return "CALLBACK_UPDATE";
  280. case CALLBACK_PATCHBAY_CLIENT_ADDED:
  281. return "CALLBACK_PATCHBAY_CLIENT_ADDED";
  282. case CALLBACK_PATCHBAY_CLIENT_REMOVED:
  283. return "CALLBACK_PATCHBAY_CLIENT_REMOVED";
  284. case CALLBACK_PATCHBAY_CLIENT_RENAMED:
  285. return "CALLBACK_PATCHBAY_CLIENT_RENAMED";
  286. case CALLBACK_PATCHBAY_PORT_ADDED:
  287. return "CALLBACK_PATCHBAY_PORT_ADDED";
  288. case CALLBACK_PATCHBAY_PORT_REMOVED:
  289. return "CALLBACK_PATCHBAY_PORT_REMOVED";
  290. case CALLBACK_PATCHBAY_PORT_RENAMED:
  291. return "CALLBACK_PATCHBAY_PORT_RENAMED";
  292. case CALLBACK_PATCHBAY_CONNECTION_ADDED:
  293. return "CALLBACK_PATCHBAY_CONNECTION_ADDED";
  294. case CALLBACK_PATCHBAY_CONNECTION_REMOVED:
  295. return "CALLBACK_PATCHBAY_CONNECTION_REMOVED";
  296. case CALLBACK_RELOAD_INFO:
  297. return "CALLBACK_RELOAD_INFO";
  298. case CALLBACK_RELOAD_PARAMETERS:
  299. return "CALLBACK_RELOAD_PARAMETERS";
  300. case CALLBACK_RELOAD_PROGRAMS:
  301. return "CALLBACK_RELOAD_PROGRAMS";
  302. case CALLBACK_RELOAD_ALL:
  303. return "CALLBACK_RELOAD_ALL";
  304. case CALLBACK_NSM_ANNOUNCE:
  305. return "CALLBACK_NSM_ANNOUNCE";
  306. case CALLBACK_NSM_OPEN1:
  307. return "CALLBACK_NSM_OPEN1";
  308. case CALLBACK_NSM_OPEN2:
  309. return "CALLBACK_NSM_OPEN2";
  310. case CALLBACK_NSM_SAVE:
  311. return "CALLBACK_NSM_SAVE";
  312. case CALLBACK_ERROR:
  313. return "CALLBACK_ERROR";
  314. case CALLBACK_QUIT:
  315. return "CALLBACK_QUIT";
  316. }
  317. carla_stderr("CarlaBackend::CallbackType2Str(%i) - invalid type", type);
  318. return nullptr;
  319. }
  320. static inline
  321. const char* ProcessMode2Str(const ProcessMode& mode)
  322. {
  323. switch (mode)
  324. {
  325. case PROCESS_MODE_SINGLE_CLIENT:
  326. return "PROCESS_MODE_SINGLE_CLIENT";
  327. case PROCESS_MODE_MULTIPLE_CLIENTS:
  328. return "PROCESS_MODE_MULTIPLE_CLIENTS";
  329. case PROCESS_MODE_CONTINUOUS_RACK:
  330. return "PROCESS_MODE_CONTINUOUS_RACK";
  331. case PROCESS_MODE_PATCHBAY:
  332. return "PROCESS_MODE_PATCHBAY";
  333. case PROCESS_MODE_BRIDGE:
  334. return "PROCESS_MODE_BRIDGE";
  335. }
  336. carla_stderr("CarlaBackend::ProcessModeType2Str(%i) - invalid type", mode);
  337. return nullptr;
  338. }
  339. // -------------------------------------------------
  340. static inline
  341. uintptr_t getAddressFromPointer(void* ptr)
  342. {
  343. carla_debug("CarlaBackend::getAddressFromPointer(%p)", ptr);
  344. CARLA_ASSERT(ptr != nullptr);
  345. uintptr_t* addr = (uintptr_t*)&ptr;
  346. return *addr;
  347. }
  348. static inline
  349. void* getPointerFromAddress(uintptr_t& addr)
  350. {
  351. CARLA_ASSERT(addr != 0);
  352. uintptr_t** const ptr = (uintptr_t**)&addr;
  353. return *ptr;
  354. }
  355. // -------------------------------------------------
  356. static inline
  357. const char* getPluginTypeAsString(const PluginType& type)
  358. {
  359. carla_debug("CarlaBackend::getPluginTypeAsString(%s)", PluginType2Str(type));
  360. switch (type)
  361. {
  362. case PLUGIN_NONE:
  363. return "NONE";
  364. case PLUGIN_INTERNAL:
  365. return "INTERNAL";
  366. case PLUGIN_LADSPA:
  367. return "LADSPA";
  368. case PLUGIN_DSSI:
  369. return "DSSI";
  370. case PLUGIN_LV2:
  371. return "LV2";
  372. case PLUGIN_VST:
  373. return "VST";
  374. case PLUGIN_GIG:
  375. return "GIG";
  376. case PLUGIN_SF2:
  377. return "SF2";
  378. case PLUGIN_SFZ:
  379. return "SFZ";
  380. }
  381. carla_stderr("CarlaBackend::getPluginTypeAsString(%i) - invalid type", type);
  382. return "NONE";
  383. }
  384. static inline
  385. PluginType getPluginTypeFromString(const char* const stype)
  386. {
  387. carla_debug("CarlaBackend::getPluginTypeFromString(%s)", stype);
  388. if (stype == nullptr)
  389. {
  390. carla_stderr("CarlaBackend::getPluginTypeFromString() - null string type");
  391. return PLUGIN_NONE;
  392. }
  393. if (std::strcmp(stype, "NONE") == 0)
  394. return PLUGIN_NONE;
  395. if (std::strcmp(stype, "INTERNAL") == 0 || std::strcmp(stype, "Internal") == 0)
  396. return PLUGIN_INTERNAL;
  397. if (std::strcmp(stype, "LADSPA") == 0)
  398. return PLUGIN_LADSPA;
  399. if (std::strcmp(stype, "DSSI") == 0)
  400. return PLUGIN_DSSI;
  401. if (std::strcmp(stype, "LV2") == 0)
  402. return PLUGIN_LV2;
  403. if (std::strcmp(stype, "VST") == 0)
  404. return PLUGIN_VST;
  405. if (std::strcmp(stype, "GIG") == 0)
  406. return PLUGIN_GIG;
  407. if (std::strcmp(stype, "SF2") == 0)
  408. return PLUGIN_SF2;
  409. if (std::strcmp(stype, "SFZ") == 0)
  410. return PLUGIN_SFZ;
  411. carla_stderr("CarlaBackend::getPluginTypeFromString(%s) - invalid string type", stype);
  412. return PLUGIN_NONE;
  413. }
  414. // -------------------------------------------------
  415. static inline
  416. PluginCategory getPluginCategoryFromName(const char* const name)
  417. {
  418. carla_debug("CarlaBackend::getPluginCategoryFromName(\"%s\")", name);
  419. CARLA_ASSERT(name);
  420. if (! name)
  421. return PLUGIN_CATEGORY_NONE;
  422. CarlaString sname(name);
  423. if (sname.isEmpty())
  424. return PLUGIN_CATEGORY_NONE;
  425. sname.toLower();
  426. // generic tags first
  427. if (sname.contains("delay"))
  428. return PLUGIN_CATEGORY_DELAY;
  429. if (sname.contains("reverb"))
  430. return PLUGIN_CATEGORY_DELAY;
  431. // filter
  432. if (sname.contains("filter"))
  433. return PLUGIN_CATEGORY_FILTER;
  434. // dynamics
  435. if (sname.contains("dynamics"))
  436. return PLUGIN_CATEGORY_DYNAMICS;
  437. if (sname.contains("amplifier"))
  438. return PLUGIN_CATEGORY_DYNAMICS;
  439. if (sname.contains("compressor"))
  440. return PLUGIN_CATEGORY_DYNAMICS;
  441. if (sname.contains("enhancer"))
  442. return PLUGIN_CATEGORY_DYNAMICS;
  443. if (sname.contains("exciter"))
  444. return PLUGIN_CATEGORY_DYNAMICS;
  445. if (sname.contains("gate"))
  446. return PLUGIN_CATEGORY_DYNAMICS;
  447. if (sname.contains("limiter"))
  448. return PLUGIN_CATEGORY_DYNAMICS;
  449. // modulator
  450. if (sname.contains("modulator"))
  451. return PLUGIN_CATEGORY_MODULATOR;
  452. if (sname.contains("chorus"))
  453. return PLUGIN_CATEGORY_MODULATOR;
  454. if (sname.contains("flanger"))
  455. return PLUGIN_CATEGORY_MODULATOR;
  456. if (sname.contains("phaser"))
  457. return PLUGIN_CATEGORY_MODULATOR;
  458. if (sname.contains("saturator"))
  459. return PLUGIN_CATEGORY_MODULATOR;
  460. // utility
  461. if (sname.contains("utility"))
  462. return PLUGIN_CATEGORY_UTILITY;
  463. if (sname.contains("analyzer"))
  464. return PLUGIN_CATEGORY_UTILITY;
  465. if (sname.contains("converter"))
  466. return PLUGIN_CATEGORY_UTILITY;
  467. if (sname.contains("deesser"))
  468. return PLUGIN_CATEGORY_UTILITY;
  469. if (sname.contains("mixer"))
  470. return PLUGIN_CATEGORY_UTILITY;
  471. // common tags
  472. if (sname.contains("verb"))
  473. return PLUGIN_CATEGORY_DELAY;
  474. if (sname.contains("eq"))
  475. return PLUGIN_CATEGORY_EQ;
  476. if (sname.contains("tool"))
  477. return PLUGIN_CATEGORY_UTILITY;
  478. return PLUGIN_CATEGORY_NONE;
  479. }
  480. CARLA_BACKEND_END_NAMESPACE
  481. #endif // __CARLA_BACKEND_UTILS_HPP__