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.

92 lines
2.6KB

  1. /*
  2. * DISTRHO Cardinal Plugin
  3. * Copyright (C) 2021-2022 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 "RemoteUI.hpp"
  18. // #include <asset.hpp>
  19. // #include <random.hpp>
  20. #include <patch.hpp>
  21. #include <settings.hpp>
  22. #include <system.hpp>
  23. #include <app/Scene.hpp>
  24. #include <engine/Engine.hpp>
  25. CardinalRemoteUI::CardinalRemoteUI(Window& window, const std::string& templatePath)
  26. : NanoTopLevelWidget(window),
  27. context(nullptr)
  28. {
  29. // create unique temporary path for this instance
  30. try {
  31. char uidBuf[24];
  32. const std::string tmp = rack::system::getTempDirectory();
  33. for (int i=1;; ++i)
  34. {
  35. std::snprintf(uidBuf, sizeof(uidBuf), "CardinalRemote.%04d", i);
  36. const std::string trypath = rack::system::join(tmp, uidBuf);
  37. if (! rack::system::exists(trypath))
  38. {
  39. if (rack::system::createDirectories(trypath))
  40. autosavePath = trypath;
  41. break;
  42. }
  43. }
  44. } DISTRHO_SAFE_EXCEPTION("create unique temporary path");
  45. rack::contextSet(&context);
  46. context.bufferSize = 512;
  47. rack::settings::sampleRate = context.sampleRate = 48000;
  48. context.engine = new rack::engine::Engine;
  49. context.engine->setSampleRate(context.sampleRate);
  50. context.history = new rack::history::State;
  51. context.patch = new rack::patch::Manager;
  52. context.patch->autosavePath = autosavePath;
  53. context.patch->templatePath = templatePath;
  54. context.event = new rack::widget::EventState;
  55. context.scene = new rack::app::Scene;
  56. context.event->rootWidget = context.scene;
  57. context.window = new rack::window::Window;
  58. context.patch->loadTemplate();
  59. context.scene->rackScroll->reset();
  60. context.nativeWindowId = getWindow().getNativeWindowHandle();
  61. }
  62. CardinalRemoteUI::~CardinalRemoteUI()
  63. {
  64. rack::contextSet(&context);
  65. context.nativeWindowId = 0;
  66. context.patch->clear();
  67. if (! autosavePath.empty())
  68. rack::system::removeRecursively(autosavePath);
  69. }
  70. void CardinalRemoteUI::onNanoDisplay()
  71. {
  72. rack::contextSet(&context);
  73. context.window->step();
  74. }