Audio plugin host https://kx.studio/carla
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.

223 lines
6.0KB

  1. /*
  2. * Carla Bridge Toolkit, Plugin version
  3. * Copyright (C) 2014 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 doc/GPL.txt file.
  16. */
  17. #include "CarlaBridgeUI.hpp"
  18. #include "CarlaBridgeToolkit.hpp"
  19. #include "CarlaPluginUI.hpp"
  20. #if defined(CARLA_OS_WIN) || defined(CARLA_OS_MAC)
  21. # include "juce_events.h"
  22. using juce::MessageManager;
  23. using juce::ScopedJuceInitialiser_GUI;
  24. #endif
  25. CARLA_BRIDGE_START_NAMESPACE
  26. // -------------------------------------------------------------------------
  27. class CarlaBridgeToolkitPlugin : public CarlaBridgeToolkit,
  28. private CarlaPluginUI::CloseCallback
  29. {
  30. public:
  31. CarlaBridgeToolkitPlugin(CarlaBridgeUI* const ui)
  32. : CarlaBridgeToolkit(ui),
  33. fUI(nullptr),
  34. fIdling(false),
  35. leakDetector_CarlaBridgeToolkitPlugin()
  36. {
  37. carla_debug("CarlaBridgeToolkitPlugin::CarlaBridgeToolkitPlugin(%p)", ui);
  38. }
  39. ~CarlaBridgeToolkitPlugin() override
  40. {
  41. CARLA_SAFE_ASSERT_RETURN(fUI == nullptr,);
  42. carla_debug("CarlaBridgeToolkitPlugin::~CarlaBridgeToolkitPlugin()");
  43. }
  44. bool init(const int /*argc*/, const char** /*argv[]*/) override
  45. {
  46. CARLA_SAFE_ASSERT_RETURN(fUI == nullptr, false);
  47. carla_debug("CarlaBridgeToolkitPlugin::init()");
  48. const CarlaBridgeUI::Options& options(ui->getOptions());
  49. #if defined(CARLA_OS_MAC) && defined(BRIDGE_COCOA)
  50. fUI = CarlaPluginUI::newCocoa(this, 0, options.isResizable);
  51. #elif defined(CARLA_OS_WIN) && defined(BRIDGE_HWND)
  52. fUI = CarlaPluginUI::newWindows(this, 0, options.isResizable);
  53. #elif defined(HAVE_X11) && defined(BRIDGE_X11)
  54. fUI = CarlaPluginUI::newX11(this, 0, options.isResizable);
  55. #endif
  56. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr, false);
  57. fUI->setTitle(options.windowTitle.buffer());
  58. if (options.transientWindowId != 0)
  59. fUI->setTransientWinId(options.transientWindowId);
  60. return true;
  61. }
  62. void exec(const bool showUI) override
  63. {
  64. CARLA_SAFE_ASSERT_RETURN(ui != nullptr,);
  65. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  66. carla_debug("CarlaBridgeToolkitPlugin::exec(%s)", bool2str(showUI));
  67. if (const char* const winIdStr = std::getenv("ENGINE_OPTION_FRONTEND_WIN_ID"))
  68. {
  69. if (const long long winId = std::strtoll(winIdStr, nullptr, 16))
  70. fUI->setTransientWinId(static_cast<uintptr_t>(winId));
  71. }
  72. if (showUI)
  73. fUI->show();
  74. fIdling = true;
  75. for (; fIdling;)
  76. {
  77. if (ui->isPipeRunning())
  78. ui->idlePipe();
  79. ui->idleUI();
  80. fUI->idle();
  81. #if defined(CARLA_OS_WIN) || defined(CARLA_OS_MAC)
  82. if (MessageManager* const msgMgr = MessageManager::getInstance())
  83. msgMgr->runDispatchLoopUntil(20);
  84. #else
  85. carla_msleep(20);
  86. #endif
  87. }
  88. }
  89. void quit() override
  90. {
  91. carla_debug("CarlaBridgeToolkitPlugin::quit()");
  92. fIdling = false;
  93. if (fUI != nullptr)
  94. {
  95. fUI->hide();
  96. delete fUI;
  97. fUI = nullptr;
  98. }
  99. }
  100. void show() override
  101. {
  102. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  103. carla_debug("CarlaBridgeToolkitPlugin::show()");
  104. fUI->show();
  105. }
  106. void focus() override
  107. {
  108. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  109. carla_debug("CarlaBridgeToolkitPlugin::focus()");
  110. fUI->focus();
  111. }
  112. void hide() override
  113. {
  114. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  115. carla_debug("CarlaBridgeToolkitPlugin::hide()");
  116. fUI->hide();
  117. }
  118. void setSize(const uint width, const uint height) override
  119. {
  120. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  121. CARLA_SAFE_ASSERT_RETURN(width > 0,);
  122. CARLA_SAFE_ASSERT_RETURN(height > 0,);
  123. carla_debug("CarlaBridgeToolkitPlugin::resize(%i, %i)", width, height);
  124. fUI->setSize(width, height, false);
  125. }
  126. void setTitle(const char* const title) override
  127. {
  128. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  129. carla_debug("CarlaBridgeToolkitPlugin::setTitle(\"%s\")", title);
  130. fUI->setTitle(title);
  131. }
  132. void* getContainerId() const override
  133. {
  134. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr, nullptr);
  135. return fUI->getPtr();
  136. }
  137. #ifdef HAVE_X11
  138. void* getContainerId2() const override
  139. {
  140. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr, nullptr);
  141. return fUI->getDisplay();
  142. }
  143. #endif
  144. // ---------------------------------------------------------------------
  145. protected:
  146. void handlePluginUIClosed() override
  147. {
  148. fIdling = false;
  149. }
  150. void handlePluginUIResized(uint,uint) override
  151. {
  152. }
  153. // ---------------------------------------------------------------------
  154. private:
  155. CarlaPluginUI* fUI;
  156. bool fIdling;
  157. #if defined(CARLA_OS_WIN) || defined(CARLA_OS_MAC)
  158. const ScopedJuceInitialiser_GUI kJuceInit;
  159. #endif
  160. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeToolkitPlugin)
  161. };
  162. // -------------------------------------------------------------------------
  163. CarlaBridgeToolkit* CarlaBridgeToolkit::createNew(CarlaBridgeUI* const ui)
  164. {
  165. return new CarlaBridgeToolkitPlugin(ui);
  166. }
  167. // -------------------------------------------------------------------------
  168. CARLA_BRIDGE_END_NAMESPACE
  169. #define CARLA_PLUGIN_UI_WITHOUT_JUCE_PROCESSORS
  170. #include "CarlaPluginUI.cpp"
  171. // -------------------------------------------------------------------------