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.1KB

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