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 5.2KB

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
10 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 (showUI)
  64. fUI->show();
  65. fIdling = true;
  66. for (; fIdling;)
  67. {
  68. fUI->idle();
  69. kClient->uiIdle();
  70. if (! kClient->oscIdle())
  71. break;
  72. #if defined(CARLA_OS_WIN) || defined(CARLA_OS_MAC)
  73. if (MessageManager* const msgMgr = MessageManager::getInstance())
  74. msgMgr->runDispatchLoopUntil(20);
  75. #else
  76. carla_msleep(20);
  77. #endif
  78. }
  79. }
  80. void quit() override
  81. {
  82. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  83. carla_debug("CarlaBridgeToolkitPlugin::quit()");
  84. fIdling = false;
  85. delete fUI;
  86. fUI = nullptr;
  87. }
  88. void show() override
  89. {
  90. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  91. carla_debug("CarlaBridgeToolkitPlugin::show()");
  92. fUI->show();
  93. }
  94. void hide() override
  95. {
  96. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  97. carla_debug("CarlaBridgeToolkitPlugin::hide()");
  98. fUI->hide();
  99. }
  100. void resize(int width, int height) override
  101. {
  102. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  103. CARLA_SAFE_ASSERT_RETURN(width >= 0,);
  104. CARLA_SAFE_ASSERT_RETURN(height >= 0,);
  105. carla_debug("CarlaBridgeToolkitPlugin::resize(%i, %i)", width, height);
  106. fUI->setSize(static_cast<uint>(width), static_cast<uint>(height), false);
  107. }
  108. void* getContainerId() const override
  109. {
  110. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr, nullptr);
  111. return fUI->getPtr();
  112. }
  113. #ifdef HAVE_X11
  114. void* getContainerId2() const override
  115. {
  116. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr, nullptr);
  117. return fUI->getDisplay();
  118. }
  119. #endif
  120. // ---------------------------------------------------------------------
  121. protected:
  122. void handlePluginUIClosed() override
  123. {
  124. fIdling = false;
  125. }
  126. void handlePluginUIResized(uint,uint) override
  127. {
  128. }
  129. // ---------------------------------------------------------------------
  130. private:
  131. CarlaPluginUI* fUI;
  132. bool fIdling;
  133. #if defined(CARLA_OS_WIN) || defined(CARLA_OS_MAC)
  134. const ScopedJuceInitialiser_GUI kJuceInit;
  135. #endif
  136. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeToolkitPlugin)
  137. };
  138. // -------------------------------------------------------------------------
  139. CarlaBridgeToolkit* CarlaBridgeToolkit::createNew(CarlaBridgeClient* const client, const char* const windowTitle)
  140. {
  141. return new CarlaBridgeToolkitPlugin(client, windowTitle);
  142. }
  143. // -------------------------------------------------------------------------
  144. CARLA_BRIDGE_END_NAMESPACE
  145. #define CARLA_PLUGIN_UI_WITHOUT_JUCE_PROCESSORS
  146. #include "CarlaPluginUI.cpp"
  147. // -------------------------------------------------------------------------