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.

CarlaBridgeToolkitPlugin.cpp 6.0KB

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