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.

522 lines
16KB

  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 doc/GPL.txt file.
  16. */
  17. #ifndef CARLA_BACKEND_UTILS_HPP_INCLUDED
  18. #define CARLA_BACKEND_UTILS_HPP_INCLUDED
  19. #include "CarlaBackend.h"
  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_BUFFERS:
  29. return "PLUGIN_OPTION_FIXED_BUFFERS";
  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 option", 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_AU:
  90. return "PLUGIN_AU";
  91. case PLUGIN_CSOUND:
  92. return "PLUGIN_CSOUND";
  93. case PLUGIN_GIG:
  94. return "PLUGIN_GIG";
  95. case PLUGIN_SF2:
  96. return "PLUGIN_SF2";
  97. case PLUGIN_SFZ:
  98. return "PLUGIN_SFZ";
  99. }
  100. carla_stderr("CarlaBackend::PluginType2Str(%i) - invalid type", type);
  101. return nullptr;
  102. }
  103. static inline
  104. const char* PluginCategory2Str(const PluginCategory category)
  105. {
  106. switch (category)
  107. {
  108. case PLUGIN_CATEGORY_NONE:
  109. return "PLUGIN_CATEGORY_NONE";
  110. case PLUGIN_CATEGORY_SYNTH:
  111. return "PLUGIN_CATEGORY_SYNTH";
  112. case PLUGIN_CATEGORY_DELAY:
  113. return "PLUGIN_CATEGORY_DELAY";
  114. case PLUGIN_CATEGORY_EQ:
  115. return "PLUGIN_CATEGORY_EQ";
  116. case PLUGIN_CATEGORY_FILTER:
  117. return "PLUGIN_CATEGORY_FILTER";
  118. case PLUGIN_CATEGORY_DISTORTION:
  119. return "PLUGIN_CATEGORY_DISTORTION";
  120. case PLUGIN_CATEGORY_DYNAMICS:
  121. return "PLUGIN_CATEGORY_DYNAMICS";
  122. case PLUGIN_CATEGORY_MODULATOR:
  123. return "PLUGIN_CATEGORY_MODULATOR";
  124. case PLUGIN_CATEGORY_UTILITY:
  125. return "PLUGIN_CATEGORY_UTILITY";
  126. case PLUGIN_CATEGORY_OTHER:
  127. return "PLUGIN_CATEGORY_OTHER";
  128. }
  129. carla_stderr("CarlaBackend::PluginCategory2Str(%i) - invalid category", category);
  130. return nullptr;
  131. }
  132. static inline
  133. const char* InternalParameterIndex2Str(const InternalParameterIndex index)
  134. {
  135. switch (index)
  136. {
  137. case PARAMETER_NULL:
  138. return "PARAMETER_NULL";
  139. case PARAMETER_ACTIVE:
  140. return "PARAMETER_ACTIVE";
  141. case PARAMETER_DRYWET:
  142. return "PARAMETER_DRYWET";
  143. case PARAMETER_VOLUME:
  144. return "PARAMETER_VOLUME";
  145. case PARAMETER_BALANCE_LEFT:
  146. return "PARAMETER_BALANCE_LEFT";
  147. case PARAMETER_BALANCE_RIGHT:
  148. return "PARAMETER_BALANCE_RIGHT";
  149. case PARAMETER_PANNING:
  150. return "PARAMETER_PANNING";
  151. case PARAMETER_CTRL_CHANNEL:
  152. return "PARAMETER_CTRL_CHANNEL";
  153. case PARAMETER_MAX:
  154. return "PARAMETER_MAX";
  155. }
  156. carla_stderr("CarlaBackend::InternalParameterIndex2Str(%i) - invalid index", index);
  157. return nullptr;
  158. }
  159. static inline
  160. const char* EngineCallbackOpcode2Str(const EngineCallbackOpcode opcode)
  161. {
  162. switch (opcode)
  163. {
  164. case ENGINE_CALLBACK_DEBUG:
  165. return "ENGINE_CALLBACK_DEBUG";
  166. case ENGINE_CALLBACK_PLUGIN_ADDED:
  167. return "ENGINE_CALLBACK_PLUGIN_ADDED";
  168. case ENGINE_CALLBACK_PLUGIN_REMOVED:
  169. return "ENGINE_CALLBACK_PLUGIN_REMOVED";
  170. case ENGINE_CALLBACK_PLUGIN_RENAMED:
  171. return "ENGINE_CALLBACK_PLUGIN_RENAMED";
  172. case ENGINE_CALLBACK_PLUGIN_UNAVAILABLE:
  173. return "ENGINE_CALLBACK_PLUGIN_UNAVAILABLE";
  174. case ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED:
  175. return "ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED";
  176. case ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED:
  177. return "ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED";
  178. case ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED:
  179. return "ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED";
  180. case ENGINE_CALLBACK_PARAMETER_MIDI_CC_CHANGED:
  181. return "ENGINE_CALLBACK_PARAMETER_MIDI_CC_CHANGED";
  182. case ENGINE_CALLBACK_PROGRAM_CHANGED:
  183. return "ENGINE_CALLBACK_PROGRAM_CHANGED";
  184. case ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED:
  185. return "ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED";
  186. case ENGINE_CALLBACK_UI_STATE_CHANGED:
  187. return "ENGINE_CALLBACK_UI_STATE_CHANGED";
  188. case ENGINE_CALLBACK_NOTE_ON:
  189. return "ENGINE_CALLBACK_NOTE_ON";
  190. case ENGINE_CALLBACK_NOTE_OFF:
  191. return "ENGINE_CALLBACK_NOTE_OFF";
  192. case ENGINE_CALLBACK_UPDATE:
  193. return "ENGINE_CALLBACK_UPDATE";
  194. case ENGINE_CALLBACK_RELOAD_INFO:
  195. return "ENGINE_CALLBACK_RELOAD_INFO";
  196. case ENGINE_CALLBACK_RELOAD_PARAMETERS:
  197. return "ENGINE_CALLBACK_RELOAD_PARAMETERS";
  198. case ENGINE_CALLBACK_RELOAD_PROGRAMS:
  199. return "ENGINE_CALLBACK_RELOAD_PROGRAMS";
  200. case ENGINE_CALLBACK_RELOAD_ALL:
  201. return "ENGINE_CALLBACK_RELOAD_ALL";
  202. case ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED:
  203. return "ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED";
  204. case ENGINE_CALLBACK_PATCHBAY_CLIENT_REMOVED:
  205. return "ENGINE_CALLBACK_PATCHBAY_CLIENT_REMOVED";
  206. case ENGINE_CALLBACK_PATCHBAY_CLIENT_RENAMED:
  207. return "ENGINE_CALLBACK_PATCHBAY_CLIENT_RENAMED";
  208. case ENGINE_CALLBACK_PATCHBAY_CLIENT_ICON_CHANGED:
  209. return "ENGINE_CALLBACK_PATCHBAY_CLIENT_ICON_CHANGED";
  210. case ENGINE_CALLBACK_PATCHBAY_PORT_ADDED:
  211. return "ENGINE_CALLBACK_PATCHBAY_PORT_ADDED";
  212. case ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED:
  213. return "ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED";
  214. case ENGINE_CALLBACK_PATCHBAY_PORT_RENAMED:
  215. return "ENGINE_CALLBACK_PATCHBAY_PORT_RENAMED";
  216. case ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED:
  217. return "ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED";
  218. case ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED:
  219. return "ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED";
  220. case ENGINE_CALLBACK_ENGINE_STARTED:
  221. return "ENGINE_CALLBACK_ENGINE_STARTED";
  222. case ENGINE_CALLBACK_ENGINE_STOPPED:
  223. return "ENGINE_CALLBACK_ENGINE_STOPPED";
  224. case ENGINE_CALLBACK_PROCESS_MODE_CHANGED:
  225. return "ENGINE_CALLBACK_PROCESS_MODE_CHANGED";
  226. case ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED:
  227. return "ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED";
  228. case ENGINE_CALLBACK_BUFFER_SIZE_CHANGED:
  229. return "ENGINE_CALLBACK_BUFFER_SIZE_CHANGED";
  230. case ENGINE_CALLBACK_SAMPLE_RATE_CHANGED:
  231. return "ENGINE_CALLBACK_SAMPLE_RATE_CHANGED";
  232. case ENGINE_CALLBACK_INFO:
  233. return "ENGINE_CALLBACK_INFO";
  234. case ENGINE_CALLBACK_ERROR:
  235. return "ENGINE_CALLBACK_ERROR";
  236. case ENGINE_CALLBACK_QUIT:
  237. return "ENGINE_CALLBACK_QUIT";
  238. }
  239. carla_stderr("CarlaBackend::EngineCallbackOpcode2Str(%i) - invalid opcode", opcode);
  240. return nullptr;
  241. }
  242. static inline
  243. const char* EngineOption2Str(const EngineOption option)
  244. {
  245. switch (option)
  246. {
  247. case ENGINE_OPTION_DEBUG:
  248. return "ENGINE_OPTION_DEBUG";
  249. case ENGINE_OPTION_PROCESS_MODE:
  250. return "ENGINE_OPTION_PROCESS_MODE";
  251. case ENGINE_OPTION_TRANSPORT_MODE:
  252. return "ENGINE_OPTION_TRANSPORT_MODE";
  253. case ENGINE_OPTION_FORCE_STEREO:
  254. return "ENGINE_OPTION_FORCE_STEREO";
  255. case ENGINE_OPTION_PREFER_PLUGIN_BRIDGES:
  256. return "ENGINE_OPTION_PREFER_PLUGIN_BRIDGES";
  257. case ENGINE_OPTION_PREFER_UI_BRIDGES:
  258. return "ENGINE_OPTION_PREFER_UI_BRIDGES";
  259. case ENGINE_OPTION_UIS_ALWAYS_ON_TOP:
  260. return "ENGINE_OPTION_UIS_ALWAYS_ON_TOP";
  261. case ENGINE_OPTION_MAX_PARAMETERS:
  262. return "ENGINE_OPTION_MAX_PARAMETERS";
  263. case ENGINE_OPTION_UI_BRIDGES_TIMEOUT:
  264. return "ENGINE_OPTION_UI_BRIDGES_TIMEOUT";
  265. case ENGINE_OPTION_AUDIO_NUM_PERIODS:
  266. return "ENGINE_OPTION_AUDIO_NUM_PERIODS";
  267. case ENGINE_OPTION_AUDIO_BUFFER_SIZE:
  268. return "ENGINE_OPTION_AUDIO_BUFFER_SIZE";
  269. case ENGINE_OPTION_AUDIO_SAMPLE_RATE:
  270. return "ENGINE_OPTION_AUDIO_SAMPLE_RATE";
  271. case ENGINE_OPTION_AUDIO_DEVICE:
  272. return "ENGINE_OPTION_AUDIO_DEVICE";
  273. case ENGINE_OPTION_PATH_BINARIES:
  274. return "ENGINE_OPTION_PATH_BINARIES";
  275. case ENGINE_OPTION_PATH_RESOURCES:
  276. return "ENGINE_OPTION_PATH_RESOURCES";
  277. }
  278. carla_stderr("CarlaBackend::EngineOption2Str(%i) - invalid option", option);
  279. return nullptr;
  280. }
  281. static inline
  282. const char* EngineProcessMode2Str(const EngineProcessMode mode)
  283. {
  284. switch (mode)
  285. {
  286. case ENGINE_PROCESS_MODE_SINGLE_CLIENT:
  287. return "ENGINE_PROCESS_MODE_SINGLE_CLIENT";
  288. case ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS:
  289. return "ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS";
  290. case ENGINE_PROCESS_MODE_CONTINUOUS_RACK:
  291. return "ENGINE_PROCESS_MODE_CONTINUOUS_RACK";
  292. case ENGINE_PROCESS_MODE_PATCHBAY:
  293. return "ENGINE_PROCESS_MODE_PATCHBAY";
  294. case ENGINE_PROCESS_MODE_BRIDGE:
  295. return "ENGINE_PROCESS_MODE_BRIDGE";
  296. }
  297. carla_stderr("CarlaBackend::EngineProcessMode2Str(%i) - invalid mode", mode);
  298. return nullptr;
  299. }
  300. static inline
  301. const char* EngineTransportMode2Str(const EngineTransportMode mode)
  302. {
  303. switch (mode)
  304. {
  305. case ENGINE_TRANSPORT_MODE_INTERNAL:
  306. return "ENGINE_TRANSPORT_MODE_INTERNAL";
  307. case ENGINE_TRANSPORT_MODE_JACK:
  308. return "ENGINE_TRANSPORT_MODE_JACK";
  309. case ENGINE_TRANSPORT_MODE_PLUGIN:
  310. return "ENGINE_TRANSPORT_MODE_PLUGIN";
  311. case ENGINE_TRANSPORT_MODE_BRIDGE:
  312. return "ENGINE_TRANSPORT_MODE_BRIDGE";
  313. }
  314. carla_stderr("CarlaBackend::EngineTransportMode2Str(%i) - invalid mode", mode);
  315. return nullptr;
  316. }
  317. // -----------------------------------------------------------------------
  318. static inline
  319. uintptr_t getAddressFromPointer(void* ptr)
  320. {
  321. CARLA_SAFE_ASSERT_RETURN(ptr != nullptr, 0);
  322. uintptr_t* const addr((uintptr_t*)&ptr);
  323. return *addr;
  324. }
  325. template<typename T>
  326. static inline
  327. T* getPointerFromAddress(uintptr_t& addr)
  328. {
  329. CARLA_SAFE_ASSERT_RETURN(addr != 0, nullptr);
  330. T** const ptr((T**)&addr);
  331. return *ptr;
  332. }
  333. // -----------------------------------------------------------------------
  334. static inline
  335. const char* getPluginTypeAsString(const PluginType type)
  336. {
  337. carla_debug("CarlaBackend::getPluginTypeAsString(%i:%s)", type, PluginType2Str(type));
  338. switch (type)
  339. {
  340. case PLUGIN_NONE:
  341. return "NONE";
  342. case PLUGIN_INTERNAL:
  343. return "INTERNAL";
  344. case PLUGIN_LADSPA:
  345. return "LADSPA";
  346. case PLUGIN_DSSI:
  347. return "DSSI";
  348. case PLUGIN_LV2:
  349. return "LV2";
  350. case PLUGIN_VST:
  351. return "VST";
  352. case PLUGIN_AU:
  353. return "AU";
  354. case PLUGIN_CSOUND:
  355. return "CSOUND";
  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 ctype)
  368. {
  369. CARLA_SAFE_ASSERT_RETURN(ctype != nullptr && ctype[0] != '\0', PLUGIN_NONE);
  370. carla_debug("CarlaBackend::getPluginTypeFromString(\"%s\")", ctype);
  371. CarlaString stype(ctype);
  372. stype.toLower();
  373. if (stype.isEmpty() || stype == "none")
  374. return PLUGIN_NONE;
  375. if (stype == "internal")
  376. return PLUGIN_INTERNAL;
  377. if (stype == "ladspa")
  378. return PLUGIN_LADSPA;
  379. if (stype == "dssi")
  380. return PLUGIN_DSSI;
  381. if (stype == "lv2")
  382. return PLUGIN_LV2;
  383. if (stype == "vst")
  384. return PLUGIN_VST;
  385. if (stype == "au")
  386. return PLUGIN_AU;
  387. if (stype == "csound")
  388. return PLUGIN_CSOUND;
  389. if (stype == "gig")
  390. return PLUGIN_GIG;
  391. if (stype == "sf2")
  392. return PLUGIN_SF2;
  393. if (stype == "sfz")
  394. return PLUGIN_SFZ;
  395. carla_stderr("CarlaBackend::getPluginTypeFromString(\"%s\") - invalid string type", ctype);
  396. return PLUGIN_NONE;
  397. }
  398. // -----------------------------------------------------------------------
  399. static inline
  400. PluginCategory getPluginCategoryFromName(const char* const name)
  401. {
  402. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', PLUGIN_CATEGORY_NONE);
  403. carla_debug("CarlaBackend::getPluginCategoryFromName(\"%s\")", name);
  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. // distortion
  417. if (sname.contains("distortion"))
  418. return PLUGIN_CATEGORY_DISTORTION;
  419. // dynamics
  420. if (sname.contains("dynamics"))
  421. return PLUGIN_CATEGORY_DYNAMICS;
  422. if (sname.contains("amplifier"))
  423. return PLUGIN_CATEGORY_DYNAMICS;
  424. if (sname.contains("compressor"))
  425. return PLUGIN_CATEGORY_DYNAMICS;
  426. if (sname.contains("enhancer"))
  427. return PLUGIN_CATEGORY_DYNAMICS;
  428. if (sname.contains("exciter"))
  429. return PLUGIN_CATEGORY_DYNAMICS;
  430. if (sname.contains("gate"))
  431. return PLUGIN_CATEGORY_DYNAMICS;
  432. if (sname.contains("limiter"))
  433. return PLUGIN_CATEGORY_DYNAMICS;
  434. // modulator
  435. if (sname.contains("modulator"))
  436. return PLUGIN_CATEGORY_MODULATOR;
  437. if (sname.contains("chorus"))
  438. return PLUGIN_CATEGORY_MODULATOR;
  439. if (sname.contains("flanger"))
  440. return PLUGIN_CATEGORY_MODULATOR;
  441. if (sname.contains("phaser"))
  442. return PLUGIN_CATEGORY_MODULATOR;
  443. if (sname.contains("saturator"))
  444. return PLUGIN_CATEGORY_MODULATOR;
  445. // utility
  446. if (sname.contains("utility"))
  447. return PLUGIN_CATEGORY_UTILITY;
  448. if (sname.contains("analyzer"))
  449. return PLUGIN_CATEGORY_UTILITY;
  450. if (sname.contains("converter"))
  451. return PLUGIN_CATEGORY_UTILITY;
  452. if (sname.contains("deesser"))
  453. return PLUGIN_CATEGORY_UTILITY;
  454. if (sname.contains("mixer"))
  455. return PLUGIN_CATEGORY_UTILITY;
  456. // common tags
  457. if (sname.contains("verb"))
  458. return PLUGIN_CATEGORY_DELAY;
  459. if (sname.contains("eq"))
  460. return PLUGIN_CATEGORY_EQ;
  461. if (sname.contains("tool"))
  462. return PLUGIN_CATEGORY_UTILITY;
  463. return PLUGIN_CATEGORY_NONE;
  464. }
  465. // -----------------------------------------------------------------------
  466. CARLA_BACKEND_END_NAMESPACE
  467. #endif // CARLA_BACKEND_UTILS_HPP_INCLUDED