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.

138 lines
3.7KB

  1. /*
  2. * DISTRHO CVCRack Plugin
  3. * Copyright (C) 2021 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <app/common.hpp>
  17. #include <app/Scene.hpp>
  18. #include <context.hpp>
  19. #include <engine/Engine.hpp>
  20. #include <patch.hpp>
  21. #include <ui/common.hpp>
  22. #include <window/Window.hpp>
  23. #include "DistrhoUI.hpp"
  24. GLFWAPI const char* glfwGetClipboardString(GLFWwindow* window) { return nullptr; }
  25. GLFWAPI void glfwSetClipboardString(GLFWwindow* window, const char*) {}
  26. GLFWAPI const char* glfwGetKeyName(int key, int scancode) { return nullptr; }
  27. GLFWAPI int glfwGetKeyScancode(int key) { return 0; }
  28. namespace rack {
  29. namespace window {
  30. DISTRHO_NAMESPACE::UI* lastUI = nullptr;
  31. }
  32. }
  33. START_NAMESPACE_DISTRHO
  34. // -----------------------------------------------------------------------------------------------------------
  35. struct Initializer {
  36. Initializer()
  37. {
  38. using namespace rack;
  39. ui::init();
  40. window::init();
  41. }
  42. ~Initializer()
  43. {
  44. using namespace rack;
  45. window::destroy();
  46. ui::destroy();
  47. }
  48. };
  49. static Initializer& getInitializerInstance()
  50. {
  51. static Initializer init;
  52. return init;
  53. }
  54. class CVCRackUI : public UI
  55. {
  56. public:
  57. CVCRackUI()
  58. : UI(1280, 720)
  59. {
  60. using namespace rack;
  61. // Initialize context
  62. INFO("Initializing context");
  63. window::lastUI = this;
  64. contextSet(new Context);
  65. APP->engine = new engine::Engine;
  66. APP->history = new history::State;
  67. APP->event = new widget::EventState;
  68. APP->scene = new app::Scene;
  69. APP->event->rootWidget = APP->scene;
  70. APP->patch = new patch::Manager;
  71. /*if (!settings::headless)*/ {
  72. APP->window = new window::Window;
  73. }
  74. window::lastUI = nullptr;
  75. APP->engine->startFallbackThread();
  76. }
  77. ~CVCRackUI() override
  78. {
  79. using namespace rack;
  80. delete APP;
  81. contextSet(NULL);
  82. }
  83. void onNanoDisplay() override
  84. {
  85. APP->window->step();
  86. }
  87. protected:
  88. /* --------------------------------------------------------------------------------------------------------
  89. * DSP/Plugin Callbacks */
  90. /**
  91. A parameter has changed on the plugin side.
  92. This is called by the host to inform the UI about parameter changes.
  93. */
  94. void parameterChanged(uint32_t index, float value) override
  95. {
  96. }
  97. // -------------------------------------------------------------------------------------------------------
  98. private:
  99. /**
  100. Set our UI class as non-copyable and add a leak detector just in case.
  101. */
  102. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CVCRackUI)
  103. };
  104. /* ------------------------------------------------------------------------------------------------------------
  105. * UI entry point, called by DPF to create a new UI instance. */
  106. UI* createUI()
  107. {
  108. getInitializerInstance();
  109. return new CVCRackUI();
  110. }
  111. // -----------------------------------------------------------------------------------------------------------
  112. END_NAMESPACE_DISTRHO