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.

853 lines
27KB

  1. /*
  2. * DISTRHO Ildaeil Plugin
  3. * Copyright (C) 2021 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 "CarlaNativePlugin.h"
  18. #include "DistrhoUI.hpp"
  19. #include "DistrhoPlugin.hpp"
  20. #include "PluginHostWindow.hpp"
  21. #include "extra/Thread.hpp"
  22. // IDE helper
  23. #include "DearImGui.hpp"
  24. #include <vector>
  25. START_NAMESPACE_DISTRHO
  26. // --------------------------------------------------------------------------------------------------------------------
  27. class IldaeilPlugin : public Plugin
  28. {
  29. public:
  30. const NativePluginDescriptor* fCarlaPluginDescriptor;
  31. NativePluginHandle fCarlaPluginHandle;
  32. NativeHostDescriptor fCarlaHostDescriptor;
  33. CarlaHostHandle fCarlaHostHandle;
  34. void* fUI;
  35. // ...
  36. };
  37. // --------------------------------------------------------------------------------------------------------------------
  38. void ildaeilParameterChangeForUI(void* ui, uint32_t index, float value);
  39. const char* ildaeilOpenFileForUI(void* ui, bool isDir, const char* title, const char* filter);
  40. // --------------------------------------------------------------------------------------------------------------------
  41. using namespace CarlaBackend;
  42. // shared resource pointer
  43. // carla_juce_init();
  44. class IldaeilUI : public UI,
  45. public Thread,
  46. public PluginHostWindow::Callbacks
  47. {
  48. static constexpr const uint kInitialWidth = 1220;
  49. static constexpr const uint kInitialHeight = 640;
  50. static constexpr const uint kGenericWidth = 360;
  51. static constexpr const uint kGenericHeight = 400;
  52. static constexpr const uint kButtonHeight = 20;
  53. enum {
  54. kDrawingInit,
  55. kDrawingError,
  56. kDrawingLoading,
  57. kDrawingPluginList,
  58. kDrawingPluginEmbedUI,
  59. kDrawingPluginGenericUI,
  60. kDrawingPluginPendingFromInit
  61. } fDrawingState;
  62. struct PluginInfoCache {
  63. char* name;
  64. char* label;
  65. PluginInfoCache()
  66. : name(nullptr),
  67. label(nullptr) {}
  68. ~PluginInfoCache()
  69. {
  70. std::free(name);
  71. std::free(label);
  72. }
  73. };
  74. struct PluginGenericUI {
  75. char* title;
  76. uint parameterCount;
  77. struct Parameter {
  78. char* name;
  79. char* format;
  80. uint32_t rindex;
  81. bool boolean, bvalue;
  82. float min, max;
  83. Parameter()
  84. : name(nullptr),
  85. format(nullptr),
  86. rindex(0),
  87. boolean(false),
  88. bvalue(false),
  89. min(0.0f),
  90. max(1.0f) {}
  91. ~Parameter()
  92. {
  93. std::free(name);
  94. std::free(format);
  95. }
  96. }* parameters;
  97. float* values;
  98. PluginGenericUI()
  99. : title(nullptr),
  100. parameterCount(0),
  101. parameters(nullptr),
  102. values(nullptr) {}
  103. ~PluginGenericUI()
  104. {
  105. std::free(title);
  106. delete[] parameters;
  107. delete[] values;
  108. }
  109. };
  110. IldaeilPlugin* const fPlugin;
  111. PluginHostWindow fPluginHostWindow;
  112. PluginType fPluginType;
  113. uint fPluginCount;
  114. uint fPluginSelected;
  115. bool fPluginScanningFinished;
  116. bool fPluginHasCustomUI;
  117. bool fPluginHasEmbedUI;
  118. bool fPluginWillRunInBridgeMode;
  119. PluginInfoCache* fPlugins;
  120. ScopedPointer<PluginGenericUI> fPluginGenericUI;
  121. bool fPluginSearchActive;
  122. char fPluginSearchString[0xff];
  123. public:
  124. IldaeilUI()
  125. : UI(kInitialWidth, kInitialHeight),
  126. Thread("IldaeilScanner"),
  127. fDrawingState(kDrawingInit),
  128. fPlugin((IldaeilPlugin*)getPluginInstancePointer()),
  129. fPluginHostWindow(getWindow(), this),
  130. fPluginType(PLUGIN_LV2),
  131. fPluginCount(0),
  132. fPluginSelected(0),
  133. fPluginScanningFinished(false),
  134. fPluginHasCustomUI(false),
  135. fPluginHasEmbedUI(false),
  136. fPluginWillRunInBridgeMode(false),
  137. fPlugins(nullptr),
  138. fPluginSearchActive(false)
  139. {
  140. if (fPlugin == nullptr || fPlugin->fCarlaHostHandle == nullptr)
  141. {
  142. fDrawingState = kDrawingError;
  143. return;
  144. }
  145. std::strcpy(fPluginSearchString, "Search...");
  146. const double padding = ImGui::GetStyle().WindowPadding.y * 2;
  147. const double scaleFactor = getScaleFactor();
  148. if (d_isNotEqual(scaleFactor, 1.0))
  149. {
  150. setSize(kInitialWidth * scaleFactor, kInitialHeight * scaleFactor);
  151. fPluginHostWindow.setPositionAndSize(0, kButtonHeight * scaleFactor + padding,
  152. kInitialWidth * scaleFactor,
  153. (kInitialHeight - kButtonHeight) * scaleFactor - padding);
  154. }
  155. else
  156. {
  157. fPluginHostWindow.setPositionAndSize(0, kButtonHeight + padding,
  158. kInitialWidth, kInitialHeight - kButtonHeight - padding);
  159. }
  160. const CarlaHostHandle handle = fPlugin->fCarlaHostHandle;
  161. char winIdStr[24];
  162. std::snprintf(winIdStr, sizeof(winIdStr), "%lx", (ulong)getWindow().getNativeWindowHandle());
  163. carla_set_engine_option(handle, ENGINE_OPTION_FRONTEND_WIN_ID, 0, winIdStr);
  164. carla_set_engine_option(handle, ENGINE_OPTION_FRONTEND_UI_SCALE, getScaleFactor()*1000, nullptr);
  165. if (carla_get_current_plugin_count(handle) != 0)
  166. {
  167. const uint hints = carla_get_plugin_info(handle, 0)->hints;
  168. fDrawingState = kDrawingPluginPendingFromInit;
  169. fPluginHasCustomUI = hints & PLUGIN_HAS_CUSTOM_UI;
  170. fPluginHasEmbedUI = hints & PLUGIN_HAS_CUSTOM_EMBED_UI;
  171. }
  172. fPlugin->fUI = this;
  173. }
  174. ~IldaeilUI() override
  175. {
  176. if (fPlugin != nullptr && fPlugin->fCarlaHostHandle != nullptr)
  177. {
  178. fPlugin->fUI = nullptr;
  179. carla_set_engine_option(fPlugin->fCarlaHostHandle, ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0");
  180. }
  181. if (isThreadRunning())
  182. stopThread(-1);
  183. hidePluginUI();
  184. fPluginGenericUI = nullptr;
  185. delete[] fPlugins;
  186. }
  187. void changeParameterFromDSP(const uint32_t index, const float value)
  188. {
  189. if (PluginGenericUI* const ui = fPluginGenericUI)
  190. {
  191. for (uint32_t i=0; i < ui->parameterCount; ++i)
  192. {
  193. if (ui->parameters[i].rindex != index)
  194. continue;
  195. ui->values[i] = value;
  196. if (ui->parameters[i].boolean)
  197. ui->parameters[i].bvalue = value > ui->parameters[i].min;
  198. break;
  199. }
  200. }
  201. }
  202. const char* openFileFromDSP(const bool /*isDir*/, const char* const title, const char* const /*filter*/)
  203. {
  204. Window::FileBrowserOptions opts;
  205. opts.title = title;
  206. getWindow().openFileBrowser(opts);
  207. return nullptr;
  208. }
  209. void showPluginUI(const CarlaHostHandle handle)
  210. {
  211. const CarlaPluginInfo* const info = carla_get_plugin_info(handle, 0);
  212. if (info->hints & PLUGIN_HAS_CUSTOM_EMBED_UI)
  213. {
  214. fDrawingState = kDrawingPluginEmbedUI;
  215. fPluginHasCustomUI = true;
  216. fPluginHasEmbedUI = true;
  217. carla_embed_custom_ui(handle, 0, fPluginHostWindow.attachAndGetWindowHandle());
  218. }
  219. else
  220. {
  221. fDrawingState = kDrawingPluginGenericUI;
  222. fPluginHasCustomUI = info->hints & PLUGIN_HAS_CUSTOM_UI;
  223. fPluginHasEmbedUI = false;
  224. if (fPluginGenericUI == nullptr)
  225. createPluginGenericUI(handle, info);
  226. else
  227. updatePluginGenericUI(handle);
  228. ImGuiStyle& style(ImGui::GetStyle());
  229. const double scaleFactor = getScaleFactor();
  230. setSize(kGenericWidth * scaleFactor, (kGenericHeight + style.FramePadding.x) * scaleFactor);
  231. }
  232. repaint();
  233. }
  234. void hidePluginUI()
  235. {
  236. if (fPlugin == nullptr || fPlugin->fCarlaHostHandle == nullptr)
  237. return;
  238. if (fDrawingState == kDrawingPluginGenericUI || fDrawingState == kDrawingPluginEmbedUI)
  239. carla_show_custom_ui(fPlugin->fCarlaHostHandle, 0, false);
  240. fPluginHostWindow.hide();
  241. }
  242. void createPluginGenericUI(const CarlaHostHandle handle, const CarlaPluginInfo* const info)
  243. {
  244. PluginGenericUI* const ui = new PluginGenericUI;
  245. String title(info->name);
  246. title += " by ";
  247. title += info->maker;
  248. ui->title = title.getAndReleaseBuffer();
  249. const uint32_t pcount = ui->parameterCount = carla_get_parameter_count(handle, 0);
  250. // make count of valid parameters
  251. for (uint32_t i=0; i < pcount; ++i)
  252. {
  253. const ParameterData* const pdata = carla_get_parameter_data(handle, 0, i);
  254. if (pdata->type != PARAMETER_INPUT ||
  255. (pdata->hints & PARAMETER_IS_ENABLED) == 0x0 ||
  256. (pdata->hints & PARAMETER_IS_READ_ONLY) != 0x0)
  257. {
  258. --ui->parameterCount;
  259. continue;
  260. }
  261. }
  262. ui->parameters = new PluginGenericUI::Parameter[ui->parameterCount];
  263. ui->values = new float[ui->parameterCount];
  264. // now safely fill in details
  265. for (uint32_t i=0, j=0; i < pcount; ++i)
  266. {
  267. const ParameterData* const pdata = carla_get_parameter_data(handle, 0, i);
  268. if (pdata->type != PARAMETER_INPUT ||
  269. (pdata->hints & PARAMETER_IS_ENABLED) == 0x0 ||
  270. (pdata->hints & PARAMETER_IS_READ_ONLY) != 0x0)
  271. continue;
  272. const CarlaParameterInfo* const pinfo = carla_get_parameter_info(handle, 0, i);
  273. const ::ParameterRanges* const pranges = carla_get_parameter_ranges(handle, 0, i);
  274. String format;
  275. if (pdata->hints & PARAMETER_IS_INTEGER)
  276. format = "%.0f ";
  277. else
  278. format = "%.3f ";
  279. format += pinfo->unit;
  280. PluginGenericUI::Parameter& param(ui->parameters[j]);
  281. param.name = strdup(pinfo->name);
  282. param.format = format.getAndReleaseBuffer();
  283. param.rindex = i;
  284. param.boolean = pdata->hints & PARAMETER_IS_BOOLEAN;
  285. param.min = pranges->min;
  286. param.max = pranges->max;
  287. ui->values[j] = carla_get_current_parameter_value(handle, 0, i);
  288. if (param.boolean)
  289. param.bvalue = ui->values[j] > param.min;
  290. else
  291. param.bvalue = false;
  292. ++j;
  293. }
  294. fPluginGenericUI = ui;
  295. }
  296. void updatePluginGenericUI(const CarlaHostHandle handle)
  297. {
  298. PluginGenericUI* const ui = fPluginGenericUI;
  299. DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,);
  300. for (uint32_t i=0; i < ui->parameterCount; ++i)
  301. {
  302. ui->values[i] = carla_get_current_parameter_value(handle, 0, ui->parameters[i].rindex);
  303. if (ui->parameters[i].boolean)
  304. ui->parameters[i].bvalue = ui->values[i] > ui->parameters[i].min;
  305. }
  306. }
  307. bool loadPlugin(const CarlaHostHandle handle, const char* const label)
  308. {
  309. if (carla_get_current_plugin_count(handle) != 0)
  310. {
  311. hidePluginUI();
  312. carla_replace_plugin(handle, 0);
  313. }
  314. carla_set_engine_option(handle, ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, fPluginWillRunInBridgeMode, nullptr);
  315. if (carla_add_plugin(handle, BINARY_NATIVE, fPluginType, nullptr, nullptr,
  316. label, 0, 0x0, PLUGIN_OPTIONS_NULL))
  317. {
  318. fPluginGenericUI = nullptr;
  319. showPluginUI(handle);
  320. return true;
  321. }
  322. return false;
  323. }
  324. protected:
  325. void pluginWindowResized(uint width, uint height) override
  326. {
  327. setSize(width, height + kButtonHeight * getScaleFactor() + ImGui::GetStyle().WindowPadding.y * 2);
  328. }
  329. void uiIdle() override
  330. {
  331. switch (fDrawingState)
  332. {
  333. case kDrawingInit:
  334. fDrawingState = kDrawingLoading;
  335. startThread();
  336. repaint();
  337. break;
  338. case kDrawingPluginPendingFromInit:
  339. showPluginUI(fPlugin->fCarlaHostHandle);
  340. startThread();
  341. break;
  342. case kDrawingPluginEmbedUI:
  343. fPlugin->fCarlaPluginDescriptor->ui_idle(fPlugin->fCarlaPluginHandle);
  344. fPluginHostWindow.idle();
  345. break;
  346. case kDrawingPluginGenericUI:
  347. fPlugin->fCarlaPluginDescriptor->ui_idle(fPlugin->fCarlaPluginHandle);
  348. break;
  349. default:
  350. break;
  351. }
  352. }
  353. void uiFileBrowserSelected(const char* const filename) override
  354. {
  355. if (fPlugin != nullptr && fPlugin->fCarlaHostHandle != nullptr && filename != nullptr)
  356. carla_set_custom_data(fPlugin->fCarlaHostHandle, 0, CUSTOM_DATA_TYPE_STRING, "file", filename);
  357. }
  358. void run() override
  359. {
  360. if (const uint count = carla_get_cached_plugin_count(fPluginType, nullptr))
  361. {
  362. fPluginCount = 0;
  363. fPlugins = new PluginInfoCache[count];
  364. if (fDrawingState == kDrawingLoading)
  365. fDrawingState = kDrawingPluginList;
  366. for (uint i=0, j; i < count && ! shouldThreadExit(); ++i)
  367. {
  368. const CarlaCachedPluginInfo* const info = carla_get_cached_plugin_info(fPluginType, i);
  369. DISTRHO_SAFE_ASSERT_CONTINUE(info != nullptr);
  370. if (! info->valid)
  371. continue;
  372. #if DISTRHO_PLUGIN_IS_SYNTH
  373. if (info->midiIns != 1 || info->audioOuts != 2)
  374. continue;
  375. if ((info->hints & PLUGIN_IS_SYNTH) == 0x0)
  376. continue;
  377. #elif DISTRHO_PLUGIN_WANT_MIDI_OUTPUT
  378. if (info->midiIns != 1 || info->midiOuts != 1)
  379. continue;
  380. if (info->audioIns != 0 || info->audioOuts != 0)
  381. continue;
  382. #else
  383. if (info->audioIns != 2 || info->audioOuts != 2)
  384. continue;
  385. #endif
  386. j = fPluginCount;
  387. fPlugins[j].name = strdup(info->name);
  388. fPlugins[j].label = strdup(info->label);
  389. ++fPluginCount;
  390. }
  391. }
  392. if (! shouldThreadExit())
  393. fPluginScanningFinished = true;
  394. }
  395. void onImGuiDisplay() override
  396. {
  397. switch (fDrawingState)
  398. {
  399. case kDrawingInit:
  400. case kDrawingLoading:
  401. case kDrawingPluginPendingFromInit:
  402. drawLoading();
  403. break;
  404. case kDrawingPluginList:
  405. drawPluginList();
  406. break;
  407. case kDrawingError:
  408. // TODO display error message
  409. break;
  410. case kDrawingPluginGenericUI:
  411. drawGenericUI();
  412. // fall-through
  413. case kDrawingPluginEmbedUI:
  414. drawTopBar();
  415. break;
  416. }
  417. }
  418. void drawTopBar()
  419. {
  420. const float padding = ImGui::GetStyle().WindowPadding.y * 2;
  421. ImGui::SetNextWindowPos(ImVec2(0, 0));
  422. ImGui::SetNextWindowSize(ImVec2(getWidth(), kButtonHeight * getScaleFactor() + padding));
  423. const int flags = ImGuiWindowFlags_NoSavedSettings
  424. | ImGuiWindowFlags_NoTitleBar
  425. | ImGuiWindowFlags_NoResize
  426. | ImGuiWindowFlags_NoCollapse
  427. | ImGuiWindowFlags_NoScrollbar
  428. | ImGuiWindowFlags_NoScrollWithMouse
  429. | ImGuiWindowFlags_NoCollapse;
  430. if (ImGui::Begin("Current Plugin", nullptr, flags))
  431. {
  432. const CarlaHostHandle handle = fPlugin->fCarlaHostHandle;
  433. if (ImGui::Button("Pick Another..."))
  434. {
  435. hidePluginUI();
  436. fDrawingState = kDrawingPluginList;
  437. const double scaleFactor = getScaleFactor();
  438. setSize(kInitialWidth * scaleFactor, kInitialHeight * scaleFactor);
  439. }
  440. ImGui::SameLine();
  441. if (ImGui::Button("Reset"))
  442. {
  443. loadPlugin(handle, carla_get_plugin_info(handle, 0)->label);
  444. }
  445. if (fDrawingState == kDrawingPluginGenericUI && fPluginHasCustomUI)
  446. {
  447. ImGui::SameLine();
  448. if (ImGui::Button("Show Custom GUI"))
  449. {
  450. if (fPluginHasEmbedUI)
  451. {
  452. fDrawingState = kDrawingPluginEmbedUI;
  453. carla_embed_custom_ui(handle, 0, fPluginHostWindow.attachAndGetWindowHandle());
  454. }
  455. else
  456. {
  457. carla_show_custom_ui(handle, 0, true);
  458. }
  459. ImGui::End();
  460. return;
  461. }
  462. }
  463. if (fDrawingState == kDrawingPluginEmbedUI)
  464. {
  465. ImGui::SameLine();
  466. if (ImGui::Button("Show Generic GUI"))
  467. {
  468. hidePluginUI();
  469. fDrawingState = kDrawingPluginGenericUI;
  470. if (fPluginGenericUI == nullptr)
  471. createPluginGenericUI(handle, carla_get_plugin_info(handle, 0));
  472. else
  473. updatePluginGenericUI(handle);
  474. const double scaleFactor = getScaleFactor();
  475. const double padding = ImGui::GetStyle().WindowPadding.y * 2;
  476. setSize(std::max(getWidth(), static_cast<uint>(kGenericWidth * scaleFactor + 0.5)),
  477. (kGenericHeight + kButtonHeight) * scaleFactor + padding);
  478. }
  479. }
  480. }
  481. ImGui::End();
  482. }
  483. void setupMainWindowPos()
  484. {
  485. float y = 0;
  486. float height = getHeight();
  487. if (fDrawingState == kDrawingPluginGenericUI)
  488. {
  489. y = kButtonHeight * getScaleFactor() + ImGui::GetStyle().WindowPadding.y * 2 - 1;
  490. height -= y;
  491. }
  492. ImGui::SetNextWindowPos(ImVec2(0, y));
  493. ImGui::SetNextWindowSize(ImVec2(getWidth(), height));
  494. }
  495. void drawGenericUI()
  496. {
  497. setupMainWindowPos();
  498. PluginGenericUI* const ui = fPluginGenericUI;
  499. DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,);
  500. if (ImGui::Begin(ui->title, nullptr, ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoCollapse))
  501. {
  502. const CarlaHostHandle handle = fPlugin->fCarlaHostHandle;
  503. for (uint32_t i=0; i < ui->parameterCount; ++i)
  504. {
  505. PluginGenericUI::Parameter& param(ui->parameters[i]);
  506. if (param.boolean)
  507. {
  508. if (ImGui::Checkbox(param.name, &ui->parameters[i].bvalue))
  509. {
  510. if (ImGui::IsItemActivated())
  511. {
  512. carla_set_parameter_touch(handle, 0, param.rindex, true);
  513. // editParameter(0, true);
  514. }
  515. ui->values[i] = ui->parameters[i].bvalue ? ui->parameters[i].max : ui->parameters[i].min;
  516. carla_set_parameter_value(handle, 0, param.rindex, ui->values[i]);
  517. // setParameterValue(0, ui->values[i]);
  518. }
  519. }
  520. else
  521. {
  522. if (ImGui::SliderFloat(param.name, &ui->values[i], param.min, param.max, param.format))
  523. {
  524. if (ImGui::IsItemActivated())
  525. {
  526. carla_set_parameter_touch(handle, 0, param.rindex, true);
  527. // editParameter(0, true);
  528. }
  529. carla_set_parameter_value(handle, 0, param.rindex, ui->values[i]);
  530. // setParameterValue(0, ui->values[i]);
  531. }
  532. }
  533. if (ImGui::IsItemDeactivated())
  534. {
  535. carla_set_parameter_touch(handle, 0, param.rindex, false);
  536. // editParameter(0, false);
  537. }
  538. }
  539. }
  540. ImGui::End();
  541. }
  542. void drawLoading()
  543. {
  544. setupMainWindowPos();
  545. if (ImGui::Begin("Plugin List", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize))
  546. {
  547. ImGui::TextUnformatted("Loading...", nullptr);
  548. }
  549. ImGui::End();
  550. }
  551. void drawPluginList()
  552. {
  553. setupMainWindowPos();
  554. const CarlaHostHandle handle = fPlugin->fCarlaHostHandle;
  555. if (ImGui::Begin("Plugin List", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize))
  556. {
  557. if (ImGui::InputText("", fPluginSearchString, sizeof(fPluginSearchString)-1, ImGuiInputTextFlags_CharsNoBlank|ImGuiInputTextFlags_AutoSelectAll))
  558. fPluginSearchActive = true;
  559. ImGui::BeginDisabled(!fPluginScanningFinished);
  560. if (ImGui::Button("Load Plugin"))
  561. {
  562. do {
  563. const PluginInfoCache& info(fPlugins[fPluginSelected]);
  564. const char* label = nullptr;
  565. switch (fPluginType)
  566. {
  567. case PLUGIN_INTERNAL:
  568. label = info.label;
  569. break;
  570. case PLUGIN_LV2: {
  571. const char* const slash = std::strchr(info.label, DISTRHO_OS_SEP);
  572. DISTRHO_SAFE_ASSERT_BREAK(slash != nullptr);
  573. label = slash+1;
  574. break;
  575. }
  576. default:
  577. break;
  578. }
  579. DISTRHO_SAFE_ASSERT_BREAK(label != nullptr);
  580. d_stdout("Loading %s...", info.name);
  581. if (loadPlugin(handle, label))
  582. {
  583. ImGui::EndDisabled();
  584. ImGui::End();
  585. return;
  586. }
  587. } while (false);
  588. }
  589. ImGui::SameLine();
  590. ImGui::Checkbox("Run in bridge mode", &fPluginWillRunInBridgeMode);
  591. if (carla_get_current_plugin_count(handle) != 0)
  592. {
  593. ImGui::SameLine();
  594. if (ImGui::Button("Cancel"))
  595. {
  596. showPluginUI(handle);
  597. }
  598. }
  599. ImGui::EndDisabled();
  600. if (ImGui::BeginChild("pluginlistwindow"))
  601. {
  602. if (ImGui::BeginTable("pluginlist",
  603. fPluginType == PLUGIN_LV2 ? 3 : 2, ImGuiTableFlags_NoSavedSettings))
  604. {
  605. const char* const search = fPluginSearchActive && fPluginSearchString[0] != '\0' ? fPluginSearchString : nullptr;
  606. switch (fPluginType)
  607. {
  608. case PLUGIN_INTERNAL:
  609. ImGui::TableSetupColumn("Name");
  610. ImGui::TableSetupColumn("Label");
  611. ImGui::TableHeadersRow();
  612. break;
  613. case PLUGIN_LV2:
  614. ImGui::TableSetupColumn("Name");
  615. ImGui::TableSetupColumn("Bundle");
  616. ImGui::TableSetupColumn("URI");
  617. ImGui::TableHeadersRow();
  618. break;
  619. default:
  620. break;
  621. }
  622. for (uint i=0; i<fPluginCount; ++i)
  623. {
  624. const PluginInfoCache& info(fPlugins[i]);
  625. if (search != nullptr && strcasestr(info.name, search) == nullptr)
  626. continue;
  627. bool selected = fPluginSelected == i;
  628. switch (fPluginType)
  629. {
  630. case PLUGIN_INTERNAL:
  631. ImGui::TableNextRow();
  632. ImGui::TableSetColumnIndex(0);
  633. ImGui::Selectable(info.name, &selected);
  634. ImGui::TableSetColumnIndex(1);
  635. ImGui::Selectable(info.label, &selected);
  636. break;
  637. case PLUGIN_LV2: {
  638. const char* const slash = std::strchr(info.label, DISTRHO_OS_SEP);
  639. DISTRHO_SAFE_ASSERT_CONTINUE(slash != nullptr);
  640. ImGui::TableNextRow();
  641. ImGui::TableSetColumnIndex(0);
  642. ImGui::Selectable(info.name, &selected);
  643. ImGui::TableSetColumnIndex(1);
  644. ImGui::Selectable(slash+1, &selected);
  645. ImGui::TableSetColumnIndex(2);
  646. ImGui::TextUnformatted(info.label, slash);
  647. break;
  648. }
  649. default:
  650. break;
  651. }
  652. if (selected)
  653. fPluginSelected = i;
  654. }
  655. ImGui::EndTable();
  656. }
  657. ImGui::EndChild();
  658. }
  659. }
  660. ImGui::End();
  661. }
  662. protected:
  663. /* --------------------------------------------------------------------------------------------------------
  664. * DSP/Plugin Callbacks */
  665. void parameterChanged(uint32_t, float) override
  666. {
  667. }
  668. void stateChanged(const char* const key, const char* const) override
  669. {
  670. if (std::strcmp(key, "project") == 0)
  671. hidePluginUI();
  672. }
  673. // -------------------------------------------------------------------------------------------------------
  674. private:
  675. /**
  676. Set our UI class as non-copyable and add a leak detector just in case.
  677. */
  678. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(IldaeilUI)
  679. };
  680. // --------------------------------------------------------------------------------------------------------------------
  681. void ildaeilParameterChangeForUI(void* const ui, const uint32_t index, const float value)
  682. {
  683. DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,);
  684. static_cast<IldaeilUI*>(ui)->changeParameterFromDSP(index, value);
  685. }
  686. const char* ildaeilOpenFileForUI(void* const ui, const bool isDir, const char* const title, const char* const filter)
  687. {
  688. DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr, nullptr);
  689. return static_cast<IldaeilUI*>(ui)->openFileFromDSP(isDir, title, filter);
  690. }
  691. /* --------------------------------------------------------------------------------------------------------------------
  692. * UI entry point, called by DPF to create a new UI instance. */
  693. UI* createUI()
  694. {
  695. return new IldaeilUI();
  696. }
  697. // --------------------------------------------------------------------------------------------------------------------
  698. END_NAMESPACE_DISTRHO