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.

218 lines
5.9KB

  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);
  58. fUI->setTransientWinId(options.transientWindowId);
  59. return true;
  60. }
  61. void exec(const bool showUI) override
  62. {
  63. CARLA_SAFE_ASSERT_RETURN(ui != nullptr,);
  64. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  65. carla_debug("CarlaBridgeToolkitPlugin::exec(%s)", bool2str(showUI));
  66. if (const char* const winIdStr = std::getenv("ENGINE_OPTION_FRONTEND_WIN_ID"))
  67. {
  68. if (const long long winId = std::strtoll(winIdStr, nullptr, 16))
  69. fUI->setTransientWinId(static_cast<uintptr_t>(winId));
  70. }
  71. if (showUI)
  72. fUI->show();
  73. fIdling = true;
  74. for (; fIdling;)
  75. {
  76. fUI->idle();
  77. ui->idlePipe();
  78. ui->idleUI();
  79. //if (! kClient->oscIdle())
  80. // break;
  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_SAFE_ASSERT_RETURN(fUI != nullptr,);
  92. carla_debug("CarlaBridgeToolkitPlugin::quit()");
  93. fIdling = false;
  94. delete fUI;
  95. fUI = nullptr;
  96. }
  97. void show() override
  98. {
  99. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  100. carla_debug("CarlaBridgeToolkitPlugin::show()");
  101. fUI->show();
  102. }
  103. void focus() override
  104. {
  105. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  106. carla_debug("CarlaBridgeToolkitPlugin::focus()");
  107. fUI->focus();
  108. }
  109. void hide() override
  110. {
  111. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  112. carla_debug("CarlaBridgeToolkitPlugin::hide()");
  113. fUI->hide();
  114. }
  115. void setSize(const uint width, const uint height) override
  116. {
  117. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  118. CARLA_SAFE_ASSERT_RETURN(width > 0,);
  119. CARLA_SAFE_ASSERT_RETURN(height > 0,);
  120. carla_debug("CarlaBridgeToolkitPlugin::resize(%i, %i)", width, height);
  121. fUI->setSize(width, height, false);
  122. }
  123. void setTitle(const char* const title) override
  124. {
  125. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  126. carla_debug("CarlaBridgeToolkitPlugin::setTitle(\"%s\")", title);
  127. fUI->setTitle(title);
  128. }
  129. void* getContainerId() const override
  130. {
  131. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr, nullptr);
  132. return fUI->getPtr();
  133. }
  134. #ifdef HAVE_X11
  135. void* getContainerId2() const override
  136. {
  137. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr, nullptr);
  138. return fUI->getDisplay();
  139. }
  140. #endif
  141. // ---------------------------------------------------------------------
  142. protected:
  143. void handlePluginUIClosed() override
  144. {
  145. fIdling = false;
  146. }
  147. void handlePluginUIResized(uint,uint) override
  148. {
  149. }
  150. // ---------------------------------------------------------------------
  151. private:
  152. CarlaPluginUI* fUI;
  153. bool fIdling;
  154. #if defined(CARLA_OS_WIN) || defined(CARLA_OS_MAC)
  155. const ScopedJuceInitialiser_GUI kJuceInit;
  156. #endif
  157. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeToolkitPlugin)
  158. };
  159. // -------------------------------------------------------------------------
  160. CarlaBridgeToolkit* CarlaBridgeToolkit::createNew(CarlaBridgeUI* const ui)
  161. {
  162. return new CarlaBridgeToolkitPlugin(ui);
  163. }
  164. // -------------------------------------------------------------------------
  165. CARLA_BRIDGE_END_NAMESPACE
  166. #define CARLA_PLUGIN_UI_WITHOUT_JUCE_PROCESSORS
  167. #include "CarlaPluginUI.cpp"
  168. // -------------------------------------------------------------------------