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.

1458 lines
46KB

  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. }
  912. #endif
  913. }
  914. ImGui::End();
  915. }
  916. void setupMainWindowPos()
  917. {
  918. const float scaleFactor = getScaleFactor();
  919. float y = 0;
  920. float height = getHeight();
  921. if (fDrawingState == kDrawingPluginGenericUI)
  922. {
  923. y = kButtonHeight * scaleFactor + ImGui::GetStyle().WindowPadding.y * 2 - scaleFactor;
  924. height -= y;
  925. }
  926. ImGui::SetNextWindowPos(ImVec2(0, y));
  927. ImGui::SetNextWindowSize(ImVec2(getWidth(), height));
  928. }
  929. void drawGenericUI()
  930. {
  931. setupMainWindowPos();
  932. PluginGenericUI* const ui = fPluginGenericUI;
  933. DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,);
  934. const int pflags = ImGuiWindowFlags_NoSavedSettings
  935. | ImGuiWindowFlags_NoResize
  936. | ImGuiWindowFlags_NoCollapse
  937. | ImGuiWindowFlags_AlwaysAutoResize;
  938. if (ImGui::Begin(ui->title, nullptr, pflags))
  939. {
  940. const CarlaHostHandle handle = fPlugin->fCarlaHostHandle;
  941. if (ui->presetCount != 0)
  942. {
  943. ImGui::Text("Preset:");
  944. ImGui::SameLine();
  945. if (ImGui::Combo("##presets", &ui->currentPreset, ui->presetStrings, ui->presetCount))
  946. {
  947. PluginGenericUI::Preset& preset(ui->presets[ui->currentPreset]);
  948. carla_set_program(handle, fPluginId, preset.index);
  949. }
  950. }
  951. for (uint32_t i=0; i < ui->parameterCount; ++i)
  952. {
  953. PluginGenericUI::Parameter& param(ui->parameters[i]);
  954. if (param.readonly)
  955. {
  956. ImGui::BeginDisabled();
  957. ImGui::SliderFloat(param.name, &ui->values[i], param.min, param.max, param.printformat,
  958. ImGuiSliderFlags_NoInput | (param.log ? ImGuiSliderFlags_Logarithmic : 0x0));
  959. ImGui::EndDisabled();
  960. continue;
  961. }
  962. if (param.boolean)
  963. {
  964. if (ImGui::Checkbox(param.name, &ui->parameters[i].bvalue))
  965. {
  966. if (ImGui::IsItemActivated())
  967. {
  968. carla_set_parameter_touch(handle, fPluginId, param.rindex, true);
  969. // editParameter(0, true);
  970. }
  971. ui->values[i] = ui->parameters[i].bvalue ? ui->parameters[i].max : ui->parameters[i].min;
  972. carla_set_parameter_value(handle, fPluginId, param.rindex, ui->values[i]);
  973. // setParameterValue(0, ui->values[i]);
  974. }
  975. }
  976. else
  977. {
  978. const bool ret = param.log
  979. ? ImGui::SliderFloat(param.name, &ui->values[i], param.min, param.max, param.printformat, ImGuiSliderFlags_Logarithmic)
  980. : ImGui::SliderFloat(param.name, &ui->values[i], param.min, param.max, param.printformat);
  981. if (ret)
  982. {
  983. if (ImGui::IsItemActivated())
  984. {
  985. carla_set_parameter_touch(handle, fPluginId, param.rindex, true);
  986. // editParameter(0, true);
  987. }
  988. carla_set_parameter_value(handle, fPluginId, param.rindex, ui->values[i]);
  989. // setParameterValue(0, ui->values[i]);
  990. }
  991. }
  992. if (ImGui::IsItemDeactivated())
  993. {
  994. carla_set_parameter_touch(handle, fPluginId, param.rindex, false);
  995. // editParameter(0, false);
  996. }
  997. }
  998. }
  999. ImGui::End();
  1000. }
  1001. void drawLoading()
  1002. {
  1003. setupMainWindowPos();
  1004. constexpr const int plflags = ImGuiWindowFlags_NoSavedSettings
  1005. | ImGuiWindowFlags_NoDecoration;
  1006. if (ImGui::Begin("Plugin List", nullptr, plflags))
  1007. ImGui::TextUnformatted("Loading...", nullptr);
  1008. ImGui::End();
  1009. }
  1010. void drawPluginList()
  1011. {
  1012. static const char* pluginTypes[] = {
  1013. getPluginTypeAsString(PLUGIN_INTERNAL),
  1014. getPluginTypeAsString(PLUGIN_LV2),
  1015. getPluginTypeAsString(PLUGIN_JSFX),
  1016. "Load from file..."
  1017. };
  1018. setupMainWindowPos();
  1019. constexpr const int plflags = ImGuiWindowFlags_NoSavedSettings
  1020. | ImGuiWindowFlags_NoDecoration;
  1021. if (ImGui::Begin("Plugin List", nullptr, plflags))
  1022. {
  1023. constexpr const int errflags = ImGuiWindowFlags_NoSavedSettings
  1024. | ImGuiWindowFlags_NoResize
  1025. | ImGuiWindowFlags_AlwaysAutoResize
  1026. | ImGuiWindowFlags_NoCollapse
  1027. | ImGuiWindowFlags_NoScrollbar
  1028. | ImGuiWindowFlags_NoScrollWithMouse;
  1029. if (ImGui::BeginPopupModal("Plugin Error", nullptr, errflags))
  1030. {
  1031. ImGui::TextWrapped("Failed to load plugin, error was:\n%s", fPopupError.buffer());
  1032. ImGui::Separator();
  1033. if (ImGui::Button("Ok"))
  1034. ImGui::CloseCurrentPopup();
  1035. ImGui::SameLine();
  1036. ImGui::Dummy(ImVec2(500 * getScaleFactor(), 1));
  1037. ImGui::EndPopup();
  1038. }
  1039. else if (fPluginSearchFirstShow)
  1040. {
  1041. fPluginSearchFirstShow = false;
  1042. ImGui::SetKeyboardFocusHere();
  1043. }
  1044. if (ImGui::InputText("##pluginsearch", fPluginSearchString, sizeof(fPluginSearchString)-1,
  1045. ImGuiInputTextFlags_CharsNoBlank|ImGuiInputTextFlags_AutoSelectAll))
  1046. fPluginSearchActive = true;
  1047. if (ImGui::IsKeyDown(ImGuiKey_Escape))
  1048. fPluginSearchActive = false;
  1049. ImGui::SameLine();
  1050. ImGui::PushItemWidth(-1.0f);
  1051. int current;
  1052. switch (fPluginType)
  1053. {
  1054. case PLUGIN_JSFX:
  1055. current = 2;
  1056. break;
  1057. case PLUGIN_LV2:
  1058. current = 1;
  1059. break;
  1060. default:
  1061. current = 0;
  1062. break;
  1063. }
  1064. if (ImGui::Combo("##plugintypes", &current, pluginTypes, ARRAY_SIZE(pluginTypes)))
  1065. {
  1066. fIdleState = kIdleChangePluginType;
  1067. switch (current)
  1068. {
  1069. case 0:
  1070. fNextPluginType = PLUGIN_INTERNAL;
  1071. break;
  1072. case 1:
  1073. fNextPluginType = PLUGIN_LV2;
  1074. break;
  1075. case 2:
  1076. fNextPluginType = PLUGIN_JSFX;
  1077. break;
  1078. case 3:
  1079. fNextPluginType = PLUGIN_TYPE_COUNT;
  1080. break;
  1081. }
  1082. }
  1083. ImGui::BeginDisabled(!fPluginScanningFinished || fPluginSelected < 0);
  1084. if (ImGui::Button("Load Plugin"))
  1085. fIdleState = kIdleLoadSelectedPlugin;
  1086. // xx cardinal
  1087. if (fPluginType != PLUGIN_INTERNAL /*&& module->canUseBridges*/)
  1088. {
  1089. ImGui::SameLine();
  1090. ImGui::Checkbox("Run in bridge mode", &fPluginWillRunInBridgeMode);
  1091. }
  1092. ImGui::EndDisabled();
  1093. if (fPluginRunning)
  1094. {
  1095. ImGui::SameLine();
  1096. if (ImGui::Button("Cancel"))
  1097. fIdleState = kIdleShowCustomUI;
  1098. }
  1099. if (ImGui::BeginChild("pluginlistwindow"))
  1100. {
  1101. if (ImGui::BeginTable("pluginlist", 2, ImGuiTableFlags_NoSavedSettings))
  1102. {
  1103. const char* const search = fPluginSearchActive && fPluginSearchString[0] != '\0' ? fPluginSearchString : nullptr;
  1104. switch (fPluginType)
  1105. {
  1106. case PLUGIN_INTERNAL:
  1107. case PLUGIN_AU:
  1108. case PLUGIN_SFZ:
  1109. case PLUGIN_JSFX:
  1110. ImGui::TableSetupColumn("Name");
  1111. ImGui::TableSetupColumn("Label");
  1112. ImGui::TableHeadersRow();
  1113. break;
  1114. case PLUGIN_LV2:
  1115. ImGui::TableSetupColumn("Name");
  1116. ImGui::TableSetupColumn("URI");
  1117. ImGui::TableHeadersRow();
  1118. break;
  1119. default:
  1120. break;
  1121. }
  1122. for (uint i=0; i<fPluginCount; ++i)
  1123. {
  1124. const PluginInfoCache& info(fPlugins[i]);
  1125. if (search != nullptr && ildaeil::strcasestr(info.name, search) == nullptr)
  1126. continue;
  1127. bool selected = fPluginSelected >= 0 && static_cast<uint>(fPluginSelected) == i;
  1128. switch (fPluginType)
  1129. {
  1130. case PLUGIN_INTERNAL:
  1131. case PLUGIN_AU:
  1132. case PLUGIN_JSFX:
  1133. case PLUGIN_SFZ:
  1134. ImGui::TableNextRow();
  1135. ImGui::TableSetColumnIndex(0);
  1136. ImGui::Selectable(info.name, &selected);
  1137. ImGui::TableSetColumnIndex(1);
  1138. ImGui::Selectable(info.label, &selected);
  1139. break;
  1140. case PLUGIN_LV2: {
  1141. const char* const slash = std::strchr(info.label, DISTRHO_OS_SEP);
  1142. DISTRHO_SAFE_ASSERT_CONTINUE(slash != nullptr);
  1143. ImGui::TableNextRow();
  1144. ImGui::TableSetColumnIndex(0);
  1145. ImGui::Selectable(info.name, &selected);
  1146. ImGui::TableSetColumnIndex(1);
  1147. ImGui::Selectable(slash+1, &selected);
  1148. break;
  1149. }
  1150. default:
  1151. break;
  1152. }
  1153. if (selected)
  1154. fPluginSelected = i;
  1155. }
  1156. ImGui::EndTable();
  1157. }
  1158. ImGui::EndChild();
  1159. }
  1160. }
  1161. ImGui::End();
  1162. }
  1163. protected:
  1164. /* --------------------------------------------------------------------------------------------------------
  1165. * DSP/Plugin Callbacks */
  1166. void parameterChanged(uint32_t, float) override
  1167. {
  1168. }
  1169. void stateChanged(const char* /* const key */, const char*) override
  1170. {
  1171. /*
  1172. if (std::strcmp(key, "project") == 0)
  1173. hidePluginUI(fPlugin->fCarlaHostHandle);
  1174. */
  1175. }
  1176. // -------------------------------------------------------------------------------------------------------
  1177. private:
  1178. /**
  1179. Set our UI class as non-copyable and add a leak detector just in case.
  1180. */
  1181. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(IldaeilUI)
  1182. };
  1183. // --------------------------------------------------------------------------------------------------------------------
  1184. void ildaeilProjectLoadedFromDSP(void* const ui)
  1185. {
  1186. DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,);
  1187. static_cast<IldaeilUI*>(ui)->projectLoadedFromDSP();
  1188. }
  1189. void ildaeilParameterChangeForUI(void* const ui, const uint32_t index, const float value)
  1190. {
  1191. DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,);
  1192. static_cast<IldaeilUI*>(ui)->changeParameterFromDSP(index, value);
  1193. }
  1194. void ildaeilCloseUI(void* ui)
  1195. {
  1196. DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,);
  1197. static_cast<IldaeilUI*>(ui)->closeUI();
  1198. }
  1199. const char* ildaeilOpenFileForUI(void* const ui, const bool isDir, const char* const title, const char* const filter)
  1200. {
  1201. DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr, nullptr);
  1202. return static_cast<IldaeilUI*>(ui)->openFileFromDSP(isDir, title, filter);
  1203. }
  1204. /* --------------------------------------------------------------------------------------------------------------------
  1205. * UI entry point, called by DPF to create a new UI instance. */
  1206. UI* createUI()
  1207. {
  1208. return new IldaeilUI();
  1209. }
  1210. // --------------------------------------------------------------------------------------------------------------------
  1211. END_NAMESPACE_DISTRHO