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.

2103 lines
76KB

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