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.

1967 lines
72KB

  1. /*
  2. * Carla plugin host
  3. * Copyright (C) 2011-2023 Filipe Coelho <falktx@falktx.com>
  4. * SPDX-License-Identifier: GPL-2.0-or-later
  5. */
  6. #include "pluginlistdialog.hpp"
  7. #include "pluginrefreshdialog.hpp"
  8. #ifdef __clang__
  9. # pragma clang diagnostic push
  10. # pragma clang diagnostic ignored "-Wdeprecated-copy-with-user-provided-copy"
  11. # pragma clang diagnostic ignored "-Wdeprecated-register"
  12. #elif defined(__GNUC__) && __GNUC__ >= 8
  13. # pragma GCC diagnostic push
  14. # pragma GCC diagnostic ignored "-Wclass-memaccess"
  15. # pragma GCC diagnostic ignored "-Wdeprecated-copy"
  16. #endif
  17. #include <QtCore/QDir>
  18. #include <QtCore/QFileInfo>
  19. #include <QtCore/QList>
  20. #include <QtCore/QTimer>
  21. #ifdef __clang__
  22. # pragma clang diagnostic pop
  23. #elif defined(__GNUC__) && __GNUC__ >= 8
  24. # pragma GCC diagnostic pop
  25. #endif
  26. #include "qcarlastring.hpp"
  27. #include "qsafesettings.hpp"
  28. #include "CarlaBackendUtils.hpp"
  29. #include "CarlaJuceUtils.hpp"
  30. #include "CarlaFrontend.h"
  31. #include "CarlaUtils.h"
  32. #include "CarlaString.hpp"
  33. #include <cstdlib>
  34. CARLA_BACKEND_USE_NAMESPACE
  35. // --------------------------------------------------------------------------------------------------------------------
  36. // Carla Settings keys
  37. #define CARLA_KEY_PATHS_LADSPA "Paths/LADSPA"
  38. #define CARLA_KEY_PATHS_DSSI "Paths/DSSI"
  39. #define CARLA_KEY_PATHS_LV2 "Paths/LV2"
  40. #define CARLA_KEY_PATHS_VST2 "Paths/VST2"
  41. #define CARLA_KEY_PATHS_VST3 "Paths/VST3"
  42. #define CARLA_KEY_PATHS_CLAP "Paths/CLAP"
  43. #define CARLA_KEY_PATHS_SF2 "Paths/SF2"
  44. #define CARLA_KEY_PATHS_SFZ "Paths/SFZ"
  45. #define CARLA_KEY_PATHS_JSFX "Paths/JSFX"
  46. // --------------------------------------------------------------------------------------------------------------------
  47. // Carla Settings defaults
  48. // --------------------------------------------------------------------------------------------------------------------
  49. // getenv with a fallback value if unset
  50. static inline
  51. const char* getEnvWithFallback(const char* const env, const char* const fallback)
  52. {
  53. if (const char* const value = std::getenv(env))
  54. return value;
  55. return fallback;
  56. }
  57. // --------------------------------------------------------------------------------------------------------------------
  58. // Plugin paths (from env vars first, then default locations)
  59. struct PluginPaths {
  60. #ifndef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  61. QCarlaString ladspa;
  62. QCarlaString dssi;
  63. #endif
  64. QCarlaString lv2;
  65. QCarlaString vst2;
  66. QCarlaString vst3;
  67. QCarlaString clap;
  68. #ifndef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  69. QCarlaString jsfx;
  70. QCarlaString sf2;
  71. QCarlaString sfz;
  72. #endif
  73. PluginPaths()
  74. {
  75. // get common env vars
  76. const QString HOME = QDir::toNativeSeparators(QDir::homePath());
  77. #if defined(CARLA_OS_WIN)
  78. const char *const envAPPDATA = std::getenv("APPDATA");
  79. const char *const envLOCALAPPDATA = getEnvWithFallback("LOCALAPPDATA", envAPPDATA);
  80. const char *const envPROGRAMFILES = std::getenv("PROGRAMFILES");
  81. const char* const envPROGRAMFILESx86 = std::getenv("PROGRAMFILES(x86)");
  82. const char *const envCOMMONPROGRAMFILES = std::getenv("COMMONPROGRAMFILES");
  83. const char* const envCOMMONPROGRAMFILESx86 = std::getenv("COMMONPROGRAMFILES(x86)");
  84. // Small integrity tests
  85. if (envAPPDATA == nullptr)
  86. {
  87. qFatal("APPDATA variable not set, cannot continue");
  88. abort();
  89. }
  90. if (envPROGRAMFILES == nullptr)
  91. {
  92. qFatal("PROGRAMFILES variable not set, cannot continue");
  93. abort();
  94. }
  95. if (envCOMMONPROGRAMFILES == nullptr)
  96. {
  97. qFatal("COMMONPROGRAMFILES variable not set, cannot continue");
  98. abort();
  99. }
  100. const QCarlaString APPDATA(envAPPDATA);
  101. const QCarlaString LOCALAPPDATA(envLOCALAPPDATA);
  102. const QCarlaString PROGRAMFILES(envPROGRAMFILES);
  103. const QCarlaString COMMONPROGRAMFILES(envCOMMONPROGRAMFILES);
  104. #elif !defined(CARLA_OS_MAC)
  105. const QCarlaString CONFIG_HOME(getEnvWithFallback("XDG_CONFIG_HOME", (HOME + "/.config").toUtf8()));
  106. #endif
  107. #ifndef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  108. // now set paths, listing format path spec if available
  109. if (const char *const envLADSPA = std::getenv("LADSPA_PATH"))
  110. {
  111. ladspa = envLADSPA;
  112. }
  113. else
  114. {
  115. // no official spec, use common paths
  116. #if defined(CARLA_OS_WIN)
  117. ladspa = APPDATA + "\\LADSPA";
  118. ladspa += ";" + PROGRAMFILES + "\\LADSPA";
  119. #elif defined(CARLA_OS_HAIKU)
  120. ladspa = HOME + "/.ladspa";
  121. ladspa += ":/system/add-ons/media/ladspaplugins";
  122. ladspa += ":/system/lib/ladspa";
  123. #elif defined(CARLA_OS_MAC)
  124. ladspa = HOME + "/Library/Audio/Plug-Ins/LADSPA";
  125. ladspa += ":/Library/Audio/Plug-Ins/LADSPA";
  126. #else
  127. ladspa = HOME + "/.ladspa";
  128. ladspa += ":/usr/local/lib/ladspa";
  129. ladspa += ":/usr/lib/ladspa";
  130. #endif
  131. }
  132. if (const char *const envDSSI = std::getenv("DSSI_PATH"))
  133. {
  134. dssi = envDSSI;
  135. }
  136. else
  137. {
  138. // no official spec, use common paths
  139. #if defined(CARLA_OS_WIN)
  140. dssi = APPDATA + "\\DSSI";
  141. dssi += ";" + PROGRAMFILES + "\\DSSI";
  142. #elif defined(CARLA_OS_HAIKU)
  143. dssi = HOME + "/.dssi";
  144. dssi += ":/system/add-ons/media/dssiplugins";
  145. dssi += ":/system/lib/dssi";
  146. #elif defined(CARLA_OS_MAC)
  147. dssi = HOME + "/Library/Audio/Plug-Ins/DSSI";
  148. dssi += ":/Library/Audio/Plug-Ins/DSSI";
  149. #else
  150. dssi = HOME + "/.dssi";
  151. dssi += ":/usr/local/lib/dssi";
  152. dssi += ":/usr/lib/dssi";
  153. #endif
  154. }
  155. #endif // !CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  156. if (const char *const envLV2 = std::getenv("LV2_PATH"))
  157. {
  158. lv2 = envLV2;
  159. }
  160. else
  161. {
  162. // https://lv2plug.in/pages/filesystem-hierarchy-standard.html
  163. #if defined(CARLA_OS_WIN)
  164. lv2 = APPDATA + "\\LV2";
  165. lv2 += ";" + COMMONPROGRAMFILES + "\\LV2";
  166. #elif defined(CARLA_OS_HAIKU)
  167. lv2 = HOME + "/.lv2";
  168. lv2 += ":/system/add-ons/media/lv2plugins";
  169. #elif defined(CARLA_OS_MAC)
  170. lv2 = HOME + "/Library/Audio/Plug-Ins/LV2";
  171. lv2 += ":/Library/Audio/Plug-Ins/LV2";
  172. #else
  173. lv2 = HOME + "/.lv2";
  174. lv2 += ":/usr/local/lib/lv2";
  175. lv2 += ":/usr/lib/lv2";
  176. #endif
  177. }
  178. if (const char *const envVST2 = std::getenv("VST_PATH"))
  179. {
  180. vst2 = envVST2;
  181. }
  182. else
  183. {
  184. #if defined(CARLA_OS_WIN)
  185. // https://helpcenter.steinberg.de/hc/en-us/articles/115000177084
  186. vst2 = PROGRAMFILES + "\\VSTPlugins";
  187. vst2 += ";" + PROGRAMFILES + "\\Steinberg\\VSTPlugins";
  188. vst2 += ";" + COMMONPROGRAMFILES + "\\VST2";
  189. vst2 += ";" + COMMONPROGRAMFILES + "\\Steinberg\\VST2";
  190. #elif defined(CARLA_OS_HAIKU)
  191. vst2 = HOME + "/.vst";
  192. vst2 += ":/system/add-ons/media/vstplugins";
  193. #elif defined(CARLA_OS_MAC)
  194. // https://helpcenter.steinberg.de/hc/en-us/articles/115000171310
  195. vst2 = HOME + "/Library/Audio/Plug-Ins/VST";
  196. vst2 += ":/Library/Audio/Plug-Ins/VST";
  197. #else
  198. // no official spec, use common paths
  199. vst2 = HOME + "/.vst";
  200. vst2 += ":" + HOME + "/.lxvst";
  201. vst2 += ":/usr/local/lib/vst";
  202. vst2 += ":/usr/local/lib/lxvst";
  203. vst2 += ":/usr/lib/vst";
  204. vst2 += ":/usr/lib/lxvst";
  205. #endif
  206. }
  207. if (const char *const envVST3 = std::getenv("VST3_PATH"))
  208. {
  209. vst3 = envVST3;
  210. }
  211. else
  212. {
  213. // https://steinbergmedia.github.io/vst3_dev_portal/pages/Technical+Documentation/Locations+Format/Plugin+Locations.html
  214. #if defined(CARLA_OS_WIN)
  215. vst3 = LOCALAPPDATA + "\\Programs\\Common\\VST3";
  216. vst3 += ";" + COMMONPROGRAMFILES + "\\VST3";
  217. #elif defined(CARLA_OS_HAIKU)
  218. vst3 = HOME + "/.vst3";
  219. vst3 += ":/system/add-ons/media/vst3plugins";
  220. #elif defined(CARLA_OS_MAC)
  221. vst3 = HOME + "/Library/Audio/Plug-Ins/VST3";
  222. vst3 += ":/Library/Audio/Plug-Ins/VST3";
  223. #else
  224. vst3 = HOME + "/.vst3";
  225. vst3 += ":/usr/local/lib/vst3";
  226. vst3 += ":/usr/lib/vst3";
  227. #endif
  228. }
  229. if (const char *const envCLAP = std::getenv("CLAP_PATH"))
  230. {
  231. clap = envCLAP;
  232. }
  233. else
  234. {
  235. // https://github.com/free-audio/clap/blob/main/include/clap/entry.h
  236. #if defined(CARLA_OS_WIN)
  237. clap = LOCALAPPDATA + "\\Programs\\Common\\CLAP";
  238. clap += ";" + COMMONPROGRAMFILES + "\\CLAP";
  239. #elif defined(CARLA_OS_HAIKU)
  240. clap = HOME + "/.clap";
  241. clap += ":/system/add-ons/media/clapplugins";
  242. #elif defined(CARLA_OS_MAC)
  243. clap = HOME + "/Library/Audio/Plug-Ins/CLAP";
  244. clap += ":/Library/Audio/Plug-Ins/CLAP";
  245. #else
  246. clap = HOME + "/.clap";
  247. clap += ":/usr/local/lib/clap";
  248. clap += ":/usr/lib/clap";
  249. #endif
  250. }
  251. #ifndef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  252. if (const char *const envJSFX = std::getenv("JSFX_PATH"))
  253. {
  254. jsfx = envJSFX;
  255. }
  256. else
  257. {
  258. // REAPER user data directory
  259. #if defined(CARLA_OS_WIN)
  260. jsfx = APPDATA + "\\REAPER\\Effects";
  261. #elif defined(CARLA_OS_MAC)
  262. jsfx = HOME + "/Library/Application Support/REAPER/Effects";
  263. #else
  264. jsfx = CONFIG_HOME + "/REAPER/Effects";
  265. #endif
  266. }
  267. if (const char *const envSF2 = std::getenv("SF2_PATH"))
  268. {
  269. sf2 = envSF2;
  270. }
  271. else
  272. {
  273. #if defined(CARLA_OS_WIN)
  274. sf2 = APPDATA + "\\SF2";
  275. #else
  276. sf2 = HOME + "/.sounds/sf2";
  277. sf2 += ":" + HOME + "/.sounds/sf3";
  278. sf2 += ":/usr/share/sounds/sf2";
  279. sf2 += ":/usr/share/sounds/sf3";
  280. sf2 += ":/usr/share/soundfonts";
  281. #endif
  282. }
  283. if (const char *const envSFZ = std::getenv("SFZ_PATH"))
  284. {
  285. sfz = envSFZ;
  286. }
  287. else
  288. {
  289. #if defined(CARLA_OS_WIN)
  290. sfz = APPDATA + "\\SFZ";
  291. #else
  292. sfz = HOME + "/.sounds/sfz";
  293. sfz += ":/usr/share/sounds/sfz";
  294. #endif
  295. }
  296. #endif // !CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  297. #ifdef CARLA_OS_WIN
  298. if (envPROGRAMFILESx86 != nullptr)
  299. {
  300. const QCarlaString PROGRAMFILESx86(envPROGRAMFILESx86);
  301. #ifndef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  302. ladspa += ";" + PROGRAMFILESx86 + "\\LADSPA";
  303. dssi += ";" + PROGRAMFILESx86 + "\\DSSI";
  304. #endif
  305. vst2 += ";" + PROGRAMFILESx86 + "\\VSTPlugins";
  306. vst2 += ";" + PROGRAMFILESx86 + "\\Steinberg\\VSTPlugins";
  307. }
  308. if (envCOMMONPROGRAMFILESx86 != nullptr)
  309. {
  310. const QCarlaString COMMONPROGRAMFILESx86(envCOMMONPROGRAMFILESx86);
  311. vst3 += COMMONPROGRAMFILESx86 + "\\VST3";
  312. clap += COMMONPROGRAMFILESx86 + "\\CLAP";
  313. }
  314. #elif !defined(CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS)
  315. QCarlaString winePrefix;
  316. if (const char* const envWINEPREFIX = std::getenv("WINEPREFIX"))
  317. winePrefix = envWINEPREFIX;
  318. if (winePrefix.isEmpty())
  319. winePrefix = HOME + "/.wine";
  320. if (QDir(winePrefix).exists())
  321. {
  322. vst2 += ":" + winePrefix + "/drive_c/Program Files/VSTPlugins";
  323. vst2 += ":" + winePrefix + "/drive_c/Program Files/Steinberg/VSTPlugins";
  324. vst3 += ":" + winePrefix + "/drive_c/Program Files/Common Files/VST3";
  325. clap += ":" + winePrefix + "/drive_c/Program Files/Common Files/CLAP";
  326. #ifdef CARLA_OS_64BIT
  327. if (QDir(winePrefix + "/drive_c/Program Files (x86)").exists())
  328. {
  329. vst2 += ":" + winePrefix + "/drive_c/Program Files (x86)/VSTPlugins";
  330. vst2 += ":" + winePrefix + "/drive_c/Program Files (x86)/Steinberg/VSTPlugins";
  331. vst3 += ":" + winePrefix + "/drive_c/Program Files (x86)/Common Files/VST3";
  332. clap += ":" + winePrefix + "/drive_c/Program Files (x86)/Common Files/CLAP";
  333. }
  334. #endif
  335. }
  336. #endif
  337. }
  338. };
  339. // --------------------------------------------------------------------------------------------------------------------
  340. // Backwards-compatible horizontalAdvance/width call, depending on Qt version
  341. static inline
  342. int fontMetricsHorizontalAdvance(const QFontMetrics& fontMetrics, const QString& string)
  343. {
  344. #if QT_VERSION >= 0x50b00
  345. return fontMetrics.horizontalAdvance(string);
  346. #else
  347. return fontMetrics.width(string);
  348. #endif
  349. }
  350. // --------------------------------------------------------------------------------------------------------------------
  351. // Qt-compatible plugin info
  352. // base details, nicely packed and POD-only so we can directly use as binary
  353. struct PluginInfoHeader {
  354. uint16_t build;
  355. uint16_t type;
  356. uint32_t hints;
  357. uint64_t uniqueId;
  358. uint16_t audioIns;
  359. uint16_t audioOuts;
  360. uint16_t cvIns;
  361. uint16_t cvOuts;
  362. uint16_t midiIns;
  363. uint16_t midiOuts;
  364. uint16_t parameterIns;
  365. uint16_t parameterOuts;
  366. };
  367. // full details, now with non-POD types
  368. struct PluginInfo : PluginInfoHeader {
  369. QString category;
  370. QString filename;
  371. QString name;
  372. QString label;
  373. QString maker;
  374. };
  375. // convert PluginInfo to Qt types
  376. static QVariant asByteArray(const PluginInfo& info)
  377. {
  378. QByteArray qdata;
  379. // start with the POD data, stored as-is
  380. qdata.append(static_cast<const char*>(static_cast<const void*>(&info)), sizeof(PluginInfoHeader));
  381. // then all the strings, with a null terminating byte
  382. {
  383. const QByteArray qcategory(info.category.toUtf8());
  384. qdata += qcategory.constData();
  385. qdata += '\0';
  386. }
  387. {
  388. const QByteArray qfilename(info.filename.toUtf8());
  389. qdata += qfilename.constData();
  390. qdata += '\0';
  391. }
  392. {
  393. const QByteArray qname(info.name.toUtf8());
  394. qdata += qname.constData();
  395. qdata += '\0';
  396. }
  397. {
  398. const QByteArray qlabel(info.label.toUtf8());
  399. qdata += qlabel.constData();
  400. qdata += '\0';
  401. }
  402. {
  403. const QByteArray qmaker(info.maker.toUtf8());
  404. qdata += qmaker.constData();
  405. qdata += '\0';
  406. }
  407. return qdata;
  408. }
  409. static QVariant asVariant(const PluginInfo& info)
  410. {
  411. return QVariant(asByteArray(info));
  412. }
  413. // convert Qt types to PluginInfo
  414. static PluginInfo asPluginInfo(const QByteArray &qdata)
  415. {
  416. // make sure data is big enough to fit POD data + 5 strings
  417. CARLA_SAFE_ASSERT_RETURN(static_cast<size_t>(qdata.size()) >= sizeof(PluginInfoHeader) + sizeof(char) * 5, {});
  418. // read POD data first
  419. const PluginInfoHeader* const data
  420. = static_cast<const PluginInfoHeader*>(static_cast<const void*>(qdata.constData()));
  421. PluginInfo info = {};
  422. info.build = data->build;
  423. info.type = data->type;
  424. info.hints = data->hints;
  425. info.uniqueId = data->uniqueId;
  426. info.audioIns = data->audioIns;
  427. info.audioOuts = data->audioOuts;
  428. info.cvIns = data->cvIns;
  429. info.cvOuts = data->cvOuts;
  430. info.midiIns = data->midiIns;
  431. info.midiOuts = data->midiOuts;
  432. info.parameterIns = data->parameterIns;
  433. info.parameterOuts = data->parameterOuts;
  434. // then all the strings, keeping the same order as in `asVariant`
  435. const char* sdata = static_cast<const char*>(static_cast<const void*>(data + 1));
  436. info.category = QString::fromUtf8(sdata);
  437. sdata += info.category.size() + 1;
  438. info.filename = QString::fromUtf8(sdata);
  439. sdata += info.filename.size() + 1;
  440. info.name = QString::fromUtf8(sdata);
  441. sdata += info.name.size() + 1;
  442. info.label = QString::fromUtf8(sdata);
  443. sdata += info.label.size() + 1;
  444. info.maker = QString::fromUtf8(sdata);
  445. sdata += info.maker.size() + 1;
  446. return info;
  447. }
  448. static PluginInfo asPluginInfo(const QVariant& var)
  449. {
  450. return asPluginInfo(var.toByteArray());
  451. }
  452. static QList<PluginInfo> asPluginInfoList(const QVariant& var)
  453. {
  454. QCarlaByteArray qdata(var.toByteArray());
  455. QList<PluginInfo> plist;
  456. while (!qdata.isEmpty())
  457. {
  458. const PluginInfo info = asPluginInfo(qdata);
  459. CARLA_SAFE_ASSERT_RETURN(info.build != BINARY_NONE, {});
  460. plist.append(info);
  461. qdata = qdata.sliced(sizeof(PluginInfoHeader)
  462. + info.category.size() + info.filename.size() + info.name.size()
  463. + info.label.size() + info.maker.size() + 5);
  464. }
  465. return plist;
  466. }
  467. // --------------------------------------------------------------------------------------------------------------------
  468. // Qt-compatible plugin favorite
  469. // base details, nicely packed and POD-only so we can directly use as binary
  470. struct PluginFavoriteHeader {
  471. uint16_t type;
  472. uint64_t uniqueId;
  473. };
  474. // full details, now with non-POD types
  475. struct PluginFavorite : PluginFavoriteHeader {
  476. QString filename;
  477. QString label;
  478. PluginFavorite()
  479. {
  480. type = PLUGIN_NONE;
  481. uniqueId = 0;
  482. }
  483. PluginFavorite(uint16_t t, uint64_t u, const QString& f, const QString& l)
  484. : filename(f), label(l)
  485. {
  486. type = t;
  487. uniqueId = u;
  488. }
  489. bool operator==(const PluginFavorite& other) const
  490. {
  491. return type == other.type && uniqueId == other.uniqueId && filename == other.filename && label == other.label;
  492. }
  493. };
  494. // convert PluginFavorite to Qt types
  495. static QByteArray asByteArray(const PluginFavorite& fav)
  496. {
  497. QByteArray qdata;
  498. // start with the POD data, stored as-is
  499. qdata.append(static_cast<const char*>(static_cast<const void*>(&fav)), sizeof(PluginFavoriteHeader));
  500. // then all the strings, with a null terminating byte
  501. {
  502. const QByteArray qfilename(fav.filename.toUtf8());
  503. qdata += qfilename.constData();
  504. qdata += '\0';
  505. }
  506. {
  507. const QByteArray qlabel(fav.label.toUtf8());
  508. qdata += qlabel.constData();
  509. qdata += '\0';
  510. }
  511. return qdata;
  512. }
  513. static QVariant asVariant(const QList<PluginFavorite>& favlist)
  514. {
  515. QByteArray qdata;
  516. for (const PluginFavorite &fav : favlist)
  517. qdata += asByteArray(fav);
  518. return QVariant(qdata);
  519. }
  520. // convert Qt types to PluginInfo
  521. static PluginFavorite asPluginFavorite(const QByteArray& qdata)
  522. {
  523. // make sure data is big enough to fit POD data + 3 strings
  524. CARLA_SAFE_ASSERT_RETURN(static_cast<size_t>(qdata.size()) >= sizeof(PluginFavoriteHeader) + sizeof(char) * 3, {});
  525. // read POD data first
  526. const PluginFavoriteHeader* const data
  527. = static_cast<const PluginFavoriteHeader*>(static_cast<const void*>(qdata.constData()));
  528. PluginFavorite fav = { data->type, data->uniqueId, {}, {} };
  529. // then all the strings, keeping the same order as in `asVariant`
  530. const char* sdata = static_cast<const char*>(static_cast<const void*>(data + 1));
  531. fav.filename = QString::fromUtf8(sdata);
  532. sdata += fav.filename.size() + 1;
  533. fav.label = QString::fromUtf8(sdata);
  534. sdata += fav.label.size() + 1;
  535. return fav;
  536. }
  537. static QList<PluginFavorite> asPluginFavoriteList(const QVariant& var)
  538. {
  539. QCarlaByteArray qdata(var.toByteArray());
  540. QList<PluginFavorite> favlist;
  541. while (!qdata.isEmpty())
  542. {
  543. const PluginFavorite fav = asPluginFavorite(qdata);
  544. CARLA_SAFE_ASSERT_RETURN(fav.type != PLUGIN_NONE, {});
  545. favlist.append(fav);
  546. qdata = qdata.sliced(sizeof(PluginFavoriteHeader) + fav.filename.size() + fav.label.size() + 2);
  547. }
  548. return favlist;
  549. }
  550. // create PluginFavorite from PluginInfo data
  551. static PluginFavorite asPluginFavorite(const PluginInfo& info)
  552. {
  553. return PluginFavorite(info.type, info.uniqueId, info.filename, info.label);
  554. }
  555. // --------------------------------------------------------------------------------------------------------------------
  556. // discovery callbacks
  557. static void discoveryCallback(void* const ptr, const CarlaPluginDiscoveryInfo* const info, const char* const sha1sum)
  558. {
  559. static_cast<PluginListDialog*>(ptr)->addPluginInfo(info, sha1sum);
  560. }
  561. static bool checkCacheCallback(void* const ptr, const char* const filename, const char* const sha1sum)
  562. {
  563. if (sha1sum == nullptr)
  564. return false;
  565. return static_cast<PluginListDialog*>(ptr)->checkPluginCache(filename, sha1sum);
  566. }
  567. // --------------------------------------------------------------------------------------------------------------------
  568. struct PluginListDialog::PrivateData {
  569. int lastTableWidgetIndex = 0;
  570. int timerId = 0;
  571. PluginInfo retPlugin;
  572. // To be changed by parent
  573. bool hasLoadedLv2Plugins = false;
  574. struct Discovery {
  575. PluginType ptype = PLUGIN_NONE;
  576. bool firstInit = true;
  577. bool ignoreCache = false;
  578. bool checkInvalid = false;
  579. CarlaPluginDiscoveryHandle handle = nullptr;
  580. QCarlaString tool;
  581. CarlaScopedPointer<PluginRefreshDialog> dialog;
  582. Discovery()
  583. {
  584. tool = carla_get_library_folder();
  585. tool += CARLA_OS_SEP_STR "carla-discovery-native";
  586. #ifdef CARLA_OS_WIN
  587. tool += ".exe";
  588. #endif
  589. }
  590. ~Discovery()
  591. {
  592. if (handle != nullptr)
  593. carla_plugin_discovery_stop(handle);
  594. }
  595. } discovery;
  596. PluginPaths paths;
  597. struct {
  598. #ifndef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  599. std::vector<PluginInfo> internal;
  600. std::vector<PluginInfo> ladspa;
  601. std::vector<PluginInfo> dssi;
  602. #endif
  603. std::vector<PluginInfo> lv2;
  604. std::vector<PluginInfo> vst2;
  605. std::vector<PluginInfo> vst3;
  606. std::vector<PluginInfo> clap;
  607. #ifndef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  608. #ifdef CARLA_OS_MAC
  609. std::vector<PluginInfo> au;
  610. #endif
  611. std::vector<PluginInfo> jsfx;
  612. std::vector<PluginInfo> kits;
  613. #endif
  614. QMap<QString, QList<PluginInfo>> cache;
  615. QList<PluginFavorite> favorites;
  616. bool add(const PluginInfo& pinfo)
  617. {
  618. switch (pinfo.type)
  619. {
  620. #ifndef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  621. case PLUGIN_INTERNAL: internal.push_back(pinfo); return true;
  622. case PLUGIN_LADSPA: ladspa.push_back(pinfo); return true;
  623. case PLUGIN_DSSI: dssi.push_back(pinfo); return true;
  624. #endif
  625. case PLUGIN_LV2: lv2.push_back(pinfo); return true;
  626. case PLUGIN_VST2: vst2.push_back(pinfo); return true;
  627. case PLUGIN_VST3: vst3.push_back(pinfo); return true;
  628. case PLUGIN_CLAP: clap.push_back(pinfo); return true;
  629. #ifndef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  630. #ifdef CARLA_OS_MAC
  631. case PLUGIN_AU: au.push_back(pinfo); return true;
  632. #endif
  633. case PLUGIN_JSFX: jsfx.push_back(pinfo); return true;
  634. case PLUGIN_SF2:
  635. case PLUGIN_SFZ: kits.push_back(pinfo); return true;
  636. #endif
  637. default: return false;
  638. }
  639. }
  640. } plugins;
  641. };
  642. // --------------------------------------------------------------------------------------------------------------------
  643. // Plugin List Dialog
  644. PluginListDialog::PluginListDialog(QWidget* const parent, const HostSettings& hostSettings)
  645. : QDialog(parent),
  646. p(new PrivateData)
  647. {
  648. ui.setupUi(this);
  649. // p->hostSettings = hostSettings;
  650. // ----------------------------------------------------------------------------------------------------------------
  651. // Set-up GUI
  652. ui.b_add->setEnabled(false);
  653. ui.tab_info->tabBar()->hide();
  654. ui.tab_reqs->tabBar()->hide();
  655. #ifdef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  656. ui.ch_internal->hide();
  657. ui.ch_ladspa->hide();
  658. ui.ch_dssi->hide();
  659. ui.ch_au->hide();
  660. ui.ch_jsfx->hide();
  661. ui.ch_kits->hide();
  662. ui.ch_gui->hide();
  663. ui.ch_inline_display->hide();
  664. ui.toolBox->setItemEnabled(3, false);
  665. #endif
  666. // do not resize info frame so much
  667. const QLayout *const infoLayout = ui.tw_info->layout();
  668. const QMargins infoMargins = infoLayout->contentsMargins();
  669. ui.tab_info->setMinimumWidth(infoMargins.left() + infoMargins.right() + infoLayout->spacing() * 3
  670. + fontMetricsHorizontalAdvance(ui.la_id->fontMetrics(), "Has Custom GUI: 9999999999"));
  671. // start with no plugin selected
  672. checkPlugin(-1);
  673. // custom action that listens for Ctrl+F shortcut
  674. addAction(ui.act_focus_search);
  675. #if BINARY_NATIVE == BINARY_POSIX32 || BINARY_NATIVE == BINARY_WIN32
  676. ui.ch_bridged->setText(tr("Bridged (64bit)"));
  677. #else
  678. ui.ch_bridged->setText(tr("Bridged (32bit)"));
  679. #endif
  680. #if !(defined(CARLA_OS_LINUX) || defined(CARLA_OS_MAC))
  681. ui.ch_bridged_wine->setChecked(false);
  682. ui.ch_bridged_wine->setEnabled(false);
  683. #endif
  684. #ifdef CARLA_OS_MAC
  685. setWindowModality(Qt::WindowModal);
  686. #else
  687. ui.ch_au->setChecked(false);
  688. ui.ch_au->setEnabled(false);
  689. ui.ch_au->setVisible(false);
  690. #endif
  691. setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
  692. // ----------------------------------------------------------------------------------------------------------------
  693. // Load settings
  694. loadSettings();
  695. // ----------------------------------------------------------------------------------------------------------------
  696. // Disable bridges if not enabled in settings
  697. #if 0
  698. // NOTE: We Assume win32 carla build will not run win64 plugins
  699. if (WINDOWS and not kIs64bit) or not host.showPluginBridges:
  700. ui.ch_native.setChecked(True)
  701. ui.ch_native.setEnabled(False)
  702. ui.ch_native.setVisible(True)
  703. ui.ch_bridged.setChecked(False)
  704. ui.ch_bridged.setEnabled(False)
  705. ui.ch_bridged.setVisible(False)
  706. ui.ch_bridged_wine.setChecked(False)
  707. ui.ch_bridged_wine.setEnabled(False)
  708. ui.ch_bridged_wine.setVisible(False)
  709. elif not host.showWineBridges:
  710. ui.ch_bridged_wine.setChecked(False)
  711. ui.ch_bridged_wine.setEnabled(False)
  712. ui.ch_bridged_wine.setVisible(False)
  713. #endif
  714. // ----------------------------------------------------------------------------------------------------------------
  715. // Set-up Icons
  716. if (hostSettings.useSystemIcons)
  717. {
  718. #if 0
  719. ui.b_add.setIcon(getIcon('list-add', 16, 'svgz'))
  720. ui.b_cancel.setIcon(getIcon('dialog-cancel', 16, 'svgz'))
  721. ui.b_clear_filters.setIcon(getIcon('edit-clear', 16, 'svgz'))
  722. ui.b_refresh.setIcon(getIcon('view-refresh', 16, 'svgz'))
  723. QTableWidgetItem* const hhi = ui.tableWidget->horizontalHeaderItem(TW_FAVORITE);
  724. hhi.setIcon(getIcon('bookmarks', 16, 'svgz'))
  725. #endif
  726. }
  727. // ----------------------------------------------------------------------------------------------------------------
  728. // Set-up connections
  729. QObject::connect(this, &QDialog::finished, this, &PluginListDialog::saveSettings);
  730. QObject::connect(ui.b_add, &QPushButton::clicked, this, &QDialog::accept);
  731. QObject::connect(ui.b_cancel, &QPushButton::clicked, this, &QDialog::reject);
  732. QObject::connect(ui.b_refresh, &QPushButton::clicked, this, &PluginListDialog::refreshPlugins);
  733. QObject::connect(ui.b_clear_filters, &QPushButton::clicked, this, &PluginListDialog::clearFilters);
  734. QObject::connect(ui.lineEdit, &QLineEdit::textChanged, this, &PluginListDialog::checkFilters);
  735. QObject::connect(ui.tableWidget, &QTableWidget::currentCellChanged, this, &PluginListDialog::checkPlugin);
  736. QObject::connect(ui.tableWidget, &QTableWidget::cellClicked, this, &PluginListDialog::cellClicked);
  737. QObject::connect(ui.tableWidget, &QTableWidget::cellDoubleClicked, this, &PluginListDialog::cellDoubleClicked);
  738. QObject::connect(ui.ch_internal, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  739. QObject::connect(ui.ch_ladspa, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  740. QObject::connect(ui.ch_dssi, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  741. QObject::connect(ui.ch_lv2, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  742. QObject::connect(ui.ch_vst, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  743. QObject::connect(ui.ch_vst3, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  744. QObject::connect(ui.ch_clap, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  745. QObject::connect(ui.ch_au, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  746. QObject::connect(ui.ch_jsfx, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  747. QObject::connect(ui.ch_kits, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  748. QObject::connect(ui.ch_effects, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  749. QObject::connect(ui.ch_instruments, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  750. QObject::connect(ui.ch_midi, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  751. QObject::connect(ui.ch_other, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  752. QObject::connect(ui.ch_native, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  753. QObject::connect(ui.ch_bridged, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  754. QObject::connect(ui.ch_bridged_wine, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  755. QObject::connect(ui.ch_favorites, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  756. QObject::connect(ui.ch_rtsafe, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  757. QObject::connect(ui.ch_cv, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  758. QObject::connect(ui.ch_gui, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  759. QObject::connect(ui.ch_inline_display, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  760. QObject::connect(ui.ch_stereo, &QCheckBox::clicked, this, &PluginListDialog::checkFilters);
  761. QObject::connect(ui.ch_cat_all, &QCheckBox::clicked, this, &PluginListDialog::checkFiltersCategoryAll);
  762. QObject::connect(ui.ch_cat_delay, &QCheckBox::clicked, this, &PluginListDialog::checkFiltersCategorySpecific);
  763. QObject::connect(ui.ch_cat_distortion, &QCheckBox::clicked, this, &PluginListDialog::checkFiltersCategorySpecific);
  764. QObject::connect(ui.ch_cat_dynamics, &QCheckBox::clicked, this, &PluginListDialog::checkFiltersCategorySpecific);
  765. QObject::connect(ui.ch_cat_eq, &QCheckBox::clicked, this, &PluginListDialog::checkFiltersCategorySpecific);
  766. QObject::connect(ui.ch_cat_filter, &QCheckBox::clicked, this, &PluginListDialog::checkFiltersCategorySpecific);
  767. QObject::connect(ui.ch_cat_modulator, &QCheckBox::clicked, this, &PluginListDialog::checkFiltersCategorySpecific);
  768. QObject::connect(ui.ch_cat_synth, &QCheckBox::clicked, this, &PluginListDialog::checkFiltersCategorySpecific);
  769. QObject::connect(ui.ch_cat_utility, &QCheckBox::clicked, this, &PluginListDialog::checkFiltersCategorySpecific);
  770. QObject::connect(ui.ch_cat_other, &QCheckBox::clicked, this, &PluginListDialog::checkFiltersCategorySpecific);
  771. QObject::connect(ui.act_focus_search, &QAction::triggered, this, &PluginListDialog::focusSearchFieldAndSelectAll);
  772. }
  773. PluginListDialog::~PluginListDialog()
  774. {
  775. if (p->timerId != 0)
  776. killTimer(p->timerId);
  777. delete p;
  778. }
  779. // --------------------------------------------------------------------------------------------------------------------
  780. // public methods
  781. const PluginInfo& PluginListDialog::getSelectedPluginInfo() const
  782. {
  783. return p->retPlugin;
  784. }
  785. void PluginListDialog::addPluginInfo(const CarlaPluginDiscoveryInfo* const info, const char* const sha1sum)
  786. {
  787. if (info == nullptr)
  788. {
  789. if (sha1sum != nullptr)
  790. {
  791. QSafeSettings settings("falkTX", "CarlaDatabase3");
  792. settings.setValue(QString("PluginCache/%1").arg(sha1sum), QByteArray());
  793. const QString qsha1sum(sha1sum);
  794. p->plugins.cache[qsha1sum] = {};
  795. }
  796. return;
  797. }
  798. PluginInfo pinfo = {};
  799. pinfo.build = static_cast<uint16_t>(info->btype);
  800. pinfo.type = static_cast<uint16_t>(info->ptype);
  801. pinfo.hints = info->metadata.hints;
  802. pinfo.uniqueId = info->uniqueId;
  803. pinfo.audioIns = static_cast<uint16_t>(info->io.audioIns);
  804. pinfo.audioOuts = static_cast<uint16_t>(info->io.audioOuts);
  805. pinfo.cvIns = static_cast<uint16_t>(info->io.cvIns);
  806. pinfo.cvOuts = static_cast<uint16_t>(info->io.cvOuts);
  807. pinfo.midiIns = static_cast<uint16_t>(info->io.midiIns);
  808. pinfo.midiOuts = static_cast<uint16_t>(info->io.midiOuts);
  809. pinfo.parameterIns = static_cast<uint16_t>(info->io.parameterIns);
  810. pinfo.parameterOuts = static_cast<uint16_t>(info->io.parameterOuts);
  811. pinfo.category = getPluginCategoryAsString(info->metadata.category);
  812. pinfo.filename = QString::fromUtf8(info->filename);
  813. pinfo.name = QString::fromUtf8(info->metadata.name);
  814. pinfo.label = QString::fromUtf8(info->label);
  815. pinfo.maker = QString::fromUtf8(info->metadata.maker);
  816. if (sha1sum != nullptr)
  817. {
  818. QSafeSettings settings("falkTX", "CarlaDatabase3");
  819. const QString qsha1sum(sha1sum);
  820. const QString key = QString("PluginCache/%1").arg(sha1sum);
  821. // single sha1sum can contain >1 plugin
  822. QByteArray qdata;
  823. if (p->plugins.cache.contains(qsha1sum))
  824. qdata = settings.valueByteArray(key);
  825. qdata += asVariant(pinfo).toByteArray();
  826. settings.setValue(key, qdata);
  827. p->plugins.cache[qsha1sum].append(pinfo);
  828. }
  829. #ifdef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  830. if ((pinfo.hints & PLUGIN_HAS_CUSTOM_EMBED_UI) == 0x0)
  831. return;
  832. #endif
  833. p->plugins.add(pinfo);
  834. }
  835. bool PluginListDialog::checkPluginCache(const char* const filename, const char* const sha1sum)
  836. {
  837. // sha1sum is always valid for this call
  838. const QString qsha1sum(sha1sum);
  839. if (filename != nullptr)
  840. p->discovery.dialog->progressBar->setFormat(filename);
  841. if (!p->plugins.cache.contains(qsha1sum))
  842. return false;
  843. const QList<PluginInfo>& plist(p->plugins.cache[qsha1sum]);
  844. if (plist.isEmpty())
  845. return p->discovery.ignoreCache || !p->discovery.checkInvalid;
  846. // if filename does not match, abort (hash collision?)
  847. if (filename == nullptr || plist.first().filename != filename)
  848. {
  849. p->plugins.cache.remove(qsha1sum);
  850. return false;
  851. }
  852. for (const PluginInfo& info : plist)
  853. {
  854. #ifdef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  855. if ((info.hints & PLUGIN_HAS_CUSTOM_EMBED_UI) == 0x0)
  856. continue;
  857. #endif
  858. p->plugins.add(info);
  859. }
  860. return true;
  861. }
  862. // --------------------------------------------------------------------------------------------------------------------
  863. // protected methods
  864. void PluginListDialog::done(const int r)
  865. {
  866. if (r == QDialog::Accepted && ui.tableWidget->currentRow() >= 0)
  867. {
  868. QTableWidgetItem* const widget = ui.tableWidget->item(ui.tableWidget->currentRow(), TW_NAME);
  869. p->retPlugin = asPluginInfo(widget->data(Qt::UserRole + UR_PLUGIN_INFO));
  870. }
  871. else
  872. {
  873. p->retPlugin = {};
  874. }
  875. QDialog::done(r);
  876. }
  877. void PluginListDialog::showEvent(QShowEvent* const event)
  878. {
  879. focusSearchFieldAndSelectAll();
  880. QDialog::showEvent(event);
  881. // Set up initial discovery
  882. if (p->discovery.firstInit)
  883. {
  884. p->discovery.firstInit = false;
  885. p->discovery.dialog = new PluginRefreshDialog(this);
  886. p->discovery.dialog->b_start->setEnabled(false);
  887. p->discovery.dialog->b_skip->setEnabled(true);
  888. p->discovery.dialog->ch_updated->setChecked(true);
  889. p->discovery.dialog->ch_invalid->setChecked(false);
  890. p->discovery.dialog->group->setEnabled(false);
  891. p->discovery.dialog->progressBar->setFormat("Starting initial discovery...");
  892. QObject::connect(p->discovery.dialog->b_skip, &QPushButton::clicked,
  893. this, &PluginListDialog::refreshPluginsSkip);
  894. QObject::connect(p->discovery.dialog, &QDialog::finished,
  895. this, &PluginListDialog::refreshPluginsStop);
  896. p->timerId = startTimer(0);
  897. QTimer::singleShot(0, p->discovery.dialog, &QDialog::exec);
  898. }
  899. }
  900. void PluginListDialog::timerEvent(QTimerEvent* const event)
  901. {
  902. if (event->timerId() == p->timerId)
  903. {
  904. do {
  905. // discovery in progress, keep it going
  906. if (p->discovery.handle != nullptr)
  907. {
  908. if (!carla_plugin_discovery_idle(p->discovery.handle))
  909. {
  910. carla_plugin_discovery_stop(p->discovery.handle);
  911. p->discovery.handle = nullptr;
  912. }
  913. break;
  914. }
  915. // start next discovery
  916. QCarlaString path;
  917. switch (p->discovery.ptype)
  918. {
  919. case PLUGIN_NONE:
  920. #ifndef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  921. ui.label->setText(tr("Discovering internal plugins..."));
  922. p->discovery.ptype = PLUGIN_INTERNAL;
  923. break;
  924. case PLUGIN_INTERNAL:
  925. ui.label->setText(tr("Discovering LADSPA plugins..."));
  926. path = p->paths.ladspa;
  927. p->discovery.ptype = PLUGIN_LADSPA;
  928. break;
  929. case PLUGIN_LADSPA:
  930. ui.label->setText(tr("Discovering DSSI plugins..."));
  931. path = p->paths.dssi;
  932. p->discovery.ptype = PLUGIN_DSSI;
  933. break;
  934. case PLUGIN_DSSI:
  935. #endif
  936. ui.label->setText(tr("Discovering LV2 plugins..."));
  937. path = p->paths.lv2;
  938. p->discovery.ptype = PLUGIN_LV2;
  939. break;
  940. case PLUGIN_LV2:
  941. ui.label->setText(tr("Discovering VST2 plugins..."));
  942. path = p->paths.vst2;
  943. p->discovery.ptype = PLUGIN_VST2;
  944. break;
  945. case PLUGIN_VST2:
  946. ui.label->setText(tr("Discovering VST3 plugins..."));
  947. path = p->paths.vst3;
  948. p->discovery.ptype = PLUGIN_VST3;
  949. break;
  950. case PLUGIN_VST3:
  951. ui.label->setText(tr("Discovering CLAP plugins..."));
  952. path = p->paths.clap;
  953. p->discovery.ptype = PLUGIN_CLAP;
  954. break;
  955. case PLUGIN_CLAP:
  956. #ifndef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  957. #ifdef CARLA_OS_MAC
  958. ui.label->setText(tr("Discovering AU plugins..."));
  959. p->discovery.ptype = PLUGIN_AU;
  960. break;
  961. case PLUGIN_AU:
  962. #endif
  963. if (p->paths.jsfx.isNotEmpty())
  964. {
  965. ui.label->setText(tr("Discovering JSFX plugins..."));
  966. path = p->paths.jsfx;
  967. p->discovery.ptype = PLUGIN_JSFX;
  968. break;
  969. }
  970. [[fallthrough]];
  971. case PLUGIN_JSFX:
  972. ui.label->setText(tr("Discovering SF2 kits..."));
  973. path = p->paths.sf2;
  974. p->discovery.ptype = PLUGIN_SF2;
  975. break;
  976. case PLUGIN_SF2:
  977. ui.label->setText(tr("Discovering SFZ kits..."));
  978. path = p->paths.sfz;
  979. p->discovery.ptype = PLUGIN_SFZ;
  980. break;
  981. case PLUGIN_SFZ:
  982. #endif
  983. default:
  984. // discovery complete
  985. refreshPluginsStop();
  986. }
  987. if (p->timerId == 0)
  988. break;
  989. if (p->discovery.dialog)
  990. p->discovery.dialog->progressBar->setFormat(ui.label->text());
  991. p->discovery.handle = carla_plugin_discovery_start(p->discovery.tool.toUtf8().constData(),
  992. p->discovery.ptype,
  993. path.toUtf8().constData(),
  994. discoveryCallback, checkCacheCallback, this);
  995. } while (false);
  996. }
  997. QDialog::timerEvent(event);
  998. }
  999. // --------------------------------------------------------------------------------------------------------------------
  1000. // private methods
  1001. void PluginListDialog::addPluginsToTable()
  1002. {
  1003. // ----------------------------------------------------------------------------------------------------------------
  1004. // sum plugins first, creating all needed rows in advance
  1005. ui.tableWidget->setSortingEnabled(false);
  1006. ui.tableWidget->clearContents();
  1007. #ifdef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  1008. ui.tableWidget->setRowCount(
  1009. int(p->plugins.lv2.size() + p->plugins.vst2.size() + p->plugins.vst3.size() + p->plugins.clap.size()));
  1010. constexpr const char* const txt = "Have %1 LV2, %2 VST2, %3 VST3 and %4 CLAP plugins";
  1011. ui.label->setText(tr(txt)
  1012. .arg(QString::number(p->plugins.lv2.size()))
  1013. .arg(QString::number(p->plugins.vst2.size()))
  1014. .arg(QString::number(p->plugins.vst3.size()))
  1015. .arg(QString::number(p->plugins.clap.size())));
  1016. #else
  1017. ui.tableWidget->setRowCount(
  1018. int(p->plugins.internal.size() + p->plugins.ladspa.size() + p->plugins.dssi.size() +
  1019. p->plugins.lv2.size() + p->plugins.vst2.size() + p->plugins.vst3.size() + p->plugins.clap.size() +
  1020. #ifdef CARLA_OS_MAC
  1021. p->plugins.au.size() +
  1022. #endif
  1023. p->plugins.jsfx.size() + p->plugins.kits.size()));
  1024. constexpr const char* const txt = "Have %1 Internal, %2 LADSPA, %3 DSSI, %4 LV2, %5 VST2, %6 VST3, %7 CLAP"
  1025. #ifdef CARLA_OS_MAC
  1026. ", %8 AudioUnit and %9 JSFX plugins, plus %10 Sound Kits"
  1027. #endif
  1028. " and %8 JSFX plugins, plus %9 Sound Kits";
  1029. ui.label->setText(tr(txt)
  1030. .arg(QString::number(p->plugins.internal.size()))
  1031. .arg(QString::number(p->plugins.ladspa.size()))
  1032. .arg(QString::number(p->plugins.dssi.size()))
  1033. .arg(QString::number(p->plugins.lv2.size()))
  1034. .arg(QString::number(p->plugins.vst2.size()))
  1035. .arg(QString::number(p->plugins.vst3.size()))
  1036. .arg(QString::number(p->plugins.clap.size()))
  1037. #ifdef CARLA_OS_MAC
  1038. .arg(QString::number(p->plugins.au.size()))
  1039. #endif
  1040. .arg(QString::number(p->plugins.jsfx.size()))
  1041. .arg(QString::number(p->plugins.kits.size())));
  1042. #endif
  1043. // ----------------------------------------------------------------------------------------------------------------
  1044. // now add all plugins to the table
  1045. auto addPluginToTable = [=](const PluginInfo& info) {
  1046. const int index = p->lastTableWidgetIndex++;
  1047. const bool isFav = p->plugins.favorites.contains(asPluginFavorite(info));
  1048. QTableWidgetItem* const itemFav = new QTableWidgetItem;
  1049. itemFav->setCheckState(isFav ? Qt::Checked : Qt::Unchecked);
  1050. itemFav->setText(isFav ? " " : " ");
  1051. const QString pluginText = (info.name + info.label + info.maker + info.filename).toLower();
  1052. ui.tableWidget->setItem(index, TW_FAVORITE, itemFav);
  1053. ui.tableWidget->setItem(index, TW_NAME, new QTableWidgetItem(info.name));
  1054. ui.tableWidget->setItem(index, TW_LABEL, new QTableWidgetItem(info.label));
  1055. ui.tableWidget->setItem(index, TW_MAKER, new QTableWidgetItem(info.maker));
  1056. ui.tableWidget->setItem(index, TW_BINARY, new QTableWidgetItem(QFileInfo(info.filename).fileName()));
  1057. QTableWidgetItem *const itemName = ui.tableWidget->item(index, TW_NAME);
  1058. itemName->setData(Qt::UserRole + UR_PLUGIN_INFO, asVariant(info));
  1059. itemName->setData(Qt::UserRole + UR_SEARCH_TEXT, pluginText);
  1060. };
  1061. p->lastTableWidgetIndex = 0;
  1062. #ifndef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  1063. for (const PluginInfo &plugin : p->plugins.internal)
  1064. addPluginToTable(plugin);
  1065. for (const PluginInfo &plugin : p->plugins.ladspa)
  1066. addPluginToTable(plugin);
  1067. for (const PluginInfo &plugin : p->plugins.dssi)
  1068. addPluginToTable(plugin);
  1069. #endif
  1070. for (const PluginInfo &plugin : p->plugins.lv2)
  1071. addPluginToTable(plugin);
  1072. for (const PluginInfo &plugin : p->plugins.vst2)
  1073. addPluginToTable(plugin);
  1074. for (const PluginInfo &plugin : p->plugins.vst3)
  1075. addPluginToTable(plugin);
  1076. for (const PluginInfo& plugin : p->plugins.clap)
  1077. addPluginToTable(plugin);
  1078. #ifndef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  1079. #ifdef CARLA_OS_MAC
  1080. for (const PluginInfo& plugin : p->plugins.au)
  1081. addPluginToTable(plugin);
  1082. #endif
  1083. for (const PluginInfo& plugin : p->plugins.jsfx)
  1084. addPluginToTable(plugin);
  1085. for (const PluginInfo& plugin : p->plugins.kits)
  1086. addPluginToTable(plugin);
  1087. #endif
  1088. CARLA_SAFE_ASSERT_INT2(p->lastTableWidgetIndex == ui.tableWidget->rowCount(),
  1089. p->lastTableWidgetIndex, ui.tableWidget->rowCount());
  1090. // ----------------------------------------------------------------------------------------------------------------
  1091. // and reenable sorting + filtering
  1092. ui.tableWidget->setSortingEnabled(true);
  1093. checkFilters();
  1094. checkPlugin(ui.tableWidget->currentRow());
  1095. }
  1096. void PluginListDialog::loadSettings()
  1097. {
  1098. const QSafeSettings settings("falkTX", "CarlaDatabase3");
  1099. restoreGeometry(settings.valueByteArray("PluginDatabase/Geometry"));
  1100. ui.ch_effects->setChecked(settings.valueBool("PluginDatabase/ShowEffects", true));
  1101. ui.ch_instruments->setChecked(settings.valueBool("PluginDatabase/ShowInstruments", true));
  1102. ui.ch_midi->setChecked(settings.valueBool("PluginDatabase/ShowMIDI", true));
  1103. ui.ch_other->setChecked(settings.valueBool("PluginDatabase/ShowOther", true));
  1104. ui.ch_internal->setChecked(settings.valueBool("PluginDatabase/ShowInternal", true));
  1105. ui.ch_ladspa->setChecked(settings.valueBool("PluginDatabase/ShowLADSPA", true));
  1106. ui.ch_dssi->setChecked(settings.valueBool("PluginDatabase/ShowDSSI", true));
  1107. ui.ch_lv2->setChecked(settings.valueBool("PluginDatabase/ShowLV2", true));
  1108. ui.ch_vst->setChecked(settings.valueBool("PluginDatabase/ShowVST2", true));
  1109. ui.ch_vst3->setChecked(settings.valueBool("PluginDatabase/ShowVST3", true));
  1110. ui.ch_clap->setChecked(settings.valueBool("PluginDatabase/ShowCLAP", true));
  1111. #ifdef CARLA_OS_MAC
  1112. ui.ch_au->setChecked(settings.valueBool("PluginDatabase/ShowAU", true));
  1113. #endif
  1114. ui.ch_jsfx->setChecked(settings.valueBool("PluginDatabase/ShowJSFX", true));
  1115. ui.ch_kits->setChecked(settings.valueBool("PluginDatabase/ShowKits", true));
  1116. ui.ch_native->setChecked(settings.valueBool("PluginDatabase/ShowNative", true));
  1117. ui.ch_bridged->setChecked(settings.valueBool("PluginDatabase/ShowBridged", true));
  1118. ui.ch_bridged_wine->setChecked(settings.valueBool("PluginDatabase/ShowBridgedWine", true));
  1119. ui.ch_favorites->setChecked(settings.valueBool("PluginDatabase/ShowFavorites", false));
  1120. ui.ch_rtsafe->setChecked(settings.valueBool("PluginDatabase/ShowRtSafe", false));
  1121. ui.ch_cv->setChecked(settings.valueBool("PluginDatabase/ShowHasCV", false));
  1122. ui.ch_gui->setChecked(settings.valueBool("PluginDatabase/ShowHasGUI", false));
  1123. ui.ch_inline_display->setChecked(settings.valueBool("PluginDatabase/ShowHasInlineDisplay", false));
  1124. ui.ch_stereo->setChecked(settings.valueBool("PluginDatabase/ShowStereoOnly", false));
  1125. ui.lineEdit->setText(settings.valueString("PluginDatabase/SearchText", ""));
  1126. const QString categories = settings.valueString("PluginDatabase/ShowCategory", "all");
  1127. if (categories == "all" or categories.length() < 2)
  1128. {
  1129. ui.ch_cat_all->setChecked(true);
  1130. ui.ch_cat_delay->setChecked(false);
  1131. ui.ch_cat_distortion->setChecked(false);
  1132. ui.ch_cat_dynamics->setChecked(false);
  1133. ui.ch_cat_eq->setChecked(false);
  1134. ui.ch_cat_filter->setChecked(false);
  1135. ui.ch_cat_modulator->setChecked(false);
  1136. ui.ch_cat_synth->setChecked(false);
  1137. ui.ch_cat_utility->setChecked(false);
  1138. ui.ch_cat_other->setChecked(false);
  1139. }
  1140. else
  1141. {
  1142. ui.ch_cat_all->setChecked(false);
  1143. ui.ch_cat_delay->setChecked(categories.contains(":delay:"));
  1144. ui.ch_cat_distortion->setChecked(categories.contains(":distortion:"));
  1145. ui.ch_cat_dynamics->setChecked(categories.contains(":dynamics:"));
  1146. ui.ch_cat_eq->setChecked(categories.contains(":eq:"));
  1147. ui.ch_cat_filter->setChecked(categories.contains(":filter:"));
  1148. ui.ch_cat_modulator->setChecked(categories.contains(":modulator:"));
  1149. ui.ch_cat_synth->setChecked(categories.contains(":synth:"));
  1150. ui.ch_cat_utility->setChecked(categories.contains(":utility:"));
  1151. ui.ch_cat_other->setChecked(categories.contains(":other:"));
  1152. }
  1153. const QByteArray tableGeometry = settings.valueByteArray("PluginDatabase/TableGeometry");
  1154. QHeaderView* const horizontalHeader = ui.tableWidget->horizontalHeader();
  1155. if (! tableGeometry.isNull())
  1156. {
  1157. horizontalHeader->restoreState(tableGeometry);
  1158. }
  1159. else
  1160. {
  1161. ui.tableWidget->setColumnWidth(TW_NAME, 250);
  1162. ui.tableWidget->setColumnWidth(TW_LABEL, 200);
  1163. ui.tableWidget->setColumnWidth(TW_MAKER, 150);
  1164. ui.tableWidget->sortByColumn(TW_NAME, Qt::AscendingOrder);
  1165. }
  1166. horizontalHeader->setSectionResizeMode(TW_FAVORITE, QHeaderView::Fixed);
  1167. ui.tableWidget->setColumnWidth(TW_FAVORITE, 24);
  1168. ui.tableWidget->setSortingEnabled(true);
  1169. p->plugins.favorites = asPluginFavoriteList(settings.valueByteArray("PluginListDialog/Favorites"));
  1170. // load entire plugin cache
  1171. const QStringList keys = settings.allKeys();
  1172. for (const QCarlaString key : keys)
  1173. {
  1174. if (!key.startsWith("PluginCache/"))
  1175. continue;
  1176. const QByteArray data(settings.valueByteArray(key));
  1177. if (data.isEmpty())
  1178. p->plugins.cache.insert(key.sliced(12), {});
  1179. else
  1180. p->plugins.cache.insert(key.sliced(12), asPluginInfoList(data));
  1181. }
  1182. #ifdef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  1183. // these are not visible, force their value
  1184. ui.ch_native->setChecked(true);
  1185. ui.ch_bridged->setChecked(false);
  1186. ui.ch_bridged_wine->setChecked(false);
  1187. ui.ch_inline_display->setChecked(false);
  1188. #endif
  1189. }
  1190. // -----------------------------------------------------------------------------------------------------------------
  1191. // private slots
  1192. void PluginListDialog::cellClicked(const int row, const int column)
  1193. {
  1194. if (column != TW_FAVORITE)
  1195. return;
  1196. const PluginInfo info = asPluginInfo(ui.tableWidget->item(row, TW_NAME)->data(Qt::UserRole + UR_PLUGIN_INFO));
  1197. const PluginFavorite fav = asPluginFavorite(info);
  1198. const bool isFavorite = p->plugins.favorites.contains(fav);
  1199. if (ui.tableWidget->item(row, TW_FAVORITE)->checkState() == Qt::Checked)
  1200. {
  1201. if (!isFavorite)
  1202. p->plugins.favorites.append(fav);
  1203. }
  1204. else if (isFavorite)
  1205. {
  1206. p->plugins.favorites.removeAll(fav);
  1207. }
  1208. QSafeSettings settings("falkTX", "CarlaDatabase3");
  1209. settings.setValue("PluginListDialog/Favorites", asVariant(p->plugins.favorites));
  1210. }
  1211. void PluginListDialog::cellDoubleClicked(int, const int column)
  1212. {
  1213. if (column != TW_FAVORITE)
  1214. done(QDialog::Accepted);
  1215. }
  1216. void PluginListDialog::focusSearchFieldAndSelectAll()
  1217. {
  1218. ui.lineEdit->setFocus();
  1219. ui.lineEdit->selectAll();
  1220. }
  1221. void PluginListDialog::checkFilters()
  1222. {
  1223. const QCarlaString text = ui.lineEdit->text().toLower();
  1224. const bool hideEffects = !ui.ch_effects->isChecked();
  1225. const bool hideInstruments = !ui.ch_instruments->isChecked();
  1226. const bool hideMidi = !ui.ch_midi->isChecked();
  1227. const bool hideOther = !ui.ch_other->isChecked();
  1228. const bool hideInternal = !ui.ch_internal->isChecked();
  1229. const bool hideLadspa = !ui.ch_ladspa->isChecked();
  1230. const bool hideDSSI = !ui.ch_dssi->isChecked();
  1231. const bool hideLV2 = !ui.ch_lv2->isChecked();
  1232. const bool hideVST2 = !ui.ch_vst->isChecked();
  1233. const bool hideVST3 = !ui.ch_vst3->isChecked();
  1234. const bool hideCLAP = !ui.ch_clap->isChecked();
  1235. const bool hideAU = !ui.ch_au->isChecked();
  1236. const bool hideJSFX = !ui.ch_jsfx->isChecked();
  1237. const bool hideKits = !ui.ch_kits->isChecked();
  1238. const bool hideNative = !ui.ch_native->isChecked();
  1239. const bool hideBridged = !ui.ch_bridged->isChecked();
  1240. const bool hideBridgedWine = !ui.ch_bridged_wine->isChecked();
  1241. const bool hideNonFavs = ui.ch_favorites->isChecked();
  1242. const bool hideNonRtSafe = ui.ch_rtsafe->isChecked();
  1243. const bool hideNonCV = ui.ch_cv->isChecked();
  1244. const bool hideNonGui = ui.ch_gui->isChecked();
  1245. const bool hideNonIDisp = ui.ch_inline_display->isChecked();
  1246. const bool hideNonStereo = ui.ch_stereo->isChecked();
  1247. #if 0
  1248. if HAIKU or LINUX or MACOS:
  1249. nativeBins = [BINARY_POSIX32, BINARY_POSIX64]
  1250. wineBins = [BINARY_WIN32, BINARY_WIN64]
  1251. elif WINDOWS:
  1252. nativeBins = [BINARY_WIN32, BINARY_WIN64]
  1253. wineBins = []
  1254. else:
  1255. nativeBins = []
  1256. wineBins = []
  1257. #endif
  1258. for (int i=0, c=ui.tableWidget->rowCount(); i<c; ++i)
  1259. {
  1260. const PluginInfo info = asPluginInfo(ui.tableWidget->item(i, TW_NAME)->data(Qt::UserRole + UR_PLUGIN_INFO));
  1261. const QString ptext = ui.tableWidget->item(i, TW_NAME)->data(Qt::UserRole + UR_SEARCH_TEXT).toString();
  1262. const uint16_t aIns = info.audioIns;
  1263. const uint16_t aOuts = info.audioOuts;
  1264. const uint16_t cvIns = info.cvIns;
  1265. const uint16_t cvOuts = info.cvOuts;
  1266. const uint16_t mIns = info.midiIns;
  1267. const uint16_t mOuts = info.midiOuts;
  1268. const uint32_t phints = info.hints;
  1269. const uint16_t ptype = info.type;
  1270. const QString categ = info.category;
  1271. const bool isSynth = phints & PLUGIN_IS_SYNTH;
  1272. const bool isEffect = aIns > 0 && aOuts > 0 && !isSynth;
  1273. const bool isMidi = aIns == 0 && aOuts == 0 && mIns > 0 && mOuts > 0;
  1274. const bool isKit = ptype == PLUGIN_SF2 || ptype == PLUGIN_SFZ;
  1275. const bool isOther = !(isEffect || isSynth || isMidi || isKit);
  1276. const bool isNative = info.build == BINARY_NATIVE;
  1277. const bool isRtSafe = phints & PLUGIN_IS_RTSAFE;
  1278. const bool isStereo = (aIns == 2 && aOuts == 2) || (isSynth && aOuts == 2);
  1279. const bool hasCV = cvIns + cvOuts > 0;
  1280. const bool hasGui = phints & PLUGIN_HAS_CUSTOM_UI;
  1281. const bool hasIDisp = phints & PLUGIN_HAS_INLINE_DISPLAY;
  1282. #if 0
  1283. const bool isBridged = bool(not isNative and info.build in nativeBins);
  1284. const bool isBridgedWine = bool(not isNative and info.build in wineBins);
  1285. #else
  1286. const bool isBridged = false;
  1287. const bool isBridgedWine = false;
  1288. #endif
  1289. const auto hasText = [text, ptext]() {
  1290. const QStringList textSplit = text.strip().split(' ');
  1291. for (const QString& t : textSplit)
  1292. if (ptext.contains(t))
  1293. return true;
  1294. return false;
  1295. };
  1296. /**/ if (hideEffects && isEffect)
  1297. ui.tableWidget->hideRow(i);
  1298. else if (hideInstruments && isSynth)
  1299. ui.tableWidget->hideRow(i);
  1300. else if (hideMidi && isMidi)
  1301. ui.tableWidget->hideRow(i);
  1302. else if (hideOther && isOther)
  1303. ui.tableWidget->hideRow(i);
  1304. else if (hideKits && isKit)
  1305. ui.tableWidget->hideRow(i);
  1306. else if (hideInternal && ptype == PLUGIN_INTERNAL)
  1307. ui.tableWidget->hideRow(i);
  1308. else if (hideLadspa && ptype == PLUGIN_LADSPA)
  1309. ui.tableWidget->hideRow(i);
  1310. else if (hideDSSI && ptype == PLUGIN_DSSI)
  1311. ui.tableWidget->hideRow(i);
  1312. else if (hideLV2 && ptype == PLUGIN_LV2)
  1313. ui.tableWidget->hideRow(i);
  1314. else if (hideVST2 && ptype == PLUGIN_VST2)
  1315. ui.tableWidget->hideRow(i);
  1316. else if (hideVST3 && ptype == PLUGIN_VST3)
  1317. ui.tableWidget->hideRow(i);
  1318. else if (hideCLAP && ptype == PLUGIN_CLAP)
  1319. ui.tableWidget->hideRow(i);
  1320. else if (hideAU && ptype == PLUGIN_AU)
  1321. ui.tableWidget->hideRow(i);
  1322. else if (hideJSFX && ptype == PLUGIN_JSFX)
  1323. ui.tableWidget->hideRow(i);
  1324. else if (hideNative && isNative)
  1325. ui.tableWidget->hideRow(i);
  1326. else if (hideBridged && isBridged)
  1327. ui.tableWidget->hideRow(i);
  1328. else if (hideBridgedWine && isBridgedWine)
  1329. ui.tableWidget->hideRow(i);
  1330. else if (hideNonRtSafe && not isRtSafe)
  1331. ui.tableWidget->hideRow(i);
  1332. else if (hideNonCV && not hasCV)
  1333. ui.tableWidget->hideRow(i);
  1334. else if (hideNonGui && not hasGui)
  1335. ui.tableWidget->hideRow(i);
  1336. else if (hideNonIDisp && not hasIDisp)
  1337. ui.tableWidget->hideRow(i);
  1338. else if (hideNonStereo && not isStereo)
  1339. ui.tableWidget->hideRow(i);
  1340. else if (text.isNotEmpty() && ! hasText())
  1341. ui.tableWidget->hideRow(i);
  1342. else if (hideNonFavs && !p->plugins.favorites.contains(asPluginFavorite(info)))
  1343. ui.tableWidget->hideRow(i);
  1344. else if (ui.ch_cat_all->isChecked() or
  1345. (ui.ch_cat_delay->isChecked() && categ == "delay") or
  1346. (ui.ch_cat_distortion->isChecked() && categ == "distortion") or
  1347. (ui.ch_cat_dynamics->isChecked() && categ == "dynamics") or
  1348. (ui.ch_cat_eq->isChecked() && categ == "eq") or
  1349. (ui.ch_cat_filter->isChecked() && categ == "filter") or
  1350. (ui.ch_cat_modulator->isChecked() && categ == "modulator") or
  1351. (ui.ch_cat_synth->isChecked() && categ == "synth") or
  1352. (ui.ch_cat_utility->isChecked() && categ == "utility") or
  1353. (ui.ch_cat_other->isChecked() && categ == "other"))
  1354. ui.tableWidget->showRow(i);
  1355. else
  1356. ui.tableWidget->hideRow(i);
  1357. }
  1358. }
  1359. void PluginListDialog::checkFiltersCategoryAll(const bool clicked)
  1360. {
  1361. const bool notClicked = !clicked;
  1362. ui.ch_cat_delay->setChecked(notClicked);
  1363. ui.ch_cat_distortion->setChecked(notClicked);
  1364. ui.ch_cat_dynamics->setChecked(notClicked);
  1365. ui.ch_cat_eq->setChecked(notClicked);
  1366. ui.ch_cat_filter->setChecked(notClicked);
  1367. ui.ch_cat_modulator->setChecked(notClicked);
  1368. ui.ch_cat_synth->setChecked(notClicked);
  1369. ui.ch_cat_utility->setChecked(notClicked);
  1370. ui.ch_cat_other->setChecked(notClicked);
  1371. checkFilters();
  1372. }
  1373. void PluginListDialog::checkFiltersCategorySpecific(bool clicked)
  1374. {
  1375. if (clicked)
  1376. {
  1377. ui.ch_cat_all->setChecked(false);
  1378. }
  1379. else if (! (ui.ch_cat_delay->isChecked() ||
  1380. ui.ch_cat_distortion->isChecked() ||
  1381. ui.ch_cat_dynamics->isChecked() ||
  1382. ui.ch_cat_eq->isChecked() ||
  1383. ui.ch_cat_filter->isChecked() ||
  1384. ui.ch_cat_modulator->isChecked() ||
  1385. ui.ch_cat_synth->isChecked() ||
  1386. ui.ch_cat_utility->isChecked() ||
  1387. ui.ch_cat_other->isChecked()))
  1388. {
  1389. ui.ch_cat_all->setChecked(true);
  1390. }
  1391. checkFilters();
  1392. }
  1393. void PluginListDialog::clearFilters()
  1394. {
  1395. auto setCheckedWithoutSignaling = [](QCheckBox* const w, const bool checked)
  1396. {
  1397. w->blockSignals(true);
  1398. w->setChecked(checked);
  1399. w->blockSignals(false);
  1400. };
  1401. setCheckedWithoutSignaling(ui.ch_internal, true);
  1402. setCheckedWithoutSignaling(ui.ch_ladspa, true);
  1403. setCheckedWithoutSignaling(ui.ch_dssi, true);
  1404. setCheckedWithoutSignaling(ui.ch_lv2, true);
  1405. setCheckedWithoutSignaling(ui.ch_vst, true);
  1406. setCheckedWithoutSignaling(ui.ch_vst3, true);
  1407. setCheckedWithoutSignaling(ui.ch_clap, true);
  1408. setCheckedWithoutSignaling(ui.ch_jsfx, true);
  1409. setCheckedWithoutSignaling(ui.ch_kits, true);
  1410. setCheckedWithoutSignaling(ui.ch_instruments, true);
  1411. setCheckedWithoutSignaling(ui.ch_effects, true);
  1412. setCheckedWithoutSignaling(ui.ch_midi, true);
  1413. setCheckedWithoutSignaling(ui.ch_other, true);
  1414. setCheckedWithoutSignaling(ui.ch_native, true);
  1415. setCheckedWithoutSignaling(ui.ch_bridged, false);
  1416. setCheckedWithoutSignaling(ui.ch_bridged_wine, false);
  1417. setCheckedWithoutSignaling(ui.ch_favorites, false);
  1418. setCheckedWithoutSignaling(ui.ch_rtsafe, false);
  1419. setCheckedWithoutSignaling(ui.ch_stereo, false);
  1420. setCheckedWithoutSignaling(ui.ch_cv, false);
  1421. setCheckedWithoutSignaling(ui.ch_gui, false);
  1422. setCheckedWithoutSignaling(ui.ch_inline_display, false);
  1423. if (ui.ch_au->isEnabled())
  1424. setCheckedWithoutSignaling(ui.ch_au, true);
  1425. setCheckedWithoutSignaling(ui.ch_cat_all, true);
  1426. setCheckedWithoutSignaling(ui.ch_cat_delay, false);
  1427. setCheckedWithoutSignaling(ui.ch_cat_distortion, false);
  1428. setCheckedWithoutSignaling(ui.ch_cat_dynamics, false);
  1429. setCheckedWithoutSignaling(ui.ch_cat_eq, false);
  1430. setCheckedWithoutSignaling(ui.ch_cat_filter, false);
  1431. setCheckedWithoutSignaling(ui.ch_cat_modulator, false);
  1432. setCheckedWithoutSignaling(ui.ch_cat_synth, false);
  1433. setCheckedWithoutSignaling(ui.ch_cat_utility, false);
  1434. setCheckedWithoutSignaling(ui.ch_cat_other, false);
  1435. ui.lineEdit->blockSignals(true);
  1436. ui.lineEdit->clear();
  1437. ui.lineEdit->blockSignals(false);
  1438. checkFilters();
  1439. }
  1440. // --------------------------------------------------------------------------------------------------------------------
  1441. void PluginListDialog::checkPlugin(const int row)
  1442. {
  1443. if (row >= 0)
  1444. {
  1445. ui.b_add->setEnabled(true);
  1446. const PluginInfo info = asPluginInfo(ui.tableWidget->item(row, TW_NAME)->data(Qt::UserRole + UR_PLUGIN_INFO));
  1447. const bool isSynth = info.hints & PLUGIN_IS_SYNTH;
  1448. const bool isEffect = info.audioIns > 0 && info.audioOuts > 0 && !isSynth;
  1449. const bool isMidi = info.audioIns == 0 && info.audioOuts == 0 && info.midiIns > 0 && info.midiOuts > 0;
  1450. QString ptype;
  1451. /**/ if (isSynth)
  1452. ptype = "Instrument";
  1453. else if (isEffect)
  1454. ptype = "Effect";
  1455. else if (isMidi)
  1456. ptype = "MIDI Plugin";
  1457. else
  1458. ptype = "Other";
  1459. QString parch;
  1460. /**/ if (info.build == BINARY_NATIVE)
  1461. parch = tr("Native");
  1462. else if (info.build == BINARY_POSIX32)
  1463. parch = "posix32";
  1464. else if (info.build == BINARY_POSIX64)
  1465. parch = "posix64";
  1466. else if (info.build == BINARY_WIN32)
  1467. parch = "win32";
  1468. else if (info.build == BINARY_WIN64)
  1469. parch = "win64";
  1470. else if (info.build == BINARY_OTHER)
  1471. parch = tr("Other");
  1472. else if (info.build == BINARY_WIN32)
  1473. parch = tr("Unknown");
  1474. ui.l_format->setText(getPluginTypeAsString(static_cast<PluginType>(info.type)));
  1475. ui.l_type->setText(ptype);
  1476. ui.l_arch->setText(parch);
  1477. ui.l_id->setText(QString::number(info.uniqueId));
  1478. ui.l_ains->setText(QString::number(info.audioIns));
  1479. ui.l_aouts->setText(QString::number(info.audioOuts));
  1480. ui.l_cvins->setText(QString::number(info.cvIns));
  1481. ui.l_cvouts->setText(QString::number(info.cvOuts));
  1482. ui.l_mins->setText(QString::number(info.midiIns));
  1483. ui.l_mouts->setText(QString::number(info.midiOuts));
  1484. ui.l_pins->setText(QString::number(info.parameterIns));
  1485. ui.l_pouts->setText(QString::number(info.parameterOuts));
  1486. ui.l_gui->setText(info.hints & PLUGIN_HAS_CUSTOM_UI ? tr("Yes") : tr("No"));
  1487. ui.l_idisp->setText(info.hints & PLUGIN_HAS_INLINE_DISPLAY ? tr("Yes") : tr("No"));
  1488. ui.l_bridged->setText(info.hints & PLUGIN_IS_BRIDGE ? tr("Yes") : tr("No"));
  1489. ui.l_synth->setText(isSynth ? tr("Yes") : tr("No"));
  1490. }
  1491. else
  1492. {
  1493. ui.b_add->setEnabled(false);
  1494. ui.l_format->setText("---");
  1495. ui.l_type->setText("---");
  1496. ui.l_arch->setText("---");
  1497. ui.l_id->setText("---");
  1498. ui.l_ains->setText("---");
  1499. ui.l_aouts->setText("---");
  1500. ui.l_cvins->setText("---");
  1501. ui.l_cvouts->setText("---");
  1502. ui.l_mins->setText("---");
  1503. ui.l_mouts->setText("---");
  1504. ui.l_pins->setText("---");
  1505. ui.l_pouts->setText("---");
  1506. ui.l_gui->setText("---");
  1507. ui.l_idisp->setText("---");
  1508. ui.l_bridged->setText("---");
  1509. ui.l_synth->setText("---");
  1510. }
  1511. }
  1512. // --------------------------------------------------------------------------------------------------------------------
  1513. void PluginListDialog::refreshPlugins()
  1514. {
  1515. refreshPluginsStop();
  1516. p->discovery.dialog = new PluginRefreshDialog(this);
  1517. QObject::connect(p->discovery.dialog->b_start, &QPushButton::clicked,
  1518. this, &PluginListDialog::refreshPluginsStart);
  1519. QObject::connect(p->discovery.dialog->b_skip, &QPushButton::clicked,
  1520. this, &PluginListDialog::refreshPluginsSkip);
  1521. QObject::connect(p->discovery.dialog, &QDialog::finished,
  1522. this, &PluginListDialog::refreshPluginsStop);
  1523. p->discovery.dialog->exec();
  1524. }
  1525. void PluginListDialog::refreshPluginsStart()
  1526. {
  1527. // remove old plugins
  1528. #ifndef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  1529. p->plugins.internal.clear();
  1530. p->plugins.ladspa.clear();
  1531. p->plugins.dssi.clear();
  1532. #endif
  1533. p->plugins.lv2.clear();
  1534. p->plugins.vst2.clear();
  1535. p->plugins.vst3.clear();
  1536. p->plugins.clap.clear();
  1537. #ifndef CARLA_FRONTEND_ONLY_EMBEDDABLE_PLUGINS
  1538. #ifdef CARLA_OS_MAC
  1539. p->plugins.au.clear();
  1540. #endif
  1541. p->plugins.jsfx.clear();
  1542. p->plugins.kits.clear();
  1543. #endif
  1544. p->discovery.dialog->b_start->setEnabled(false);
  1545. p->discovery.dialog->b_skip->setEnabled(true);
  1546. p->discovery.ignoreCache = p->discovery.dialog->ch_all->isChecked();
  1547. p->discovery.checkInvalid =
  1548. p->discovery.dialog->ch_invalid->isChecked();
  1549. if (p->discovery.ignoreCache)
  1550. p->plugins.cache.clear();
  1551. // start discovery again
  1552. p->discovery.ptype = PLUGIN_NONE;
  1553. if (p->timerId == 0)
  1554. p->timerId = startTimer(0);
  1555. }
  1556. void PluginListDialog::refreshPluginsStop()
  1557. {
  1558. // stop previous discovery if still running
  1559. if (p->discovery.handle != nullptr)
  1560. {
  1561. carla_plugin_discovery_stop(p->discovery.handle);
  1562. p->discovery.handle = nullptr;
  1563. }
  1564. if (p->discovery.dialog)
  1565. {
  1566. p->discovery.dialog->close();
  1567. p->discovery.dialog = nullptr;
  1568. }
  1569. if (p->timerId != 0)
  1570. {
  1571. killTimer(p->timerId);
  1572. p->timerId = 0;
  1573. addPluginsToTable();
  1574. }
  1575. }
  1576. void PluginListDialog::refreshPluginsSkip()
  1577. {
  1578. if (p->discovery.handle != nullptr)
  1579. carla_plugin_discovery_skip(p->discovery.handle);
  1580. }
  1581. // --------------------------------------------------------------------------------------------------------------------
  1582. void PluginListDialog::saveSettings()
  1583. {
  1584. QSafeSettings settings("falkTX", "CarlaDatabase3");
  1585. settings.setValue("PluginDatabase/Geometry", saveGeometry());
  1586. settings.setValue("PluginDatabase/TableGeometry", ui.tableWidget->horizontalHeader()->saveState());
  1587. settings.setValue("PluginDatabase/ShowEffects", ui.ch_effects->isChecked());
  1588. settings.setValue("PluginDatabase/ShowInstruments", ui.ch_instruments->isChecked());
  1589. settings.setValue("PluginDatabase/ShowMIDI", ui.ch_midi->isChecked());
  1590. settings.setValue("PluginDatabase/ShowOther", ui.ch_other->isChecked());
  1591. settings.setValue("PluginDatabase/ShowInternal", ui.ch_internal->isChecked());
  1592. settings.setValue("PluginDatabase/ShowLADSPA", ui.ch_ladspa->isChecked());
  1593. settings.setValue("PluginDatabase/ShowDSSI", ui.ch_dssi->isChecked());
  1594. settings.setValue("PluginDatabase/ShowLV2", ui.ch_lv2->isChecked());
  1595. settings.setValue("PluginDatabase/ShowVST2", ui.ch_vst->isChecked());
  1596. settings.setValue("PluginDatabase/ShowVST3", ui.ch_vst3->isChecked());
  1597. settings.setValue("PluginDatabase/ShowCLAP", ui.ch_clap->isChecked());
  1598. settings.setValue("PluginDatabase/ShowAU", ui.ch_au->isChecked());
  1599. settings.setValue("PluginDatabase/ShowJSFX", ui.ch_jsfx->isChecked());
  1600. settings.setValue("PluginDatabase/ShowKits", ui.ch_kits->isChecked());
  1601. settings.setValue("PluginDatabase/ShowNative", ui.ch_native->isChecked());
  1602. settings.setValue("PluginDatabase/ShowBridged", ui.ch_bridged->isChecked());
  1603. settings.setValue("PluginDatabase/ShowBridgedWine", ui.ch_bridged_wine->isChecked());
  1604. settings.setValue("PluginDatabase/ShowFavorites", ui.ch_favorites->isChecked());
  1605. settings.setValue("PluginDatabase/ShowRtSafe", ui.ch_rtsafe->isChecked());
  1606. settings.setValue("PluginDatabase/ShowHasCV", ui.ch_cv->isChecked());
  1607. settings.setValue("PluginDatabase/ShowHasGUI", ui.ch_gui->isChecked());
  1608. settings.setValue("PluginDatabase/ShowHasInlineDisplay", ui.ch_inline_display->isChecked());
  1609. settings.setValue("PluginDatabase/ShowStereoOnly", ui.ch_stereo->isChecked());
  1610. settings.setValue("PluginDatabase/SearchText", ui.lineEdit->text());
  1611. if (ui.ch_cat_all->isChecked())
  1612. {
  1613. settings.setValue("PluginDatabase/ShowCategory", "all");
  1614. }
  1615. else
  1616. {
  1617. QCarlaString categories;
  1618. if (ui.ch_cat_delay->isChecked())
  1619. categories += ":delay";
  1620. if (ui.ch_cat_distortion->isChecked())
  1621. categories += ":distortion";
  1622. if (ui.ch_cat_dynamics->isChecked())
  1623. categories += ":dynamics";
  1624. if (ui.ch_cat_eq->isChecked())
  1625. categories += ":eq";
  1626. if (ui.ch_cat_filter->isChecked())
  1627. categories += ":filter";
  1628. if (ui.ch_cat_modulator->isChecked())
  1629. categories += ":modulator";
  1630. if (ui.ch_cat_synth->isChecked())
  1631. categories += ":synth";
  1632. if (ui.ch_cat_utility->isChecked())
  1633. categories += ":utility";
  1634. if (ui.ch_cat_other->isChecked())
  1635. categories += ":other";
  1636. if (categories.isNotEmpty())
  1637. categories += ":";
  1638. settings.setValue("PluginDatabase/ShowCategory", categories);
  1639. }
  1640. settings.setValue("PluginListDialog/Favorites", asVariant(p->plugins.favorites));
  1641. }
  1642. // --------------------------------------------------------------------------------------------------------------------
  1643. PluginListDialog*
  1644. carla_frontend_createPluginListDialog(void* const parent)
  1645. {
  1646. const HostSettings hostSettings = {};
  1647. return new PluginListDialog(reinterpret_cast<QWidget*>(parent), hostSettings);
  1648. }
  1649. const PluginListDialogResults*
  1650. carla_frontend_execPluginListDialog(PluginListDialog* const dialog)
  1651. {
  1652. if (dialog->exec())
  1653. {
  1654. static PluginListDialogResults ret;
  1655. static CarlaString category;
  1656. static CarlaString filename;
  1657. static CarlaString name;
  1658. static CarlaString label;
  1659. static CarlaString maker;
  1660. const PluginInfo& plugin(dialog->getSelectedPluginInfo());
  1661. category = plugin.category.toUtf8();
  1662. filename = plugin.filename.toUtf8();
  1663. name = plugin.name.toUtf8();
  1664. label = plugin.label.toUtf8();
  1665. maker = plugin.maker.toUtf8();
  1666. ret.build = plugin.build;
  1667. ret.type = plugin.type;
  1668. ret.hints = plugin.hints;
  1669. ret.category = category;
  1670. ret.filename = filename;
  1671. ret.name = name;
  1672. ret.label = label;
  1673. ret.maker = maker;
  1674. ret.uniqueId = plugin.uniqueId;
  1675. ret.audioIns = plugin.audioIns;
  1676. ret.audioOuts = plugin.audioOuts;
  1677. ret.cvIns = plugin.cvIns;
  1678. ret.cvOuts = plugin.cvOuts;
  1679. ret.midiIns = plugin.midiIns;
  1680. ret.midiOuts = plugin.midiOuts;
  1681. ret.parameterIns = plugin.parameterIns;
  1682. ret.parameterOuts = plugin.parameterOuts;
  1683. return &ret;
  1684. }
  1685. return nullptr;
  1686. }
  1687. // --------------------------------------------------------------------------------------------------------------------
  1688. const PluginListDialogResults*
  1689. carla_frontend_createAndExecPluginListDialog(void* const parent/*, const HostSettings& hostSettings*/)
  1690. {
  1691. const HostSettings hostSettings = {};
  1692. PluginListDialog gui(reinterpret_cast<QWidget*>(parent), hostSettings);
  1693. return carla_frontend_execPluginListDialog(&gui);
  1694. }
  1695. // --------------------------------------------------------------------------------------------------------------------