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.

196 lines
5.4KB

  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 "CarlaBridgeClient.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(CarlaBridgeClient* const client, const char* const windowTitle)
  32. : CarlaBridgeToolkit(client, windowTitle),
  33. fUI(nullptr),
  34. fIdling(false),
  35. leakDetector_CarlaBridgeToolkitPlugin()
  36. {
  37. carla_debug("CarlaBridgeToolkitPlugin::CarlaBridgeToolkitPlugin(%p, \"%s\")", client, windowTitle);
  38. }
  39. ~CarlaBridgeToolkitPlugin() override
  40. {
  41. CARLA_SAFE_ASSERT_RETURN(fUI == nullptr,);
  42. carla_debug("CarlaBridgeToolkitPlugin::~CarlaBridgeToolkitPlugin()");
  43. }
  44. void init() override
  45. {
  46. CARLA_SAFE_ASSERT_RETURN(fUI == nullptr,);
  47. carla_debug("CarlaBridgeToolkitPlugin::init()");
  48. #if defined(CARLA_OS_MAC) && defined(BRIDGE_COCOA)
  49. fUI = CarlaPluginUI::newCocoa(this, 0);
  50. #elif defined(CARLA_OS_WIN) && defined(BRIDGE_HWND)
  51. fUI = CarlaPluginUI::newWindows(this, 0);
  52. #elif defined(HAVE_X11) && defined(BRIDGE_X11)
  53. fUI = CarlaPluginUI::newX11(this, 0, false); // TODO: check if UI is resizable
  54. #endif
  55. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  56. fUI->setTitle(kWindowTitle);
  57. }
  58. void exec(const bool showUI) override
  59. {
  60. CARLA_SAFE_ASSERT_RETURN(kClient != nullptr,);
  61. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  62. carla_debug("CarlaBridgeToolkitPlugin::exec(%s)", bool2str(showUI));
  63. if (const char* const winIdStr = std::getenv("ENGINE_OPTION_FRONTEND_WIN_ID"))
  64. {
  65. if (const long long winId = std::strtoll(winIdStr, nullptr, 16))
  66. fUI->setTransientWinId(static_cast<uintptr_t>(winId));
  67. }
  68. if (showUI)
  69. fUI->show();
  70. fIdling = true;
  71. for (; fIdling;)
  72. {
  73. fUI->idle();
  74. kClient->uiIdle();
  75. if (! kClient->oscIdle())
  76. break;
  77. #if defined(CARLA_OS_WIN) || defined(CARLA_OS_MAC)
  78. if (MessageManager* const msgMgr = MessageManager::getInstance())
  79. msgMgr->runDispatchLoopUntil(20);
  80. #else
  81. carla_msleep(20);
  82. #endif
  83. }
  84. }
  85. void quit() override
  86. {
  87. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  88. carla_debug("CarlaBridgeToolkitPlugin::quit()");
  89. fIdling = false;
  90. delete fUI;
  91. fUI = nullptr;
  92. }
  93. void show() override
  94. {
  95. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  96. carla_debug("CarlaBridgeToolkitPlugin::show()");
  97. fUI->show();
  98. }
  99. void hide() override
  100. {
  101. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  102. carla_debug("CarlaBridgeToolkitPlugin::hide()");
  103. fUI->hide();
  104. }
  105. void resize(int width, int height) override
  106. {
  107. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  108. CARLA_SAFE_ASSERT_RETURN(width >= 0,);
  109. CARLA_SAFE_ASSERT_RETURN(height >= 0,);
  110. carla_debug("CarlaBridgeToolkitPlugin::resize(%i, %i)", width, height);
  111. fUI->setSize(static_cast<uint>(width), static_cast<uint>(height), false);
  112. }
  113. void* getContainerId() const override
  114. {
  115. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr, nullptr);
  116. return fUI->getPtr();
  117. }
  118. #ifdef HAVE_X11
  119. void* getContainerId2() const override
  120. {
  121. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr, nullptr);
  122. return fUI->getDisplay();
  123. }
  124. #endif
  125. // ---------------------------------------------------------------------
  126. protected:
  127. void handlePluginUIClosed() override
  128. {
  129. fIdling = false;
  130. }
  131. void handlePluginUIResized(uint,uint) override
  132. {
  133. }
  134. // ---------------------------------------------------------------------
  135. private:
  136. CarlaPluginUI* fUI;
  137. bool fIdling;
  138. #if defined(CARLA_OS_WIN) || defined(CARLA_OS_MAC)
  139. const ScopedJuceInitialiser_GUI kJuceInit;
  140. #endif
  141. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeToolkitPlugin)
  142. };
  143. // -------------------------------------------------------------------------
  144. CarlaBridgeToolkit* CarlaBridgeToolkit::createNew(CarlaBridgeClient* const client, const char* const windowTitle)
  145. {
  146. return new CarlaBridgeToolkitPlugin(client, windowTitle);
  147. }
  148. // -------------------------------------------------------------------------
  149. CARLA_BRIDGE_END_NAMESPACE
  150. #define CARLA_PLUGIN_UI_WITHOUT_JUCE_PROCESSORS
  151. #include "CarlaPluginUI.cpp"
  152. // -------------------------------------------------------------------------