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.

1495 lines
48KB

  1. /*
  2. * DISTRHO Ildaeil Plugin
  3. * Copyright (C) 2021-2023 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the LICENSE file.
  16. */
  17. #include "IldaeilBasePlugin.hpp"
  18. #include "DistrhoUI.hpp"
  19. #if ILDAEIL_STANDALONE
  20. #include "DistrhoStandaloneUtils.hpp"
  21. #endif
  22. #include "CarlaBackendUtils.hpp"
  23. #include "PluginHostWindow.hpp"
  24. #include "extra/Runner.hpp"
  25. // IDE helper
  26. #include "DearImGui.hpp"
  27. #include <string>
  28. #include <vector>
  29. // strcasestr
  30. #ifdef DISTRHO_OS_WINDOWS
  31. # include <shlwapi.h>
  32. namespace ildaeil {
  33. inline const char* strcasestr(const char* const haystack, const char* const needle)
  34. {
  35. return StrStrIA(haystack, needle);
  36. }
  37. // using strcasestr = StrStrIA;
  38. }
  39. #else
  40. namespace ildaeil {
  41. using ::strcasestr;
  42. }
  43. #endif
  44. // #define WASM_TESTING
  45. START_NAMESPACE_DISTRHO
  46. using namespace CARLA_BACKEND_NAMESPACE;
  47. // --------------------------------------------------------------------------------------------------------------------
  48. class IldaeilUI : public UI,
  49. public Runner,
  50. public PluginHostWindow::Callbacks
  51. {
  52. static constexpr const uint kGenericWidth = 380;
  53. static constexpr const uint kGenericHeight = 400;
  54. static constexpr const uint kButtonHeight = 20;
  55. struct PluginInfoCache {
  56. BinaryType btype;
  57. uint64_t uniqueId;
  58. std::string filename;
  59. std::string name;
  60. std::string label;
  61. };
  62. struct PluginGenericUI {
  63. char* title;
  64. uint parameterCount;
  65. struct Parameter {
  66. char* name;
  67. char* printformat;
  68. uint32_t rindex;
  69. bool boolean, bvalue, log, readonly;
  70. float min, max, power;
  71. Parameter()
  72. : name(nullptr),
  73. printformat(nullptr),
  74. rindex(0),
  75. boolean(false),
  76. bvalue(false),
  77. log(false),
  78. min(0.0f),
  79. max(1.0f) {}
  80. ~Parameter()
  81. {
  82. std::free(name);
  83. std::free(printformat);
  84. }
  85. }* parameters;
  86. float* values;
  87. uint presetCount;
  88. struct Preset {
  89. uint32_t index;
  90. char* name;
  91. ~Preset()
  92. {
  93. std::free(name);
  94. }
  95. }* presets;
  96. int currentPreset;
  97. const char** presetStrings;
  98. PluginGenericUI()
  99. : title(nullptr),
  100. parameterCount(0),
  101. parameters(nullptr),
  102. values(nullptr),
  103. presetCount(0),
  104. presets(nullptr),
  105. currentPreset(-1),
  106. presetStrings(nullptr) {}
  107. ~PluginGenericUI()
  108. {
  109. std::free(title);
  110. delete[] parameters;
  111. delete[] values;
  112. }
  113. };
  114. enum {
  115. kDrawingLoading,
  116. kDrawingPluginError,
  117. kDrawingPluginList,
  118. kDrawingPluginEmbedUI,
  119. kDrawingPluginGenericUI,
  120. kDrawingErrorInit,
  121. kDrawingErrorDraw
  122. } fDrawingState;
  123. enum {
  124. kIdleInit,
  125. kIdleInitPluginAlreadyLoaded,
  126. kIdleLoadSelectedPlugin,
  127. kIdlePluginLoadedFromDSP,
  128. kIdleResetPlugin,
  129. kIdleOpenFileUI,
  130. kIdleShowCustomUI,
  131. kIdleHideEmbedAndShowGenericUI,
  132. kIdleHidePluginUI,
  133. kIdleGiveIdleToUI,
  134. kIdleChangePluginType,
  135. kIdleNothing
  136. } fIdleState = kIdleInit;
  137. IldaeilBasePlugin* const fPlugin;
  138. PluginHostWindow fPluginHostWindow;
  139. PluginType fPluginType;
  140. PluginType fNextPluginType;
  141. uint fPluginId;
  142. int fPluginSelected;
  143. bool fPluginScanningFinished;
  144. bool fPluginHasCustomUI;
  145. bool fPluginHasEmbedUI;
  146. bool fPluginHasFileOpen;
  147. bool fPluginHasOutputParameters;
  148. bool fPluginRunning;
  149. bool fPluginWillRunInBridgeMode;
  150. Mutex fPluginsMutex;
  151. PluginInfoCache fCurrentPluginInfo;
  152. std::vector<PluginInfoCache> fPlugins;
  153. ScopedPointer<PluginGenericUI> fPluginGenericUI;
  154. bool fPluginSearchActive;
  155. bool fPluginSearchFirstShow;
  156. char fPluginSearchString[0xff];
  157. String fPopupError, fPluginFilename;
  158. Size<uint> fNextSize;
  159. struct RunnerData {
  160. bool needsReinit;
  161. CarlaPluginDiscoveryHandle handle;
  162. RunnerData()
  163. : needsReinit(true),
  164. handle(nullptr) {}
  165. void init()
  166. {
  167. needsReinit = true;
  168. if (handle != nullptr)
  169. {
  170. carla_plugin_discovery_stop(handle);
  171. handle = nullptr;
  172. }
  173. }
  174. } fRunnerData;
  175. public:
  176. IldaeilUI()
  177. : UI(kInitialWidth, kInitialHeight),
  178. Runner("IldaeilScanner"),
  179. fDrawingState(kDrawingLoading),
  180. fIdleState(kIdleInit),
  181. fPlugin((IldaeilBasePlugin*)getPluginInstancePointer()),
  182. fPluginHostWindow(getWindow(), this),
  183. fPluginType(PLUGIN_LV2),
  184. fNextPluginType(fPluginType),
  185. fPluginId(0),
  186. fPluginSelected(-1),
  187. fPluginScanningFinished(false),
  188. fPluginHasCustomUI(false),
  189. fPluginHasEmbedUI(false),
  190. fPluginHasFileOpen(false),
  191. fPluginHasOutputParameters(false),
  192. fPluginRunning(false),
  193. fPluginWillRunInBridgeMode(false),
  194. fCurrentPluginInfo(),
  195. fPluginSearchActive(false),
  196. fPluginSearchFirstShow(false),
  197. fRunnerData()
  198. {
  199. const double scaleFactor = getScaleFactor();
  200. if (fPlugin == nullptr || fPlugin->fCarlaHostHandle == nullptr)
  201. {
  202. fDrawingState = kDrawingErrorInit;
  203. fIdleState = kIdleNothing;
  204. fPopupError = "Ildaeil backend failed to init properly, cannot continue.";
  205. setSize(kInitialWidth * scaleFactor * 0.5, kInitialHeight * scaleFactor * 0.5);
  206. return;
  207. }
  208. std::strcpy(fPluginSearchString, "Search...");
  209. ImGuiStyle& style(ImGui::GetStyle());
  210. style.FrameRounding = 4;
  211. const double paddingY = style.WindowPadding.y * 2;
  212. if (d_isNotEqual(scaleFactor, 1.0))
  213. {
  214. setSize(kInitialWidth * scaleFactor, kInitialHeight * scaleFactor);
  215. fPluginHostWindow.setPositionAndSize(0, kButtonHeight * scaleFactor + paddingY,
  216. kInitialWidth * scaleFactor,
  217. (kInitialHeight - kButtonHeight) * scaleFactor - paddingY);
  218. }
  219. else
  220. {
  221. fPluginHostWindow.setPositionAndSize(0, kButtonHeight + paddingY,
  222. kInitialWidth, kInitialHeight - kButtonHeight - paddingY);
  223. }
  224. const CarlaHostHandle handle = fPlugin->fCarlaHostHandle;
  225. char winIdStr[24];
  226. std::snprintf(winIdStr, sizeof(winIdStr), "%lx", (ulong)getWindow().getNativeWindowHandle());
  227. carla_set_engine_option(handle, ENGINE_OPTION_FRONTEND_WIN_ID, 0, winIdStr);
  228. carla_set_engine_option(handle, ENGINE_OPTION_FRONTEND_UI_SCALE, scaleFactor*1000, nullptr);
  229. if (checkIfPluginIsLoaded())
  230. fIdleState = kIdleInitPluginAlreadyLoaded;
  231. fPlugin->fUI = this;
  232. #ifdef WASM_TESTING
  233. if (carla_add_plugin(handle, BINARY_NATIVE, PLUGIN_INTERNAL, nullptr, nullptr,
  234. "midifile", 0, 0x0, PLUGIN_OPTIONS_NULL))
  235. {
  236. d_stdout("Special hack for MIDI file playback activated");
  237. carla_set_custom_data(handle, 0, CUSTOM_DATA_TYPE_PATH, "file", "/furelise.mid");
  238. carla_set_parameter_value(handle, 0, 0, 1.0f);
  239. carla_set_parameter_value(handle, 0, 1, 0.0f);
  240. fPluginId = 2;
  241. }
  242. carla_add_plugin(handle, BINARY_NATIVE, PLUGIN_INTERNAL, nullptr, nullptr, "miditranspose", 0, 0x0, PLUGIN_OPTIONS_NULL);
  243. carla_add_plugin(handle, BINARY_NATIVE, PLUGIN_INTERNAL, nullptr, nullptr, "bypass", 0, 0x0, PLUGIN_OPTIONS_NULL);
  244. carla_add_plugin(handle, BINARY_NATIVE, PLUGIN_INTERNAL, nullptr, nullptr, "3bandeq", 0, 0x0, PLUGIN_OPTIONS_NULL);
  245. carla_add_plugin(handle, BINARY_NATIVE, PLUGIN_INTERNAL, nullptr, nullptr, "pingpongpan", 0, 0x0, PLUGIN_OPTIONS_NULL);
  246. carla_set_parameter_value(handle, 4, 1, 0.0f);
  247. carla_add_plugin(handle, BINARY_NATIVE, PLUGIN_INTERNAL, nullptr, nullptr, "audiogain_s", 0, 0x0, PLUGIN_OPTIONS_NULL);
  248. for (uint i=0; i<5; ++i)
  249. carla_add_plugin(handle, BINARY_NATIVE, PLUGIN_INTERNAL, nullptr, nullptr, "bypass", 0, 0x0, PLUGIN_OPTIONS_NULL);
  250. #endif
  251. }
  252. ~IldaeilUI() override
  253. {
  254. if (fPlugin != nullptr && fPlugin->fCarlaHostHandle != nullptr)
  255. {
  256. fPlugin->fUI = nullptr;
  257. if (fPluginRunning)
  258. hidePluginUI(fPlugin->fCarlaHostHandle);
  259. carla_set_engine_option(fPlugin->fCarlaHostHandle, ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0");
  260. }
  261. stopRunner();
  262. fPluginGenericUI = nullptr;
  263. }
  264. bool checkIfPluginIsLoaded()
  265. {
  266. const CarlaHostHandle handle = fPlugin->fCarlaHostHandle;
  267. if (carla_get_current_plugin_count(handle) == 0)
  268. return false;
  269. const uint hints = carla_get_plugin_info(handle, fPluginId)->hints;
  270. updatePluginFlags(hints);
  271. fPluginRunning = true;
  272. return true;
  273. }
  274. void updatePluginFlags(const uint hints) noexcept
  275. {
  276. if (hints & PLUGIN_HAS_CUSTOM_UI_USING_FILE_OPEN)
  277. {
  278. fPluginHasCustomUI = false;
  279. fPluginHasEmbedUI = false;
  280. fPluginHasFileOpen = true;
  281. }
  282. else
  283. {
  284. fPluginHasCustomUI = hints & PLUGIN_HAS_CUSTOM_UI;
  285. #ifndef DISTRHO_OS_WASM
  286. fPluginHasEmbedUI = hints & PLUGIN_HAS_CUSTOM_EMBED_UI;
  287. #endif
  288. fPluginHasFileOpen = false;
  289. }
  290. }
  291. void projectLoadedFromDSP()
  292. {
  293. if (checkIfPluginIsLoaded())
  294. fIdleState = kIdlePluginLoadedFromDSP;
  295. }
  296. void changeParameterFromDSP(const uint32_t index, const float value)
  297. {
  298. if (PluginGenericUI* const ui = fPluginGenericUI)
  299. {
  300. for (uint32_t i=0; i < ui->parameterCount; ++i)
  301. {
  302. if (ui->parameters[i].rindex != index)
  303. continue;
  304. ui->values[i] = value;
  305. if (ui->parameters[i].boolean)
  306. ui->parameters[i].bvalue = value > ui->parameters[i].min;
  307. break;
  308. }
  309. }
  310. repaint();
  311. }
  312. void closeUI()
  313. {
  314. if (fIdleState == kIdleGiveIdleToUI)
  315. fIdleState = kIdleNothing;
  316. }
  317. const char* openFileFromDSP(const bool /*isDir*/, const char* const title, const char* const /*filter*/)
  318. {
  319. DISTRHO_SAFE_ASSERT_RETURN(fPluginType == PLUGIN_INTERNAL || fPluginType == PLUGIN_LV2, nullptr);
  320. FileBrowserOptions opts;
  321. opts.title = title;
  322. openFileBrowser(opts);
  323. return nullptr;
  324. }
  325. void showPluginUI(const CarlaHostHandle handle, const bool showIfNotEmbed)
  326. {
  327. #ifndef DISTRHO_OS_WASM
  328. const uint hints = carla_get_plugin_info(handle, fPluginId)->hints;
  329. if (hints & PLUGIN_HAS_CUSTOM_EMBED_UI)
  330. {
  331. fDrawingState = kDrawingPluginEmbedUI;
  332. fIdleState = kIdleGiveIdleToUI;
  333. fPluginHasCustomUI = true;
  334. fPluginHasEmbedUI = true;
  335. fPluginHasFileOpen = false;
  336. carla_embed_custom_ui(handle, fPluginId, fPluginHostWindow.attachAndGetWindowHandle());
  337. }
  338. else
  339. #endif
  340. {
  341. // fPluginHas* flags are updated in the next function
  342. createOrUpdatePluginGenericUI(handle);
  343. if (showIfNotEmbed && fPluginHasCustomUI)
  344. {
  345. fIdleState = kIdleGiveIdleToUI;
  346. carla_show_custom_ui(handle, fPluginId, true);
  347. }
  348. }
  349. repaint();
  350. }
  351. void hidePluginUI(const CarlaHostHandle handle)
  352. {
  353. DISTRHO_SAFE_ASSERT_RETURN(fPluginRunning,);
  354. if (fPluginHostWindow.hide())
  355. carla_show_custom_ui(handle, fPluginId, false);
  356. }
  357. void createOrUpdatePluginGenericUI(const CarlaHostHandle handle, const CarlaPluginInfo* info = nullptr)
  358. {
  359. if (info == nullptr)
  360. info = carla_get_plugin_info(handle, fPluginId);
  361. fDrawingState = kDrawingPluginGenericUI;
  362. updatePluginFlags(info->hints);
  363. if (fPluginGenericUI == nullptr)
  364. createPluginGenericUI(handle, info);
  365. else
  366. updatePluginGenericUI(handle);
  367. #if !ILDAEIL_STANDALONE
  368. const double scaleFactor = getScaleFactor();
  369. fNextSize = Size<uint>(kGenericWidth * scaleFactor,
  370. (kGenericHeight + ImGui::GetStyle().WindowPadding.y) * scaleFactor);
  371. #endif
  372. }
  373. void createPluginGenericUI(const CarlaHostHandle handle, const CarlaPluginInfo* const info)
  374. {
  375. PluginGenericUI* const ui = new PluginGenericUI;
  376. String title(info->name);
  377. title += " by ";
  378. title += info->maker;
  379. ui->title = title.getAndReleaseBuffer();
  380. const uint32_t parameterCount = ui->parameterCount = carla_get_parameter_count(handle, fPluginId);
  381. // make count of valid parameters
  382. for (uint32_t i=0; i < parameterCount; ++i)
  383. {
  384. const ParameterData* const pdata = carla_get_parameter_data(handle, fPluginId, i);
  385. if ((pdata->hints & PARAMETER_IS_ENABLED) == 0x0)
  386. {
  387. --ui->parameterCount;
  388. continue;
  389. }
  390. if (pdata->type == PARAMETER_OUTPUT)
  391. fPluginHasOutputParameters = true;
  392. }
  393. ui->parameters = new PluginGenericUI::Parameter[ui->parameterCount];
  394. ui->values = new float[ui->parameterCount];
  395. // now safely fill in details
  396. for (uint32_t i=0, j=0; i < parameterCount; ++i)
  397. {
  398. const ParameterData* const pdata = carla_get_parameter_data(handle, fPluginId, i);
  399. if ((pdata->hints & PARAMETER_IS_ENABLED) == 0x0)
  400. continue;
  401. const CarlaParameterInfo* const pinfo = carla_get_parameter_info(handle, fPluginId, i);
  402. const ::ParameterRanges* const pranges = carla_get_parameter_ranges(handle, fPluginId, i);
  403. String printformat;
  404. if (pdata->hints & PARAMETER_IS_INTEGER)
  405. printformat = "%.0f ";
  406. else
  407. printformat = "%.3f ";
  408. printformat += pinfo->unit;
  409. PluginGenericUI::Parameter& param(ui->parameters[j]);
  410. param.name = strdup(pinfo->name);
  411. param.printformat = printformat.getAndReleaseBuffer();
  412. param.rindex = i;
  413. param.boolean = pdata->hints & PARAMETER_IS_BOOLEAN;
  414. param.log = pdata->hints & PARAMETER_IS_LOGARITHMIC;
  415. param.readonly = pdata->type != PARAMETER_INPUT || (pdata->hints & PARAMETER_IS_READ_ONLY);
  416. param.min = pranges->min;
  417. param.max = pranges->max;
  418. ui->values[j] = carla_get_current_parameter_value(handle, fPluginId, i);
  419. if (param.boolean)
  420. param.bvalue = ui->values[j] > param.min;
  421. else
  422. param.bvalue = false;
  423. ++j;
  424. }
  425. // handle presets too
  426. const uint32_t presetCount = ui->presetCount = carla_get_program_count(handle, fPluginId);
  427. for (uint32_t i=0; i < presetCount; ++i)
  428. {
  429. const char* const pname = carla_get_program_name(handle, fPluginId, i);
  430. if (pname[0] == '\0')
  431. {
  432. --ui->presetCount;
  433. continue;
  434. }
  435. }
  436. ui->presets = new PluginGenericUI::Preset[ui->presetCount];
  437. ui->presetStrings = new const char*[ui->presetCount];
  438. for (uint32_t i=0, j=0; i < presetCount; ++i)
  439. {
  440. const char* const pname = carla_get_program_name(handle, fPluginId, i);
  441. if (pname[0] == '\0')
  442. continue;
  443. PluginGenericUI::Preset& preset(ui->presets[j]);
  444. preset.index = i;
  445. preset.name = strdup(pname);
  446. ui->presetStrings[j] = preset.name;
  447. ++j;
  448. }
  449. ui->currentPreset = -1;
  450. fPluginGenericUI = ui;
  451. }
  452. void updatePluginGenericUI(const CarlaHostHandle handle)
  453. {
  454. PluginGenericUI* const ui = fPluginGenericUI;
  455. DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,);
  456. for (uint32_t i=0; i < ui->parameterCount; ++i)
  457. {
  458. ui->values[i] = carla_get_current_parameter_value(handle, fPluginId, ui->parameters[i].rindex);
  459. if (ui->parameters[i].boolean)
  460. ui->parameters[i].bvalue = ui->values[i] > ui->parameters[i].min;
  461. }
  462. }
  463. bool loadPlugin(const CarlaHostHandle handle, const PluginInfoCache& info)
  464. {
  465. if (fPluginRunning || fPluginId != 0)
  466. {
  467. hidePluginUI(handle);
  468. carla_replace_plugin(handle, fPluginId);
  469. }
  470. carla_set_engine_option(handle, ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, fPluginWillRunInBridgeMode, nullptr);
  471. const MutexLocker cml(fPlugin->sPluginInfoLoadMutex);
  472. const bool ok = carla_add_plugin(handle,
  473. info.btype,
  474. fPluginType,
  475. info.filename.c_str(),
  476. info.name.c_str(),
  477. info.label.c_str(),
  478. info.uniqueId,
  479. nullptr,
  480. PLUGIN_OPTIONS_NULL);
  481. if (ok)
  482. {
  483. fPluginRunning = true;
  484. fPluginGenericUI = nullptr;
  485. fPluginFilename.clear();
  486. showPluginUI(handle, false);
  487. #ifdef WASM_TESTING
  488. d_stdout("loaded a plugin with label '%s'", label);
  489. if (std::strcmp(label, "audiofile") == 0)
  490. {
  491. d_stdout("Loading mp3 file into audiofile plugin");
  492. carla_set_custom_data(handle, fPluginId, CUSTOM_DATA_TYPE_PATH, "file", "/foolme.mp3");
  493. carla_set_parameter_value(handle, fPluginId, 1, 0.0f);
  494. fPluginGenericUI->values[1] = 0.0f;
  495. }
  496. #endif
  497. }
  498. else
  499. {
  500. fPopupError = carla_get_last_error(handle);
  501. d_stdout("got error: %s", fPopupError.buffer());
  502. fDrawingState = kDrawingPluginError;
  503. }
  504. repaint();
  505. return ok;
  506. }
  507. void loadFileAsPlugin(const CarlaHostHandle handle, const char* const filename)
  508. {
  509. if (fPluginRunning || fPluginId != 0)
  510. {
  511. hidePluginUI(handle);
  512. carla_replace_plugin(handle, fPluginId);
  513. }
  514. carla_set_engine_option(handle, ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, fPluginWillRunInBridgeMode, nullptr);
  515. const MutexLocker cml(fPlugin->sPluginInfoLoadMutex);
  516. if (carla_load_file(handle, filename))
  517. {
  518. fPluginRunning = true;
  519. fPluginGenericUI = nullptr;
  520. fPluginFilename = filename;
  521. showPluginUI(handle, false);
  522. }
  523. else
  524. {
  525. fPopupError = carla_get_last_error(handle);
  526. d_stdout("got error: %s", fPopupError.buffer());
  527. fDrawingState = kDrawingPluginError;
  528. fPluginFilename.clear();
  529. }
  530. repaint();
  531. }
  532. protected:
  533. void pluginWindowResized(const uint width, const uint height) override
  534. {
  535. const uint extraHeight = kButtonHeight * getScaleFactor() + ImGui::GetStyle().WindowPadding.y * 2;
  536. fNextSize = Size<uint>(width, height + extraHeight);
  537. }
  538. void uiIdle() override
  539. {
  540. const CarlaHostHandle handle = fPlugin->fCarlaHostHandle;
  541. DISTRHO_SAFE_ASSERT_RETURN(handle != nullptr,);
  542. // carla_juce_idle();
  543. if (fDrawingState == kDrawingPluginGenericUI && fPluginGenericUI != nullptr && fPluginHasOutputParameters)
  544. {
  545. updatePluginGenericUI(handle);
  546. repaint();
  547. }
  548. if (fNextSize.isValid())
  549. {
  550. setSize(fNextSize);
  551. fNextSize = Size<uint>();
  552. }
  553. switch (fIdleState)
  554. {
  555. case kIdleInit:
  556. fIdleState = kIdleNothing;
  557. initAndStartRunner();
  558. break;
  559. case kIdleInitPluginAlreadyLoaded:
  560. fIdleState = kIdleNothing;
  561. showPluginUI(handle, false);
  562. initAndStartRunner();
  563. break;
  564. case kIdlePluginLoadedFromDSP:
  565. fIdleState = kIdleNothing;
  566. showPluginUI(handle, false);
  567. break;
  568. case kIdleLoadSelectedPlugin:
  569. fIdleState = kIdleNothing;
  570. loadSelectedPlugin(handle);
  571. break;
  572. case kIdleResetPlugin:
  573. fIdleState = kIdleNothing;
  574. if (fPluginFilename.isNotEmpty())
  575. loadFileAsPlugin(handle, fPluginFilename.buffer());
  576. else
  577. loadPlugin(handle, fCurrentPluginInfo);
  578. break;
  579. case kIdleOpenFileUI:
  580. fIdleState = kIdleNothing;
  581. carla_show_custom_ui(handle, fPluginId, true);
  582. break;
  583. case kIdleShowCustomUI:
  584. fIdleState = kIdleNothing;
  585. showPluginUI(handle, true);
  586. break;
  587. case kIdleHideEmbedAndShowGenericUI:
  588. fIdleState = kIdleNothing;
  589. hidePluginUI(handle);
  590. createOrUpdatePluginGenericUI(handle);
  591. break;
  592. case kIdleHidePluginUI:
  593. fIdleState = kIdleNothing;
  594. hidePluginUI(handle);
  595. break;
  596. case kIdleGiveIdleToUI:
  597. if (fPlugin->fCarlaPluginDescriptor->ui_idle != nullptr)
  598. fPlugin->fCarlaPluginDescriptor->ui_idle(fPlugin->fCarlaPluginHandle);
  599. fPluginHostWindow.idle();
  600. break;
  601. case kIdleChangePluginType:
  602. fIdleState = kIdleNothing;
  603. if (fPluginRunning)
  604. hidePluginUI(handle);
  605. if (fNextPluginType == PLUGIN_TYPE_COUNT)
  606. {
  607. FileBrowserOptions opts;
  608. opts.title = "Load from file";
  609. openFileBrowser(opts);
  610. }
  611. else
  612. {
  613. fPluginSelected = -1;
  614. stopRunner();
  615. fPluginType = fNextPluginType;
  616. initAndStartRunner();
  617. }
  618. break;
  619. case kIdleNothing:
  620. break;
  621. }
  622. }
  623. void loadSelectedPlugin(const CarlaHostHandle handle)
  624. {
  625. DISTRHO_SAFE_ASSERT_RETURN(fPluginSelected >= 0,);
  626. PluginInfoCache info;
  627. {
  628. const MutexLocker cml(fPluginsMutex);
  629. info = fPlugins[fPluginSelected];
  630. }
  631. d_stdout("Loading %s...", info.name.c_str());
  632. if (loadPlugin(handle, info))
  633. fCurrentPluginInfo = info;
  634. }
  635. void uiFileBrowserSelected(const char* const filename) override
  636. {
  637. if (fPlugin != nullptr && fPlugin->fCarlaHostHandle != nullptr && filename != nullptr)
  638. {
  639. if (fNextPluginType == PLUGIN_TYPE_COUNT)
  640. loadFileAsPlugin(fPlugin->fCarlaHostHandle, filename);
  641. else
  642. carla_set_custom_data(fPlugin->fCarlaHostHandle, fPluginId, CUSTOM_DATA_TYPE_PATH, "file", filename);
  643. }
  644. }
  645. bool initAndStartRunner()
  646. {
  647. if (isRunnerActive())
  648. stopRunner();
  649. fRunnerData.init();
  650. return startRunner();
  651. }
  652. bool run() override
  653. {
  654. if (fRunnerData.needsReinit)
  655. {
  656. fRunnerData.needsReinit = false;
  657. fPluginScanningFinished = false;
  658. {
  659. const MutexLocker cml(fPluginsMutex);
  660. fPlugins.clear();
  661. }
  662. {
  663. const MutexLocker cml(fPlugin->sPluginInfoLoadMutex);
  664. d_stdout("Will scan plugins now...");
  665. fRunnerData.handle = carla_plugin_discovery_start(fPlugin->fDiscoveryTool,
  666. fPluginType,
  667. IldaeilBasePlugin::getPluginPath(fPluginType),
  668. _binaryPluginSearchCallback, this);
  669. }
  670. if (fDrawingState == kDrawingLoading)
  671. {
  672. fDrawingState = kDrawingPluginList;
  673. fPluginSearchFirstShow = true;
  674. }
  675. if (fRunnerData.handle == nullptr)
  676. {
  677. d_stdout("Nothing found!");
  678. fPluginScanningFinished = true;
  679. return false;
  680. }
  681. }
  682. DISTRHO_SAFE_ASSERT_RETURN(!fPluginScanningFinished, false);
  683. DISTRHO_SAFE_ASSERT_RETURN(fRunnerData.handle != nullptr, false);
  684. bool ok;
  685. {
  686. const MutexLocker cml(fPlugin->sPluginInfoLoadMutex);
  687. ok = carla_plugin_discovery_idle(fRunnerData.handle);
  688. }
  689. if (ok)
  690. return true;
  691. // stop here
  692. {
  693. const MutexLocker cml(fPlugin->sPluginInfoLoadMutex);
  694. d_stdout("Found %lu plugins!", (ulong)fPlugins.size());
  695. carla_plugin_discovery_stop(fRunnerData.handle);
  696. fRunnerData.handle = nullptr;
  697. }
  698. fPluginScanningFinished = true;
  699. return false;
  700. }
  701. void binaryPluginSearchCallback(const CarlaPluginDiscoveryInfo* const info)
  702. {
  703. if (info->io.cvIns != 0 || info->io.cvOuts != 0)
  704. return;
  705. if (info->io.midiIns != 0 && info->io.midiIns != 1)
  706. return;
  707. if (info->io.midiOuts != 0 && info->io.midiOuts != 1)
  708. return;
  709. #if ILDAEIL_STANDALONE
  710. if (fPluginType == PLUGIN_INTERNAL)
  711. {
  712. if (std::strcmp(info->label, "audiogain") == 0)
  713. return;
  714. if (std::strcmp(info->label, "midichanfilter") == 0)
  715. return;
  716. if (std::strcmp(info->label, "midichannelize") == 0)
  717. return;
  718. }
  719. #elif DISTRHO_PLUGIN_IS_SYNTH
  720. if (info->io.midiIns != 1)
  721. return;
  722. if (info->io.audioIns == 0)
  723. return;
  724. if ((info->metadata.hints & PLUGIN_IS_SYNTH) == 0x0)
  725. return;
  726. #elif DISTRHO_PLUGIN_WANT_MIDI_OUTPUT
  727. if ((info->io.midiIns != 1 && info->io.audioIns != 0 && info->io.audioOuts != 0) || info->io.midiOuts != 1)
  728. return;
  729. if (info->io.audioIns != 0 || info->io.audioOuts != 0)
  730. return;
  731. #else
  732. if (info->io.audioIns != 1 && info->io.audioIns != 2)
  733. return;
  734. if (info->io.audioOuts != 1 && info->io.audioOuts != 2)
  735. return;
  736. #endif
  737. if (fPluginType == PLUGIN_INTERNAL)
  738. {
  739. #if !ILDAEIL_STANDALONE
  740. if (std::strcmp(info->label, "audiogain_s") == 0)
  741. return;
  742. #endif
  743. if (std::strcmp(info->label, "lfo") == 0)
  744. return;
  745. if (std::strcmp(info->label, "midi2cv") == 0)
  746. return;
  747. if (std::strcmp(info->label, "midithrough") == 0)
  748. return;
  749. if (std::strcmp(info->label, "3bandsplitter") == 0)
  750. return;
  751. }
  752. const PluginInfoCache pinfo = {
  753. info->btype,
  754. info->uniqueId,
  755. info->filename,
  756. info->metadata.name,
  757. info->label,
  758. };
  759. const MutexLocker cml(fPluginsMutex);
  760. fPlugins.push_back(pinfo);
  761. }
  762. static void _binaryPluginSearchCallback(void* ptr, const CarlaPluginDiscoveryInfo* info)
  763. {
  764. static_cast<IldaeilUI*>(ptr)->binaryPluginSearchCallback(info);
  765. }
  766. void onImGuiDisplay() override
  767. {
  768. switch (fDrawingState)
  769. {
  770. case kDrawingLoading:
  771. drawLoading();
  772. break;
  773. case kDrawingPluginError:
  774. ImGui::OpenPopup("Plugin Error");
  775. // call ourselves again with the plugin list
  776. fDrawingState = kDrawingPluginList;
  777. onImGuiDisplay();
  778. break;
  779. case kDrawingPluginList:
  780. drawPluginList();
  781. break;
  782. case kDrawingPluginGenericUI:
  783. drawTopBar();
  784. drawGenericUI();
  785. break;
  786. case kDrawingPluginEmbedUI:
  787. drawTopBar();
  788. break;
  789. case kDrawingErrorInit:
  790. fDrawingState = kDrawingErrorDraw;
  791. drawError(true);
  792. break;
  793. case kDrawingErrorDraw:
  794. drawError(false);
  795. break;
  796. }
  797. }
  798. void drawError(const bool open)
  799. {
  800. ImGui::SetNextWindowPos(ImVec2(0, 0));
  801. ImGui::SetNextWindowSize(ImVec2(getWidth(), getHeight()));
  802. const int flags = ImGuiWindowFlags_NoSavedSettings
  803. | ImGuiWindowFlags_NoTitleBar
  804. | ImGuiWindowFlags_NoResize
  805. | ImGuiWindowFlags_NoCollapse
  806. | ImGuiWindowFlags_NoScrollbar
  807. | ImGuiWindowFlags_NoScrollWithMouse;
  808. if (ImGui::Begin("Error Window", nullptr, flags))
  809. {
  810. if (open)
  811. ImGui::OpenPopup("Engine Error");
  812. const int pflags = ImGuiWindowFlags_NoSavedSettings
  813. | ImGuiWindowFlags_NoResize
  814. | ImGuiWindowFlags_NoCollapse
  815. | ImGuiWindowFlags_NoScrollbar
  816. | ImGuiWindowFlags_NoScrollWithMouse
  817. | ImGuiWindowFlags_AlwaysAutoResize
  818. | ImGuiWindowFlags_AlwaysUseWindowPadding;
  819. if (ImGui::BeginPopupModal("Engine Error", nullptr, pflags))
  820. {
  821. ImGui::TextUnformatted(fPopupError.buffer(), nullptr);
  822. ImGui::EndPopup();
  823. }
  824. }
  825. ImGui::End();
  826. }
  827. void drawTopBar()
  828. {
  829. const double scaleFactor = getScaleFactor();
  830. const float padding = ImGui::GetStyle().WindowPadding.y * 2;
  831. ImGui::SetNextWindowPos(ImVec2(0, 0));
  832. ImGui::SetNextWindowSize(ImVec2(getWidth(), kButtonHeight * scaleFactor + padding));
  833. const int flags = ImGuiWindowFlags_NoSavedSettings
  834. | ImGuiWindowFlags_NoTitleBar
  835. | ImGuiWindowFlags_NoResize
  836. | ImGuiWindowFlags_NoCollapse
  837. | ImGuiWindowFlags_NoScrollbar
  838. | ImGuiWindowFlags_NoScrollWithMouse;
  839. if (ImGui::Begin("Current Plugin", nullptr, flags))
  840. {
  841. if (ImGui::Button("Pick Another..."))
  842. {
  843. fIdleState = kIdleHidePluginUI;
  844. fDrawingState = kDrawingPluginList;
  845. #if !ILDAEIL_STANDALONE
  846. fNextSize = Size<uint>(kInitialWidth * scaleFactor, kInitialHeight * scaleFactor);
  847. #endif
  848. }
  849. ImGui::SameLine();
  850. if (ImGui::Button("Reset"))
  851. fIdleState = kIdleResetPlugin;
  852. if (fDrawingState == kDrawingPluginGenericUI)
  853. {
  854. if (fPluginHasCustomUI)
  855. {
  856. ImGui::SameLine();
  857. if (ImGui::Button("Show Custom GUI"))
  858. fIdleState = kIdleShowCustomUI;
  859. }
  860. if (fPluginHasFileOpen)
  861. {
  862. ImGui::SameLine();
  863. if (ImGui::Button("Open File..."))
  864. fIdleState = kIdleOpenFileUI;
  865. }
  866. #ifdef WASM_TESTING
  867. ImGui::SameLine();
  868. ImGui::TextUnformatted(" Plugin to control:");
  869. for (uint i=1; i<10; ++i)
  870. {
  871. char txt[8];
  872. sprintf(txt, "%d", i);
  873. ImGui::SameLine();
  874. if (ImGui::Button(txt))
  875. {
  876. fPluginId = i;
  877. fPluginGenericUI = nullptr;
  878. fIdleState = kIdleHideEmbedAndShowGenericUI;
  879. }
  880. }
  881. #endif
  882. }
  883. if (fDrawingState == kDrawingPluginEmbedUI)
  884. {
  885. ImGui::SameLine();
  886. if (ImGui::Button("Show Generic GUI"))
  887. fIdleState = kIdleHideEmbedAndShowGenericUI;
  888. }
  889. #if ILDAEIL_STANDALONE
  890. if (isUsingNativeAudio())
  891. {
  892. ImGui::SameLine();
  893. ImGui::Spacing();
  894. ImGui::SameLine();
  895. if (supportsAudioInput() && !isAudioInputEnabled() && ImGui::Button("Enable Input"))
  896. requestAudioInput();
  897. ImGui::SameLine();
  898. if (supportsMIDI() && !isMIDIEnabled() && ImGui::Button("Enable MIDI"))
  899. requestMIDI();
  900. if (supportsBufferSizeChanges())
  901. {
  902. ImGui::SameLine();
  903. ImGui::Spacing();
  904. ImGui::SameLine();
  905. ImGui::Text("Buffer Size:");
  906. static constexpr uint bufferSizes_i[] = {
  907. #ifndef DISTRHO_OS_WASM
  908. 128,
  909. #endif
  910. 256, 512, 1024, 2048, 4096, 8192,
  911. #ifdef DISTRHO_OS_WASM
  912. 16384,
  913. #endif
  914. };
  915. static constexpr const char* bufferSizes_s[] = {
  916. #ifndef DISTRHO_OS_WASM
  917. "128",
  918. #endif
  919. "256", "512", "1024", "2048", "4096", "8192",
  920. #ifdef DISTRHO_OS_WASM
  921. "16384",
  922. #endif
  923. };
  924. uint buffersize = getBufferSize();
  925. int current = -1;
  926. for (uint i=0; i<ARRAY_SIZE(bufferSizes_i); ++i)
  927. {
  928. if (bufferSizes_i[i] == buffersize)
  929. {
  930. current = i;
  931. break;
  932. }
  933. }
  934. ImGui::SameLine();
  935. if (ImGui::Combo("##buffersize", &current, bufferSizes_s, ARRAY_SIZE(bufferSizes_s)))
  936. {
  937. const uint next = bufferSizes_i[current];
  938. d_stdout("requesting new buffer size: %u -> %u", buffersize, next);
  939. requestBufferSizeChange(next);
  940. }
  941. }
  942. }
  943. #endif
  944. }
  945. ImGui::End();
  946. }
  947. void setupMainWindowPos()
  948. {
  949. const float scaleFactor = getScaleFactor();
  950. float y = 0;
  951. float height = getHeight();
  952. if (fDrawingState == kDrawingPluginGenericUI)
  953. {
  954. y = kButtonHeight * scaleFactor + ImGui::GetStyle().WindowPadding.y * 2 - scaleFactor;
  955. height -= y;
  956. }
  957. ImGui::SetNextWindowPos(ImVec2(0, y));
  958. ImGui::SetNextWindowSize(ImVec2(getWidth(), height));
  959. }
  960. void drawGenericUI()
  961. {
  962. setupMainWindowPos();
  963. PluginGenericUI* const ui = fPluginGenericUI;
  964. DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,);
  965. const int pflags = ImGuiWindowFlags_NoSavedSettings
  966. | ImGuiWindowFlags_NoResize
  967. | ImGuiWindowFlags_NoCollapse
  968. | ImGuiWindowFlags_AlwaysAutoResize;
  969. if (ImGui::Begin(ui->title, nullptr, pflags))
  970. {
  971. const CarlaHostHandle handle = fPlugin->fCarlaHostHandle;
  972. if (ui->presetCount != 0)
  973. {
  974. ImGui::Text("Preset:");
  975. ImGui::SameLine();
  976. if (ImGui::Combo("##presets", &ui->currentPreset, ui->presetStrings, ui->presetCount))
  977. {
  978. PluginGenericUI::Preset& preset(ui->presets[ui->currentPreset]);
  979. carla_set_program(handle, fPluginId, preset.index);
  980. }
  981. }
  982. for (uint32_t i=0; i < ui->parameterCount; ++i)
  983. {
  984. PluginGenericUI::Parameter& param(ui->parameters[i]);
  985. if (param.readonly)
  986. {
  987. ImGui::BeginDisabled();
  988. ImGui::SliderFloat(param.name, &ui->values[i], param.min, param.max, param.printformat,
  989. ImGuiSliderFlags_NoInput | (param.log ? ImGuiSliderFlags_Logarithmic : 0x0));
  990. ImGui::EndDisabled();
  991. continue;
  992. }
  993. if (param.boolean)
  994. {
  995. if (ImGui::Checkbox(param.name, &ui->parameters[i].bvalue))
  996. {
  997. if (ImGui::IsItemActivated())
  998. {
  999. carla_set_parameter_touch(handle, fPluginId, param.rindex, true);
  1000. // editParameter(0, true);
  1001. }
  1002. ui->values[i] = ui->parameters[i].bvalue ? ui->parameters[i].max : ui->parameters[i].min;
  1003. carla_set_parameter_value(handle, fPluginId, param.rindex, ui->values[i]);
  1004. // setParameterValue(0, ui->values[i]);
  1005. }
  1006. }
  1007. else
  1008. {
  1009. const bool ret = param.log
  1010. ? ImGui::SliderFloat(param.name, &ui->values[i], param.min, param.max, param.printformat, ImGuiSliderFlags_Logarithmic)
  1011. : ImGui::SliderFloat(param.name, &ui->values[i], param.min, param.max, param.printformat);
  1012. if (ret)
  1013. {
  1014. if (ImGui::IsItemActivated())
  1015. {
  1016. carla_set_parameter_touch(handle, fPluginId, param.rindex, true);
  1017. // editParameter(0, true);
  1018. }
  1019. carla_set_parameter_value(handle, fPluginId, param.rindex, ui->values[i]);
  1020. // setParameterValue(0, ui->values[i]);
  1021. }
  1022. }
  1023. if (ImGui::IsItemDeactivated())
  1024. {
  1025. carla_set_parameter_touch(handle, fPluginId, param.rindex, false);
  1026. // editParameter(0, false);
  1027. }
  1028. }
  1029. }
  1030. ImGui::End();
  1031. }
  1032. void drawLoading()
  1033. {
  1034. setupMainWindowPos();
  1035. constexpr const int plflags = ImGuiWindowFlags_NoSavedSettings
  1036. | ImGuiWindowFlags_NoDecoration;
  1037. if (ImGui::Begin("Plugin List", nullptr, plflags))
  1038. ImGui::TextUnformatted("Loading...", nullptr);
  1039. ImGui::End();
  1040. }
  1041. void drawPluginList()
  1042. {
  1043. static const char* pluginTypes[] = {
  1044. getPluginTypeAsString(PLUGIN_INTERNAL),
  1045. getPluginTypeAsString(PLUGIN_LADSPA),
  1046. getPluginTypeAsString(PLUGIN_DSSI),
  1047. getPluginTypeAsString(PLUGIN_LV2),
  1048. getPluginTypeAsString(PLUGIN_VST2),
  1049. getPluginTypeAsString(PLUGIN_VST3),
  1050. getPluginTypeAsString(PLUGIN_CLAP),
  1051. getPluginTypeAsString(PLUGIN_JSFX),
  1052. "Load from file..."
  1053. };
  1054. setupMainWindowPos();
  1055. constexpr const int plflags = ImGuiWindowFlags_NoSavedSettings
  1056. | ImGuiWindowFlags_NoDecoration;
  1057. if (ImGui::Begin("Plugin List", nullptr, plflags))
  1058. {
  1059. constexpr const int errflags = ImGuiWindowFlags_NoSavedSettings
  1060. | ImGuiWindowFlags_NoResize
  1061. | ImGuiWindowFlags_AlwaysAutoResize
  1062. | ImGuiWindowFlags_NoCollapse
  1063. | ImGuiWindowFlags_NoScrollbar
  1064. | ImGuiWindowFlags_NoScrollWithMouse;
  1065. if (ImGui::BeginPopupModal("Plugin Error", nullptr, errflags))
  1066. {
  1067. ImGui::TextWrapped("Failed to load plugin, error was:\n%s", fPopupError.buffer());
  1068. ImGui::Separator();
  1069. if (ImGui::Button("Ok"))
  1070. ImGui::CloseCurrentPopup();
  1071. ImGui::SameLine();
  1072. ImGui::Dummy(ImVec2(500 * getScaleFactor(), 1));
  1073. ImGui::EndPopup();
  1074. }
  1075. else if (fPluginSearchFirstShow)
  1076. {
  1077. fPluginSearchFirstShow = false;
  1078. ImGui::SetKeyboardFocusHere();
  1079. }
  1080. if (ImGui::InputText("##pluginsearch", fPluginSearchString, sizeof(fPluginSearchString)-1,
  1081. ImGuiInputTextFlags_CharsNoBlank|ImGuiInputTextFlags_AutoSelectAll))
  1082. fPluginSearchActive = true;
  1083. if (ImGui::IsKeyDown(ImGuiKey_Escape))
  1084. fPluginSearchActive = false;
  1085. ImGui::SameLine();
  1086. ImGui::PushItemWidth(-1.0f);
  1087. int current;
  1088. switch (fPluginType)
  1089. {
  1090. case PLUGIN_JSFX: current = 7; break;
  1091. case PLUGIN_CLAP: current = 6; break;
  1092. case PLUGIN_VST3: current = 5; break;
  1093. case PLUGIN_VST2: current = 4; break;
  1094. case PLUGIN_LV2: current = 3; break;
  1095. case PLUGIN_DSSI: current = 2; break;
  1096. case PLUGIN_LADSPA: current = 1; break;
  1097. default: current = 0; break;
  1098. }
  1099. if (ImGui::Combo("##plugintypes", &current, pluginTypes, ARRAY_SIZE(pluginTypes)))
  1100. {
  1101. fIdleState = kIdleChangePluginType;
  1102. switch (current)
  1103. {
  1104. case 0: fNextPluginType = PLUGIN_INTERNAL; break;
  1105. case 1: fNextPluginType = PLUGIN_LADSPA; break;
  1106. case 2: fNextPluginType = PLUGIN_DSSI; break;
  1107. case 3: fNextPluginType = PLUGIN_LV2; break;
  1108. case 4: fNextPluginType = PLUGIN_VST2; break;
  1109. case 5: fNextPluginType = PLUGIN_VST3; break;
  1110. case 6: fNextPluginType = PLUGIN_CLAP; break;
  1111. case 7: fNextPluginType = PLUGIN_JSFX; break;
  1112. case 8: fNextPluginType = PLUGIN_TYPE_COUNT; break;
  1113. }
  1114. }
  1115. ImGui::BeginDisabled(!fPluginScanningFinished || fPluginSelected < 0);
  1116. if (ImGui::Button("Load Plugin"))
  1117. fIdleState = kIdleLoadSelectedPlugin;
  1118. // xx cardinal
  1119. if (fPluginType != PLUGIN_INTERNAL /*&& module->canUseBridges*/)
  1120. {
  1121. ImGui::SameLine();
  1122. ImGui::Checkbox("Run in bridge mode", &fPluginWillRunInBridgeMode);
  1123. }
  1124. ImGui::EndDisabled();
  1125. if (fPluginRunning)
  1126. {
  1127. ImGui::SameLine();
  1128. if (ImGui::Button("Cancel"))
  1129. fIdleState = kIdleShowCustomUI;
  1130. }
  1131. if (ImGui::BeginChild("pluginlistwindow"))
  1132. {
  1133. if (ImGui::BeginTable("pluginlist", 2, ImGuiTableFlags_NoSavedSettings))
  1134. {
  1135. const char* const search = fPluginSearchActive && fPluginSearchString[0] != '\0' ? fPluginSearchString : nullptr;
  1136. switch (fPluginType)
  1137. {
  1138. case PLUGIN_INTERNAL:
  1139. case PLUGIN_AU:
  1140. ImGui::TableSetupColumn("Name");
  1141. ImGui::TableSetupColumn("Label");
  1142. ImGui::TableHeadersRow();
  1143. break;
  1144. case PLUGIN_LV2:
  1145. ImGui::TableSetupColumn("Name");
  1146. ImGui::TableSetupColumn("URI");
  1147. ImGui::TableHeadersRow();
  1148. break;
  1149. default:
  1150. ImGui::TableSetupColumn("Name");
  1151. ImGui::TableSetupColumn("Filename");
  1152. ImGui::TableHeadersRow();
  1153. break;
  1154. }
  1155. const MutexLocker cml(fPluginsMutex);
  1156. for (uint i=0; i<fPlugins.size(); ++i)
  1157. {
  1158. const PluginInfoCache& info(fPlugins[i]);
  1159. if (search != nullptr && ildaeil::strcasestr(info.name.c_str(), search) == nullptr)
  1160. continue;
  1161. bool selected = fPluginSelected >= 0 && static_cast<uint>(fPluginSelected) == i;
  1162. switch (fPluginType)
  1163. {
  1164. case PLUGIN_INTERNAL:
  1165. case PLUGIN_AU:
  1166. ImGui::TableNextRow();
  1167. ImGui::TableSetColumnIndex(0);
  1168. ImGui::Selectable(info.name.c_str(), &selected);
  1169. ImGui::TableSetColumnIndex(1);
  1170. ImGui::Selectable(info.label.c_str(), &selected);
  1171. break;
  1172. case PLUGIN_LV2:
  1173. ImGui::TableNextRow();
  1174. ImGui::TableSetColumnIndex(0);
  1175. ImGui::Selectable(info.name.c_str(), &selected);
  1176. ImGui::TableSetColumnIndex(1);
  1177. ImGui::Selectable(info.label.c_str(), &selected);
  1178. break;
  1179. default:
  1180. ImGui::TableNextRow();
  1181. ImGui::TableSetColumnIndex(0);
  1182. ImGui::Selectable(info.name.c_str(), &selected);
  1183. ImGui::TableSetColumnIndex(1);
  1184. ImGui::Selectable(info.filename.c_str(), &selected);
  1185. break;
  1186. }
  1187. if (selected)
  1188. fPluginSelected = i;
  1189. }
  1190. ImGui::EndTable();
  1191. }
  1192. ImGui::EndChild();
  1193. }
  1194. }
  1195. ImGui::End();
  1196. }
  1197. protected:
  1198. /* --------------------------------------------------------------------------------------------------------
  1199. * DSP/Plugin Callbacks */
  1200. void parameterChanged(uint32_t, float) override
  1201. {
  1202. }
  1203. void stateChanged(const char* /* const key */, const char*) override
  1204. {
  1205. /*
  1206. if (std::strcmp(key, "project") == 0)
  1207. hidePluginUI(fPlugin->fCarlaHostHandle);
  1208. */
  1209. }
  1210. // -------------------------------------------------------------------------------------------------------
  1211. private:
  1212. /**
  1213. Set our UI class as non-copyable and add a leak detector just in case.
  1214. */
  1215. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(IldaeilUI)
  1216. };
  1217. // --------------------------------------------------------------------------------------------------------------------
  1218. void ildaeilProjectLoadedFromDSP(void* const ui)
  1219. {
  1220. DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,);
  1221. static_cast<IldaeilUI*>(ui)->projectLoadedFromDSP();
  1222. }
  1223. void ildaeilParameterChangeForUI(void* const ui, const uint32_t index, const float value)
  1224. {
  1225. DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,);
  1226. static_cast<IldaeilUI*>(ui)->changeParameterFromDSP(index, value);
  1227. }
  1228. void ildaeilCloseUI(void* ui)
  1229. {
  1230. DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,);
  1231. static_cast<IldaeilUI*>(ui)->closeUI();
  1232. }
  1233. const char* ildaeilOpenFileForUI(void* const ui, const bool isDir, const char* const title, const char* const filter)
  1234. {
  1235. DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr, nullptr);
  1236. return static_cast<IldaeilUI*>(ui)->openFileFromDSP(isDir, title, filter);
  1237. }
  1238. /* --------------------------------------------------------------------------------------------------------------------
  1239. * UI entry point, called by DPF to create a new UI instance. */
  1240. UI* createUI()
  1241. {
  1242. return new IldaeilUI();
  1243. }
  1244. // --------------------------------------------------------------------------------------------------------------------
  1245. END_NAMESPACE_DISTRHO