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.

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