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.

1280 lines
44KB

  1. /*
  2. * DISTRHO Cardinal Plugin
  3. * Copyright (C) 2021-2024 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 3 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 <app/MenuBar.hpp>
  18. #include <app/Scene.hpp>
  19. #include <asset.hpp>
  20. #include <context.hpp>
  21. #include <engine/Engine.hpp>
  22. #include <helpers.hpp>
  23. #include <patch.hpp>
  24. #include <settings.hpp>
  25. #include <string.hpp>
  26. #include <system.hpp>
  27. #include <ui/Button.hpp>
  28. #include <ui/MenuItem.hpp>
  29. #include <ui/MenuSeparator.hpp>
  30. #include <window/Window.hpp>
  31. #ifdef DPF_RUNTIME_TESTING
  32. # include <plugin.hpp>
  33. #endif
  34. #ifdef DISTRHO_OS_WASM
  35. # include <ui/Button.hpp>
  36. # include <ui/Label.hpp>
  37. # include <ui/MenuOverlay.hpp>
  38. # include <ui/SequentialLayout.hpp>
  39. # include <emscripten/emscripten.h>
  40. #endif
  41. #ifdef NDEBUG
  42. # undef DEBUG
  43. #endif
  44. #include "Application.hpp"
  45. #include "AsyncDialog.hpp"
  46. #include "CardinalCommon.hpp"
  47. #include "CardinalPluginContext.hpp"
  48. #include "WindowParameters.hpp"
  49. #include "extra/Base64.hpp"
  50. #ifndef DISTRHO_OS_WASM
  51. # include "extra/SharedResourcePointer.hpp"
  52. #endif
  53. #ifndef HEADLESS
  54. # include "extra/ScopedValueSetter.hpp"
  55. #endif
  56. namespace rack {
  57. #ifdef DISTRHO_OS_WASM
  58. namespace asset {
  59. std::string patchesPath();
  60. }
  61. #endif
  62. namespace engine {
  63. void Engine_setAboutToClose(Engine*);
  64. void Engine_setRemoteDetails(Engine*, remoteUtils::RemoteDetails*);
  65. }
  66. namespace window {
  67. void WindowSetPluginUI(Window* window, CardinalBaseUI* ui);
  68. void WindowSetMods(Window* window, int mods);
  69. void WindowSetInternalSize(rack::window::Window* window, math::Vec size);
  70. }
  71. }
  72. START_NAMESPACE_DISTRHO
  73. // --------------------------------------------------------------------------------------------------------------------
  74. #if ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  75. uint32_t Plugin::getBufferSize() const noexcept { return 0; }
  76. double Plugin::getSampleRate() const noexcept { return 0.0; }
  77. const char* Plugin::getBundlePath() const noexcept { return nullptr; }
  78. bool Plugin::isSelfTestInstance() const noexcept { return false; }
  79. bool Plugin::writeMidiEvent(const MidiEvent&) noexcept { return false; }
  80. #endif
  81. // --------------------------------------------------------------------------------------------------------------------
  82. #if defined(DISTRHO_OS_WASM) && ! CARDINAL_VARIANT_MINI
  83. struct WasmWelcomeDialog : rack::widget::OpaqueWidget
  84. {
  85. static const constexpr float margin = 10;
  86. static const constexpr float buttonWidth = 110;
  87. WasmWelcomeDialog()
  88. {
  89. using rack::ui::Button;
  90. using rack::ui::Label;
  91. using rack::ui::MenuOverlay;
  92. using rack::ui::SequentialLayout;
  93. box.size = rack::math::Vec(550, 310);
  94. SequentialLayout* const layout = new SequentialLayout;
  95. layout->box.pos = rack::math::Vec(0, 0);
  96. layout->box.size = box.size;
  97. layout->orientation = SequentialLayout::VERTICAL_ORIENTATION;
  98. layout->margin = rack::math::Vec(margin, margin);
  99. layout->spacing = rack::math::Vec(margin, margin);
  100. layout->wrap = false;
  101. addChild(layout);
  102. SequentialLayout* const contentLayout = new SequentialLayout;
  103. contentLayout->spacing = rack::math::Vec(margin, margin);
  104. layout->addChild(contentLayout);
  105. SequentialLayout* const buttonLayout = new SequentialLayout;
  106. buttonLayout->alignment = SequentialLayout::CENTER_ALIGNMENT;
  107. buttonLayout->box.size = box.size;
  108. buttonLayout->spacing = rack::math::Vec(margin, margin);
  109. layout->addChild(buttonLayout);
  110. Label* const label = new Label;
  111. label->box.size.x = box.size.x - 2*margin;
  112. label->box.size.y = box.size.y - 2*margin - 40;
  113. label->fontSize = 20;
  114. label->text = ""
  115. "Welcome to Cardinal on the Web!\n"
  116. "\n"
  117. "If using mobile/touch devices, please note:\n"
  118. " - Single quick press does simple mouse click\n"
  119. " - Press & move does click & drag action\n"
  120. " - Press & hold does right-click (and opens module browser)\n"
  121. "\n"
  122. "Still a bit experimental, so proceed with caution.\n"
  123. "Have fun!";
  124. contentLayout->addChild(label);
  125. struct JoinDiscussionButton : Button {
  126. WasmWelcomeDialog* dialog;
  127. void onAction(const ActionEvent& e) override {
  128. patchUtils::openBrowser("https://github.com/DISTRHO/Cardinal/issues/287");
  129. dialog->getParent()->requestDelete();
  130. }
  131. };
  132. JoinDiscussionButton* const discussionButton = new JoinDiscussionButton;
  133. discussionButton->box.size.x = buttonWidth;
  134. discussionButton->text = "Join discussion";
  135. discussionButton->dialog = this;
  136. buttonLayout->addChild(discussionButton);
  137. struct DismissButton : Button {
  138. WasmWelcomeDialog* dialog;
  139. void onAction(const ActionEvent& e) override {
  140. dialog->getParent()->requestDelete();
  141. }
  142. };
  143. DismissButton* const dismissButton = new DismissButton;
  144. dismissButton->box.size.x = buttonWidth;
  145. dismissButton->text = "Dismiss";
  146. dismissButton->dialog = this;
  147. buttonLayout->addChild(dismissButton);
  148. MenuOverlay* const overlay = new MenuOverlay;
  149. overlay->bgColor = nvgRGBAf(0, 0, 0, 0.33);
  150. overlay->addChild(this);
  151. APP->scene->addChild(overlay);
  152. }
  153. void step() override
  154. {
  155. OpaqueWidget::step();
  156. box.pos = parent->box.size.minus(box.size).div(2).round();
  157. }
  158. void draw(const DrawArgs& args) override
  159. {
  160. bndMenuBackground(args.vg, 0.0, 0.0, box.size.x, box.size.y, 0);
  161. Widget::draw(args);
  162. }
  163. };
  164. struct WasmRemotePatchLoadingDialog : rack::widget::OpaqueWidget
  165. {
  166. static const constexpr float margin = 10;
  167. rack::ui::MenuOverlay* overlay;
  168. WasmRemotePatchLoadingDialog(const bool isFromPatchStorage)
  169. {
  170. using rack::ui::Label;
  171. using rack::ui::MenuOverlay;
  172. using rack::ui::SequentialLayout;
  173. box.size = rack::math::Vec(300, 40);
  174. SequentialLayout* const layout = new SequentialLayout;
  175. layout->box.pos = rack::math::Vec(0, 0);
  176. layout->box.size = box.size;
  177. layout->alignment = SequentialLayout::CENTER_ALIGNMENT;
  178. layout->margin = rack::math::Vec(margin, margin);
  179. layout->spacing = rack::math::Vec(margin, margin);
  180. layout->wrap = false;
  181. addChild(layout);
  182. Label* const label = new Label;
  183. label->box.size.x = box.size.x - 2*margin;
  184. label->box.size.y = box.size.y - 2*margin;
  185. label->fontSize = 16;
  186. label->text = isFromPatchStorage
  187. ? "Loading patch from PatchStorage...\n"
  188. : "Loading remote patch...\n";
  189. layout->addChild(label);
  190. overlay = new MenuOverlay;
  191. overlay->bgColor = nvgRGBAf(0, 0, 0, 0.33);
  192. overlay->addChild(this);
  193. APP->scene->addChild(overlay);
  194. }
  195. void step() override
  196. {
  197. OpaqueWidget::step();
  198. box.pos = parent->box.size.minus(box.size).div(2).round();
  199. }
  200. void draw(const DrawArgs& args) override
  201. {
  202. bndMenuBackground(args.vg, 0.0, 0.0, box.size.x, box.size.y, 0);
  203. Widget::draw(args);
  204. }
  205. };
  206. static void downloadRemotePatchFailed(const char* const filename)
  207. {
  208. d_stdout("downloadRemotePatchFailed %s", filename);
  209. CardinalPluginContext* const context = static_cast<CardinalPluginContext*>(APP);
  210. CardinalBaseUI* const ui = static_cast<CardinalBaseUI*>(context->ui);
  211. if (ui->psDialog != nullptr)
  212. {
  213. ui->psDialog->overlay->requestDelete();
  214. ui->psDialog = nullptr;
  215. asyncDialog::create("Failed to fetch remote patch");
  216. }
  217. using namespace rack;
  218. context->patch->templatePath = rack::system::join(asset::patchesPath(), "templates/main.vcv");
  219. context->patch->loadTemplate();
  220. context->scene->rackScroll->reset();
  221. }
  222. static void downloadRemotePatchSucceeded(const char* const filename)
  223. {
  224. d_stdout("downloadRemotePatchSucceeded %s | %s", filename, APP->patch->templatePath.c_str());
  225. CardinalPluginContext* const context = static_cast<CardinalPluginContext*>(APP);
  226. CardinalBaseUI* const ui = static_cast<CardinalBaseUI*>(context->ui);
  227. ui->psDialog->overlay->requestDelete();
  228. ui->psDialog = nullptr;
  229. if (FILE* f = fopen(filename, "r"))
  230. {
  231. uint8_t buf[8] = {};
  232. fread(buf, 8, 1, f);
  233. d_stdout("read patch %x %x %x %x %x %x %x %x",
  234. buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7]);
  235. fclose(f);
  236. }
  237. try {
  238. context->patch->load(filename);
  239. } catch (rack::Exception& e) {
  240. const std::string message = rack::string::f("Could not load patch: %s", e.what());
  241. asyncDialog::create(message.c_str());
  242. return;
  243. }
  244. context->patch->path.clear();
  245. context->scene->rackScroll->reset();
  246. context->history->setSaved();
  247. }
  248. #endif
  249. // -----------------------------------------------------------------------------------------------------------
  250. class CardinalUI : public CardinalBaseUI,
  251. public WindowParametersCallback
  252. {
  253. #if ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  254. #ifdef DISTRHO_OS_WASM
  255. ScopedPointer<Initializer> fInitializer;
  256. #else
  257. SharedResourcePointer<Initializer> fInitializer;
  258. #endif
  259. std::string fAutosavePath;
  260. #endif
  261. rack::math::Vec lastMousePos;
  262. WindowParameters windowParameters;
  263. int rateLimitStep = 0;
  264. #if defined(DISTRHO_OS_WASM) && ! CARDINAL_VARIANT_MINI
  265. int8_t counterForFirstIdlePoint = 0;
  266. #endif
  267. #ifdef DPF_RUNTIME_TESTING
  268. bool inSelfTest = false;
  269. #endif
  270. struct ScopedContext {
  271. CardinalPluginContext* const context;
  272. ScopedContext(CardinalUI* const ui)
  273. : context(ui->context)
  274. {
  275. rack::contextSet(context);
  276. WindowParametersRestore(context->window);
  277. }
  278. ScopedContext(CardinalUI* const ui, const int mods)
  279. : context(ui->context)
  280. {
  281. rack::contextSet(context);
  282. rack::window::WindowSetMods(context->window, mods);
  283. WindowParametersRestore(context->window);
  284. }
  285. ~ScopedContext()
  286. {
  287. if (context->window != nullptr)
  288. WindowParametersSave(context->window);
  289. }
  290. };
  291. public:
  292. CardinalUI()
  293. : CardinalBaseUI(),
  294. #if ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  295. #ifdef DISTRHO_OS_WASM
  296. fInitializer(new Initializer(static_cast<const CardinalBasePlugin*>(nullptr), this)),
  297. #else
  298. fInitializer(static_cast<const CardinalBasePlugin*>(nullptr), this),
  299. #endif
  300. #endif
  301. lastMousePos()
  302. {
  303. rack::contextSet(context);
  304. #if CARDINAL_VARIANT_MINI && ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  305. // create unique temporary path for this instance
  306. try {
  307. char uidBuf[24];
  308. const std::string tmp = rack::system::getTempDirectory();
  309. for (int i=1;; ++i)
  310. {
  311. std::snprintf(uidBuf, sizeof(uidBuf), "Cardinal.%04d", i);
  312. const std::string trypath = rack::system::join(tmp, uidBuf);
  313. if (! rack::system::exists(trypath))
  314. {
  315. if (rack::system::createDirectories(trypath))
  316. fAutosavePath = trypath;
  317. break;
  318. }
  319. }
  320. } DISTRHO_SAFE_EXCEPTION("create unique temporary path");
  321. const float sampleRate = 60; // fake audio running at 60 fps
  322. rack::settings::sampleRate = sampleRate;
  323. context->dataIns = new const float*[DISTRHO_PLUGIN_NUM_INPUTS];
  324. context->dataOuts = new float*[DISTRHO_PLUGIN_NUM_OUTPUTS];
  325. for (uint32_t i=0; i<DISTRHO_PLUGIN_NUM_INPUTS;++i)
  326. {
  327. float** const bufferptr = const_cast<float**>(&context->dataIns[i]);
  328. *bufferptr = new float[1];
  329. (*bufferptr)[0] = 0.f;
  330. }
  331. for (uint32_t i=0; i<DISTRHO_PLUGIN_NUM_OUTPUTS;++i)
  332. context->dataOuts[i] = new float[1];
  333. context->bufferSize = 1;
  334. context->sampleRate = sampleRate;
  335. context->engine = new rack::engine::Engine;
  336. context->engine->setSampleRate(sampleRate);
  337. context->history = new rack::history::State;
  338. context->patch = new rack::patch::Manager;
  339. context->patch->autosavePath = fAutosavePath;
  340. context->patch->templatePath = context->patch->factoryTemplatePath = fInitializer->factoryTemplatePath;
  341. context->event = new rack::widget::EventState;
  342. context->scene = new rack::app::Scene;
  343. context->event->rootWidget = context->scene;
  344. context->window = new rack::window::Window;
  345. context->patch->loadTemplate();
  346. context->scene->rackScroll->reset();
  347. DISTRHO_SAFE_ASSERT(remoteUtils::connectToRemote(CARDINAL_DEFAULT_REMOTE_URL));
  348. Engine_setRemoteDetails(context->engine, remoteDetails);
  349. #endif
  350. Window& window(getWindow());
  351. window.setIgnoringKeyRepeat(true);
  352. context->nativeWindowId = window.getNativeWindowHandle();
  353. const double scaleFactor = getScaleFactor();
  354. setGeometryConstraints(648 * scaleFactor, 538 * scaleFactor);
  355. if (rack::isStandalone() && rack::system::exists(rack::settings::settingsPath))
  356. {
  357. const double width = std::max(648.f, rack::settings::windowSize.x) * scaleFactor;
  358. const double height = std::max(538.f, rack::settings::windowSize.y) * scaleFactor;
  359. setSize(width, height);
  360. }
  361. #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  362. const DGL_NAMESPACE::Window::ScopedGraphicsContext sgc(window);
  363. #endif
  364. rack::window::WindowSetPluginUI(context->window, this);
  365. // hide "Browse VCV Library" button
  366. rack::widget::Widget* const browser = context->scene->browser->children.back();
  367. rack::widget::Widget* const headerLayout = browser->children.front();
  368. rack::widget::Widget* const libraryButton = headerLayout->children.back();
  369. libraryButton->hide();
  370. // Report to user if something is wrong with the installation
  371. std::string errorMessage;
  372. if (rack::asset::systemDir.empty())
  373. {
  374. errorMessage = "Failed to locate Cardinal plugin bundle.\n"
  375. "Install Cardinal with its plugin bundle folder intact and try again.";
  376. }
  377. else if (! rack::system::exists(rack::asset::systemDir))
  378. {
  379. errorMessage = rack::string::f("System directory \"%s\" does not exist. "
  380. "Make sure Cardinal was downloaded and installed correctly.",
  381. rack::asset::systemDir.c_str());
  382. }
  383. if (! errorMessage.empty())
  384. {
  385. static bool shown = false;
  386. if (! shown)
  387. {
  388. shown = true;
  389. asyncDialog::create(errorMessage.c_str());
  390. }
  391. }
  392. #if defined(DISTRHO_OS_WASM) && ! CARDINAL_VARIANT_MINI
  393. if (rack::patchStorageSlug != nullptr)
  394. {
  395. psDialog = new WasmRemotePatchLoadingDialog(true);
  396. }
  397. else if (rack::patchRemoteURL != nullptr)
  398. {
  399. psDialog = new WasmRemotePatchLoadingDialog(false);
  400. }
  401. else if (rack::patchFromURL != nullptr)
  402. {
  403. static_cast<CardinalBasePlugin*>(context->plugin)->setState("patch", rack::patchFromURL);
  404. rack::contextSet(context);
  405. }
  406. else
  407. {
  408. new WasmWelcomeDialog();
  409. }
  410. #endif
  411. context->window->step();
  412. rack::contextSet(nullptr);
  413. WindowParametersSetCallback(context->window, this);
  414. }
  415. ~CardinalUI() override
  416. {
  417. rack::contextSet(context);
  418. context->nativeWindowId = 0;
  419. rack::window::WindowSetPluginUI(context->window, nullptr);
  420. context->tlw = nullptr;
  421. context->ui = nullptr;
  422. #if CARDINAL_VARIANT_MINI && ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  423. {
  424. const ScopedContext sc(this);
  425. context->patch->clear();
  426. // do a little dance to prevent context scene deletion from saving to temp dir
  427. const ScopedValueSetter<bool> svs(rack::settings::headless, true);
  428. Engine_setAboutToClose(context->engine);
  429. delete context;
  430. }
  431. if (! fAutosavePath.empty())
  432. rack::system::removeRecursively(fAutosavePath);
  433. #endif
  434. #if ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  435. if (fInitializer->shouldSaveSettings)
  436. {
  437. INFO("Save settings");
  438. rack::settings::save();
  439. }
  440. #endif
  441. rack::contextSet(nullptr);
  442. }
  443. void onNanoDisplay() override
  444. {
  445. const ScopedContext sc(this);
  446. context->window->step();
  447. }
  448. void uiIdle() override
  449. {
  450. #ifdef DPF_RUNTIME_TESTING
  451. if (inSelfTest)
  452. {
  453. context->window->step();
  454. return;
  455. }
  456. if (context->plugin->isSelfTestInstance())
  457. {
  458. inSelfTest = true;
  459. Application& app(getApp());
  460. const ScopedContext sc(this);
  461. context->patch->clear();
  462. app.idle();
  463. const rack::math::Vec mousePos(getWidth()/2,getHeight()/2);
  464. context->event->handleButton(mousePos, GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE, 0x0);
  465. context->event->handleHover(mousePos, rack::math::Vec(0,0));
  466. app.idle();
  467. for (rack::plugin::Plugin* p : rack::plugin::plugins)
  468. {
  469. for (rack::plugin::Model* m : p->models)
  470. {
  471. d_stdout(">>>>>>>>>>>>>>>>> LOADING module %s : %s", p->slug.c_str(), m->slug.c_str());
  472. rack::engine::Module* const module = m->createModule();
  473. DISTRHO_SAFE_ASSERT_CONTINUE(module != nullptr);
  474. rack::CardinalPluginModelHelper* const helper = dynamic_cast<rack::CardinalPluginModelHelper*>(m);
  475. DISTRHO_SAFE_ASSERT_CONTINUE(helper != nullptr);
  476. d_stdout(">>>>>>>>>>>>>>>>> LOADING moduleWidget %s : %s", p->slug.c_str(), m->slug.c_str());
  477. rack::app::ModuleWidget* const moduleWidget = helper->createModuleWidget(module);
  478. DISTRHO_SAFE_ASSERT_CONTINUE(moduleWidget != nullptr);
  479. d_stdout(">>>>>>>>>>>>>>>>> ADDING TO ENGINE %s : %s", p->slug.c_str(), m->slug.c_str());
  480. context->engine->addModule(module);
  481. d_stdout(">>>>>>>>>>>>>>>>> ADDING TO RACK VIEW %s : %s", p->slug.c_str(), m->slug.c_str());
  482. context->scene->rack->addModuleAtMouse(moduleWidget);
  483. for (int i=5; --i>=0;)
  484. app.idle();
  485. d_stdout(">>>>>>>>>>>>>>>>> REMOVING FROM RACK VIEW %s : %s", p->slug.c_str(), m->slug.c_str());
  486. context->scene->rack->removeModule(moduleWidget);
  487. app.idle();
  488. d_stdout(">>>>>>>>>>>>>>>>> DELETING module + moduleWidget %s : %s", p->slug.c_str(), m->slug.c_str());
  489. delete moduleWidget;
  490. app.idle();
  491. }
  492. }
  493. inSelfTest = false;
  494. }
  495. #endif
  496. #if defined(DISTRHO_OS_WASM) && ! CARDINAL_VARIANT_MINI
  497. if (counterForFirstIdlePoint >= 0 && ++counterForFirstIdlePoint == 30)
  498. {
  499. counterForFirstIdlePoint = -1;
  500. if (rack::patchStorageSlug != nullptr)
  501. {
  502. std::string url("/patchstorage.php?slug=");
  503. url += rack::patchStorageSlug;
  504. std::free(rack::patchStorageSlug);
  505. rack::patchStorageSlug = nullptr;
  506. emscripten_async_wget(url.c_str(), context->patch->templatePath.c_str(),
  507. downloadRemotePatchSucceeded, downloadRemotePatchFailed);
  508. }
  509. else if (rack::patchRemoteURL != nullptr)
  510. {
  511. std::string url("/patchurl.php?url=");
  512. url += rack::patchRemoteURL;
  513. std::free(rack::patchRemoteURL);
  514. rack::patchRemoteURL = nullptr;
  515. emscripten_async_wget(url.c_str(), context->patch->templatePath.c_str(),
  516. downloadRemotePatchSucceeded, downloadRemotePatchFailed);
  517. }
  518. }
  519. #endif
  520. if (filebrowserhandle != nullptr && fileBrowserIdle(filebrowserhandle))
  521. {
  522. {
  523. const char* const path = fileBrowserGetPath(filebrowserhandle);
  524. const ScopedContext sc(this);
  525. filebrowseraction(path != nullptr ? strdup(path) : nullptr);
  526. }
  527. fileBrowserClose(filebrowserhandle);
  528. filebrowseraction = nullptr;
  529. filebrowserhandle = nullptr;
  530. }
  531. #if CARDINAL_VARIANT_MINI && ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  532. {
  533. const ScopedContext sc(this);
  534. for (uint32_t i=0; i<DISTRHO_PLUGIN_NUM_OUTPUTS;++i)
  535. context->dataOuts[i][0] = 0.f;
  536. ++context->processCounter;
  537. context->engine->stepBlock(1);
  538. }
  539. #endif
  540. if (windowParameters.rateLimit != 0 && ++rateLimitStep % (windowParameters.rateLimit * 2))
  541. return;
  542. rateLimitStep = 0;
  543. repaint();
  544. }
  545. void WindowParametersChanged(const WindowParameterList param, float value) override
  546. {
  547. float mult = 1.0f;
  548. switch (param)
  549. {
  550. case kWindowParameterShowTooltips:
  551. windowParameters.tooltips = value > 0.5f;
  552. break;
  553. case kWindowParameterCableOpacity:
  554. mult = 100.0f;
  555. windowParameters.cableOpacity = value;
  556. break;
  557. case kWindowParameterCableTension:
  558. mult = 100.0f;
  559. windowParameters.cableTension = value;
  560. break;
  561. case kWindowParameterRackBrightness:
  562. mult = 100.0f;
  563. windowParameters.rackBrightness = value;
  564. break;
  565. case kWindowParameterHaloBrightness:
  566. mult = 100.0f;
  567. windowParameters.haloBrightness = value;
  568. break;
  569. case kWindowParameterKnobMode:
  570. switch (static_cast<int>(value + 0.5f))
  571. {
  572. case rack::settings::KNOB_MODE_LINEAR:
  573. value = 0;
  574. windowParameters.knobMode = rack::settings::KNOB_MODE_LINEAR;
  575. break;
  576. case rack::settings::KNOB_MODE_ROTARY_ABSOLUTE:
  577. value = 1;
  578. windowParameters.knobMode = rack::settings::KNOB_MODE_ROTARY_ABSOLUTE;
  579. break;
  580. case rack::settings::KNOB_MODE_ROTARY_RELATIVE:
  581. value = 2;
  582. windowParameters.knobMode = rack::settings::KNOB_MODE_ROTARY_RELATIVE;
  583. break;
  584. }
  585. break;
  586. case kWindowParameterWheelKnobControl:
  587. windowParameters.knobScroll = value > 0.5f;
  588. break;
  589. case kWindowParameterWheelSensitivity:
  590. mult = 1000.0f;
  591. windowParameters.knobScrollSensitivity = value;
  592. break;
  593. case kWindowParameterLockModulePositions:
  594. windowParameters.lockModules = value > 0.5f;
  595. break;
  596. case kWindowParameterUpdateRateLimit:
  597. windowParameters.rateLimit = static_cast<int>(value + 0.5f);
  598. rateLimitStep = 0;
  599. break;
  600. case kWindowParameterBrowserSort:
  601. windowParameters.browserSort = static_cast<int>(value + 0.5f);
  602. break;
  603. case kWindowParameterBrowserZoom:
  604. windowParameters.browserZoom = value;
  605. value = std::pow(2.f, value) * 100.0f;
  606. break;
  607. case kWindowParameterInvertZoom:
  608. windowParameters.invertZoom = value > 0.5f;
  609. break;
  610. case kWindowParameterSqueezeModulePositions:
  611. windowParameters.squeezeModules = value > 0.5f;
  612. break;
  613. default:
  614. return;
  615. }
  616. setParameterValue(kCardinalParameterStartWindow + param, value * mult);
  617. }
  618. protected:
  619. /* --------------------------------------------------------------------------------------------------------
  620. * DSP/Plugin Callbacks */
  621. /**
  622. A parameter has changed on the plugin side.
  623. This is called by the host to inform the UI about parameter changes.
  624. */
  625. void parameterChanged(const uint32_t index, const float value) override
  626. {
  627. // host mapped parameters
  628. if (index < kCardinalParameterCountAtModules)
  629. {
  630. #if CARDINAL_VARIANT_MINI && ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  631. context->parameters[index] = value;
  632. #endif
  633. return;
  634. }
  635. // bypass
  636. if (index == kCardinalParameterBypass)
  637. {
  638. #if CARDINAL_VARIANT_MINI && ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  639. context->bypassed = value > 0.5f;
  640. #endif
  641. return;
  642. }
  643. if (index < kCardinalParameterCountAtWindow)
  644. {
  645. switch (index - kCardinalParameterStartWindow)
  646. {
  647. case kWindowParameterShowTooltips:
  648. windowParameters.tooltips = value > 0.5f;
  649. break;
  650. case kWindowParameterCableOpacity:
  651. windowParameters.cableOpacity = value / 100.0f;
  652. break;
  653. case kWindowParameterCableTension:
  654. windowParameters.cableTension = value / 100.0f;
  655. break;
  656. case kWindowParameterRackBrightness:
  657. windowParameters.rackBrightness = value / 100.0f;
  658. break;
  659. case kWindowParameterHaloBrightness:
  660. windowParameters.haloBrightness = value / 100.0f;
  661. break;
  662. case kWindowParameterKnobMode:
  663. switch (static_cast<int>(value + 0.5f))
  664. {
  665. case 0:
  666. windowParameters.knobMode = rack::settings::KNOB_MODE_LINEAR;
  667. break;
  668. case 1:
  669. windowParameters.knobMode = rack::settings::KNOB_MODE_ROTARY_ABSOLUTE;
  670. break;
  671. case 2:
  672. windowParameters.knobMode = rack::settings::KNOB_MODE_ROTARY_RELATIVE;
  673. break;
  674. }
  675. break;
  676. case kWindowParameterWheelKnobControl:
  677. windowParameters.knobScroll = value > 0.5f;
  678. break;
  679. case kWindowParameterWheelSensitivity:
  680. windowParameters.knobScrollSensitivity = value / 1000.0f;
  681. break;
  682. case kWindowParameterLockModulePositions:
  683. windowParameters.lockModules = value > 0.5f;
  684. break;
  685. case kWindowParameterUpdateRateLimit:
  686. windowParameters.rateLimit = static_cast<int>(value + 0.5f);
  687. rateLimitStep = 0;
  688. break;
  689. case kWindowParameterBrowserSort:
  690. windowParameters.browserSort = static_cast<int>(value + 0.5f);
  691. break;
  692. case kWindowParameterBrowserZoom:
  693. // round up to nearest valid value
  694. {
  695. float rvalue = value - 1.0f;
  696. if (rvalue <= 25.0f)
  697. rvalue = -2.0f;
  698. else if (rvalue <= 35.0f)
  699. rvalue = -1.5f;
  700. else if (rvalue <= 50.0f)
  701. rvalue = -1.0f;
  702. else if (rvalue <= 71.0f)
  703. rvalue = -0.5f;
  704. else if (rvalue <= 100.0f)
  705. rvalue = 0.0f;
  706. else if (rvalue <= 141.0f)
  707. rvalue = 0.5f;
  708. else if (rvalue <= 200.0f)
  709. rvalue = 1.0f;
  710. else
  711. rvalue = 0.0f;
  712. windowParameters.browserZoom = rvalue;
  713. }
  714. break;
  715. case kWindowParameterInvertZoom:
  716. windowParameters.invertZoom = value > 0.5f;
  717. break;
  718. case kWindowParameterSqueezeModulePositions:
  719. windowParameters.squeezeModules = value > 0.5f;
  720. break;
  721. default:
  722. return;
  723. }
  724. WindowParametersSetValues(context->window, windowParameters);
  725. return;
  726. }
  727. #if CARDINAL_VARIANT_MINI && ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  728. if (index < kCardinalParameterCountAtMiniBuffers)
  729. {
  730. float* const buffer = *const_cast<float**>(&context->dataIns[index - kCardinalParameterStartMiniBuffers]);
  731. buffer[0] = value;
  732. return;
  733. }
  734. switch (index)
  735. {
  736. case kCardinalParameterMiniTimeFlags: {
  737. const int32_t flags = static_cast<int32_t>(value + 0.5f);
  738. context->playing = flags & 0x1;
  739. context->bbtValid = flags & 0x2;
  740. context->reset = flags & 0x4;
  741. return;
  742. }
  743. case kCardinalParameterMiniTimeBar:
  744. context->bar = static_cast<int32_t>(value + 0.5f);
  745. return;
  746. case kCardinalParameterMiniTimeBeat:
  747. context->beat = static_cast<int32_t>(value + 0.5f);
  748. return;
  749. case kCardinalParameterMiniTimeBeatsPerBar:
  750. context->beatsPerBar = static_cast<int32_t>(value + 0.5f);
  751. return;
  752. case kCardinalParameterMiniTimeBeatType:
  753. context->beatType = static_cast<int32_t>(value + 0.5f);
  754. context->ticksPerClock = context->ticksPerBeat / context->beatType;
  755. context->tickClock = std::fmod(context->tick, context->ticksPerClock);
  756. return;
  757. case kCardinalParameterMiniTimeFrame:
  758. context->frame = static_cast<uint64_t>(value * context->sampleRate + 0.5f);
  759. return;
  760. case kCardinalParameterMiniTimeBarStartTick:
  761. context->barStartTick = value;
  762. return;
  763. case kCardinalParameterMiniTimeBeatsPerMinute:
  764. context->beatsPerMinute = value;
  765. context->ticksPerFrame = 1.0 / (60.0 * context->sampleRate / context->beatsPerMinute / context->ticksPerBeat);
  766. return;
  767. case kCardinalParameterMiniTimeTick:
  768. context->tick = value;
  769. context->tickClock = std::fmod(context->tick, context->ticksPerClock);
  770. return;
  771. case kCardinalParameterMiniTimeTicksPerBeat:
  772. context->ticksPerBeat = value;
  773. context->ticksPerClock = context->ticksPerBeat / context->beatType;
  774. context->ticksPerFrame = 1.0 / (60.0 * context->sampleRate / context->beatsPerMinute / context->ticksPerBeat);
  775. context->tickClock = std::fmod(context->tick, context->ticksPerClock);
  776. return;
  777. }
  778. #endif
  779. }
  780. void stateChanged(const char* const key, const char* const value) override
  781. {
  782. #if CARDINAL_VARIANT_MINI && ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
  783. if (std::strcmp(key, "patch") == 0)
  784. {
  785. if (fAutosavePath.empty())
  786. return;
  787. rack::system::removeRecursively(fAutosavePath);
  788. rack::system::createDirectories(fAutosavePath);
  789. FILE* const f = std::fopen(rack::system::join(fAutosavePath, "patch.json").c_str(), "w");
  790. DISTRHO_SAFE_ASSERT_RETURN(f != nullptr,);
  791. std::fwrite(value, std::strlen(value), 1, f);
  792. std::fclose(f);
  793. const ScopedContext sc(this);
  794. try {
  795. context->patch->loadAutosave();
  796. } catch(const rack::Exception& e) {
  797. d_stderr(e.what());
  798. } DISTRHO_SAFE_EXCEPTION_RETURN("stateChanged loadAutosave",);
  799. return;
  800. }
  801. #endif
  802. if (std::strcmp(key, "windowSize") == 0)
  803. {
  804. int width = 0;
  805. int height = 0;
  806. std::sscanf(value, "%d:%d", &width, &height);
  807. if (width > 0 && height > 0)
  808. {
  809. const double scaleFactor = getScaleFactor();
  810. setSize(width * scaleFactor, height * scaleFactor);
  811. }
  812. return;
  813. }
  814. }
  815. // -------------------------------------------------------------------------------------------------------
  816. static int glfwMods(const uint mod) noexcept
  817. {
  818. int mods = 0;
  819. if (mod & kModifierControl)
  820. mods |= GLFW_MOD_CONTROL;
  821. if (mod & kModifierShift)
  822. mods |= GLFW_MOD_SHIFT;
  823. if (mod & kModifierAlt)
  824. mods |= GLFW_MOD_ALT;
  825. if (mod & kModifierSuper)
  826. mods |= GLFW_MOD_SUPER;
  827. /*
  828. if (glfwGetKey(win, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(win, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS)
  829. mods |= GLFW_MOD_SHIFT;
  830. if (glfwGetKey(win, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS || glfwGetKey(win, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS)
  831. mods |= GLFW_MOD_CONTROL;
  832. if (glfwGetKey(win, GLFW_KEY_LEFT_ALT) == GLFW_PRESS || glfwGetKey(win, GLFW_KEY_RIGHT_ALT) == GLFW_PRESS)
  833. mods |= GLFW_MOD_ALT;
  834. if (glfwGetKey(win, GLFW_KEY_LEFT_SUPER) == GLFW_PRESS || glfwGetKey(win, GLFW_KEY_RIGHT_SUPER) == GLFW_PRESS)
  835. mods |= GLFW_MOD_SUPER;
  836. */
  837. return mods;
  838. }
  839. bool onMouse(const MouseEvent& ev) override
  840. {
  841. #ifdef DPF_RUNTIME_TESTING
  842. if (inSelfTest) return false;
  843. #endif
  844. if (ev.press)
  845. getWindow().focus();
  846. const int action = ev.press ? GLFW_PRESS : GLFW_RELEASE;
  847. int mods = glfwMods(ev.mod);
  848. int button;
  849. switch (ev.button)
  850. {
  851. case kMouseButtonLeft: button = GLFW_MOUSE_BUTTON_LEFT; break;
  852. case kMouseButtonRight: button = GLFW_MOUSE_BUTTON_RIGHT; break;
  853. case kMouseButtonMiddle: button = GLFW_MOUSE_BUTTON_MIDDLE; break;
  854. default:
  855. button = ev.button;
  856. break;
  857. }
  858. #ifdef DISTRHO_OS_MAC
  859. // Remap Ctrl-left click to right click on macOS
  860. if (button == GLFW_MOUSE_BUTTON_LEFT && (mods & RACK_MOD_MASK) == GLFW_MOD_CONTROL) {
  861. button = GLFW_MOUSE_BUTTON_RIGHT;
  862. mods &= ~GLFW_MOD_CONTROL;
  863. }
  864. // Remap Ctrl-shift-left click to middle click on macOS
  865. if (button == GLFW_MOUSE_BUTTON_LEFT && (mods & RACK_MOD_MASK) == (GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) {
  866. button = GLFW_MOUSE_BUTTON_MIDDLE;
  867. mods &= ~(GLFW_MOD_CONTROL | GLFW_MOD_SHIFT);
  868. }
  869. #endif
  870. const ScopedContext sc(this, mods);
  871. return context->event->handleButton(lastMousePos, button, action, mods);
  872. }
  873. bool onMotion(const MotionEvent& ev) override
  874. {
  875. #ifdef DPF_RUNTIME_TESTING
  876. if (inSelfTest) return false;
  877. #endif
  878. const rack::math::Vec mousePos = rack::math::Vec(ev.pos.getX(), ev.pos.getY()).div(getScaleFactor()).round();
  879. const rack::math::Vec mouseDelta = mousePos.minus(lastMousePos);
  880. lastMousePos = mousePos;
  881. const ScopedContext sc(this, glfwMods(ev.mod));
  882. return context->event->handleHover(mousePos, mouseDelta);
  883. }
  884. bool onScroll(const ScrollEvent& ev) override
  885. {
  886. #ifdef DPF_RUNTIME_TESTING
  887. if (inSelfTest) return false;
  888. #endif
  889. const rack::math::Vec scrollDelta = rack::math::Vec(-ev.delta.getX(), ev.delta.getY()) * 50 ;
  890. const int mods = glfwMods(ev.mod);
  891. const ScopedContext sc(this, mods);
  892. return context->event->handleScroll(lastMousePos, scrollDelta);
  893. }
  894. bool onCharacterInput(const CharacterInputEvent& ev) override
  895. {
  896. #ifdef DPF_RUNTIME_TESTING
  897. if (inSelfTest) return false;
  898. #endif
  899. if (ev.character < ' ' || ev.character >= kKeyDelete)
  900. return false;
  901. const int mods = glfwMods(ev.mod);
  902. const ScopedContext sc(this, mods);
  903. return context->event->handleText(lastMousePos, ev.character);
  904. }
  905. bool onKeyboard(const KeyboardEvent& ev) override
  906. {
  907. #ifdef DPF_RUNTIME_TESTING
  908. if (inSelfTest) return false;
  909. #endif
  910. const int action = ev.press ? GLFW_PRESS : GLFW_RELEASE;
  911. const int mods = glfwMods(ev.mod);
  912. int key;
  913. switch (ev.key)
  914. {
  915. case kKeyTab: key = GLFW_KEY_TAB; break;
  916. case kKeyBackspace: key = GLFW_KEY_BACKSPACE; break;
  917. case kKeyEnter: key = GLFW_KEY_ENTER; break;
  918. case kKeyEscape: key = GLFW_KEY_ESCAPE; break;
  919. case kKeyDelete: key = GLFW_KEY_DELETE; break;
  920. case kKeySpace: key = GLFW_KEY_SPACE; break;
  921. case kKeyF1: key = GLFW_KEY_F1; break;
  922. case kKeyF2: key = GLFW_KEY_F2; break;
  923. case kKeyF3: key = GLFW_KEY_F3; break;
  924. case kKeyF4: key = GLFW_KEY_F4; break;
  925. case kKeyF5: key = GLFW_KEY_F5; break;
  926. case kKeyF6: key = GLFW_KEY_F6; break;
  927. case kKeyF7: key = GLFW_KEY_F7; break;
  928. case kKeyF8: key = GLFW_KEY_F8; break;
  929. case kKeyF9: key = GLFW_KEY_F9; break;
  930. case kKeyF10: key = GLFW_KEY_F10; break;
  931. case kKeyF11: key = GLFW_KEY_F11; break;
  932. case kKeyF12: key = GLFW_KEY_F12; break;
  933. case kKeyPageUp: key = GLFW_KEY_PAGE_UP; break;
  934. case kKeyPageDown: key = GLFW_KEY_PAGE_DOWN; break;
  935. case kKeyEnd: key = GLFW_KEY_END; break;
  936. case kKeyHome: key = GLFW_KEY_HOME; break;
  937. case kKeyLeft: key = GLFW_KEY_LEFT; break;
  938. case kKeyUp: key = GLFW_KEY_UP; break;
  939. case kKeyRight: key = GLFW_KEY_RIGHT; break;
  940. case kKeyDown: key = GLFW_KEY_DOWN; break;
  941. case kKeyPrintScreen: key = GLFW_KEY_PRINT_SCREEN; break;
  942. case kKeyInsert: key = GLFW_KEY_INSERT; break;
  943. case kKeyPause: key = GLFW_KEY_PAUSE; break;
  944. case kKeyMenu: key = GLFW_KEY_MENU; break;
  945. case kKeyNumLock: key = GLFW_KEY_NUM_LOCK; break;
  946. case kKeyScrollLock: key = GLFW_KEY_SCROLL_LOCK; break;
  947. case kKeyCapsLock: key = GLFW_KEY_CAPS_LOCK; break;
  948. case kKeyShiftL: key = GLFW_KEY_LEFT_SHIFT; break;
  949. case kKeyShiftR: key = GLFW_KEY_RIGHT_SHIFT; break;
  950. case kKeyControlL: key = GLFW_KEY_LEFT_CONTROL; break;
  951. case kKeyControlR: key = GLFW_KEY_RIGHT_CONTROL; break;
  952. case kKeyAltL: key = GLFW_KEY_LEFT_ALT; break;
  953. case kKeyAltR: key = GLFW_KEY_RIGHT_ALT; break;
  954. case kKeySuperL: key = GLFW_KEY_LEFT_SUPER; break;
  955. case kKeySuperR: key = GLFW_KEY_RIGHT_SUPER; break;
  956. case kKeyPad0: key = GLFW_KEY_KP_0; break;
  957. case kKeyPad1: key = GLFW_KEY_KP_1; break;
  958. case kKeyPad2: key = GLFW_KEY_KP_2; break;
  959. case kKeyPad3: key = GLFW_KEY_KP_3; break;
  960. case kKeyPad4: key = GLFW_KEY_KP_4; break;
  961. case kKeyPad5: key = GLFW_KEY_KP_5; break;
  962. case kKeyPad6: key = GLFW_KEY_KP_6; break;
  963. case kKeyPad7: key = GLFW_KEY_KP_7; break;
  964. case kKeyPad8: key = GLFW_KEY_KP_8; break;
  965. case kKeyPad9: key = GLFW_KEY_KP_9; break;
  966. case kKeyPadEnter: key = GLFW_KEY_KP_ENTER; break;
  967. /* undefined in glfw
  968. case kKeyPadPageUp:
  969. case kKeyPadPageDown:
  970. case kKeyPadEnd:
  971. case kKeyPadHome:
  972. case kKeyPadLeft:
  973. case kKeyPadUp:
  974. case kKeyPadRight:
  975. case kKeyPadDown:
  976. case kKeyPadClear:
  977. case kKeyPadInsert:
  978. case kKeyPadDelete:
  979. */
  980. case kKeyPadEqual: key = GLFW_KEY_KP_EQUAL; break;
  981. case kKeyPadMultiply: key = GLFW_KEY_KP_MULTIPLY; break;
  982. case kKeyPadAdd: key = GLFW_KEY_KP_ADD; break;
  983. /* undefined in glfw
  984. case kKeyPadSeparator:
  985. */
  986. case kKeyPadSubtract: key = GLFW_KEY_KP_SUBTRACT; break;
  987. case kKeyPadDecimal: key = GLFW_KEY_KP_DECIMAL; break;
  988. case kKeyPadDivide: key = GLFW_KEY_KP_DIVIDE; break;
  989. default:
  990. // glfw expects uppercase
  991. if (ev.key >= 'a' && ev.key <= 'z')
  992. key = ev.key - ('a' - 'A');
  993. else
  994. key = ev.key;
  995. break;
  996. }
  997. const ScopedContext sc(this, mods);
  998. return context->event->handleKey(lastMousePos, key, ev.keycode, action, mods);
  999. }
  1000. void onResize(const ResizeEvent& ev) override
  1001. {
  1002. UI::onResize(ev);
  1003. if (context->window != nullptr)
  1004. WindowSetInternalSize(context->window, rack::math::Vec(ev.size.getWidth(), ev.size.getHeight()));
  1005. const double scaleFactor = getScaleFactor();
  1006. const int width = static_cast<int>(ev.size.getWidth() / scaleFactor + 0.5);
  1007. const int height = static_cast<int>(ev.size.getHeight() / scaleFactor + 0.5);
  1008. char sizeString[64] = {};
  1009. std::snprintf(sizeString, sizeof(sizeString) - 1, "%d:%d", width, height);
  1010. setState("windowSize", sizeString);
  1011. if (rack::isStandalone())
  1012. rack::settings::windowSize = rack::math::Vec(width, height);
  1013. }
  1014. void uiFocus(const bool focus, CrossingMode) override
  1015. {
  1016. #ifdef DPF_RUNTIME_TESTING
  1017. if (inSelfTest) return;
  1018. #endif
  1019. if (!focus)
  1020. {
  1021. const ScopedContext sc(this, 0);
  1022. context->event->handleLeave();
  1023. }
  1024. }
  1025. void uiFileBrowserSelected(const char* const filename) override
  1026. {
  1027. if (filename == nullptr)
  1028. return;
  1029. rack::contextSet(context);
  1030. WindowParametersRestore(context->window);
  1031. std::string sfilename = filename;
  1032. if (saving)
  1033. {
  1034. const bool uncompressed = savingUncompressed;
  1035. savingUncompressed = false;
  1036. if (rack::system::getExtension(sfilename) != ".vcv")
  1037. sfilename += ".vcv";
  1038. try {
  1039. if (uncompressed)
  1040. {
  1041. context->engine->prepareSave();
  1042. if (json_t* const rootJ = context->patch->toJson())
  1043. {
  1044. if (FILE* const file = std::fopen(sfilename.c_str(), "w"))
  1045. {
  1046. json_dumpf(rootJ, file, JSON_INDENT(2));
  1047. std::fclose(file);
  1048. }
  1049. json_decref(rootJ);
  1050. }
  1051. }
  1052. else
  1053. {
  1054. context->patch->save(sfilename);
  1055. }
  1056. }
  1057. catch (rack::Exception& e) {
  1058. std::string message = rack::string::f("Could not save patch: %s", e.what());
  1059. asyncDialog::create(message.c_str());
  1060. return;
  1061. }
  1062. }
  1063. else
  1064. {
  1065. try {
  1066. context->patch->load(sfilename);
  1067. } catch (rack::Exception& e) {
  1068. std::string message = rack::string::f("Could not load patch: %s", e.what());
  1069. asyncDialog::create(message.c_str());
  1070. return;
  1071. }
  1072. }
  1073. context->patch->path = sfilename;
  1074. context->patch->pushRecentPath(sfilename);
  1075. context->history->setSaved();
  1076. #ifdef DISTRHO_OS_WASM
  1077. rack::syncfs();
  1078. #else
  1079. rack::settings::save();
  1080. #endif
  1081. }
  1082. private:
  1083. /**
  1084. Set our UI class as non-copyable and add a leak detector just in case.
  1085. */
  1086. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CardinalUI)
  1087. };
  1088. /* ------------------------------------------------------------------------------------------------------------
  1089. * UI entry point, called by DPF to create a new UI instance. */
  1090. UI* createUI()
  1091. {
  1092. return new CardinalUI();
  1093. }
  1094. // -----------------------------------------------------------------------------------------------------------
  1095. END_NAMESPACE_DISTRHO