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.

174 lines
4.7KB

  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. CARLA_BRIDGE_START_NAMESPACE
  21. // -------------------------------------------------------------------------
  22. class CarlaBridgeToolkitPlugin : public CarlaBridgeToolkit,
  23. private CarlaPluginUI::CloseCallback
  24. {
  25. public:
  26. CarlaBridgeToolkitPlugin(CarlaBridgeClient* const client, const char* const windowTitle)
  27. : CarlaBridgeToolkit(client, windowTitle),
  28. fUI(nullptr),
  29. fIdling(false),
  30. leakDetector_CarlaBridgeToolkitPlugin()
  31. {
  32. carla_debug("CarlaBridgeToolkitPlugin::CarlaBridgeToolkitPlugin(%p, \"%s\")", client, windowTitle);
  33. }
  34. ~CarlaBridgeToolkitPlugin() override
  35. {
  36. CARLA_SAFE_ASSERT_RETURN(fUI == nullptr,);
  37. carla_debug("CarlaBridgeToolkitPlugin::~CarlaBridgeToolkitPlugin()");
  38. }
  39. void init() override
  40. {
  41. CARLA_SAFE_ASSERT_RETURN(fUI == nullptr,);
  42. carla_debug("CarlaBridgeToolkitPlugin::init()");
  43. #if defined(CARLA_OS_MAC) && defined(BRIDGE_COCOA)
  44. fUI = CarlaPluginUI::newCocoa(this, 0);
  45. #elif defined(CARLA_OS_WIN) && defined(BRIDGE_HWND)
  46. fUI = CarlaPluginUI::newWindows(this, 0);
  47. #elif defined(HAVE_X11) && defined(BRIDGE_X11)
  48. fUI = CarlaPluginUI::newX11(this, 0, false); // TODO: check if UI is resizable
  49. #endif
  50. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  51. fUI->setTitle(kWindowTitle);
  52. }
  53. void exec(const bool showUI) override
  54. {
  55. CARLA_SAFE_ASSERT_RETURN(kClient != nullptr,);
  56. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  57. carla_debug("CarlaBridgeToolkitPlugin::exec(%s)", bool2str(showUI));
  58. if (showUI)
  59. fUI->show();
  60. fIdling = true;
  61. for (; fIdling;)
  62. {
  63. fUI->idle();
  64. kClient->uiIdle();
  65. if (! kClient->oscIdle())
  66. break;
  67. carla_msleep(20);
  68. }
  69. }
  70. void quit() override
  71. {
  72. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  73. carla_debug("CarlaBridgeToolkitPlugin::quit()");
  74. fIdling = false;
  75. delete fUI;
  76. fUI = nullptr;
  77. }
  78. void show() override
  79. {
  80. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  81. carla_debug("CarlaBridgeToolkitPlugin::show()");
  82. fUI->show();
  83. }
  84. void hide() override
  85. {
  86. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  87. carla_debug("CarlaBridgeToolkitPlugin::hide()");
  88. fUI->hide();
  89. }
  90. void resize(int width, int height) override
  91. {
  92. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr,);
  93. CARLA_SAFE_ASSERT_RETURN(width >= 0,);
  94. CARLA_SAFE_ASSERT_RETURN(height >= 0,);
  95. carla_debug("CarlaBridgeToolkitPlugin::resize(%i, %i)", width, height);
  96. fUI->setSize(static_cast<uint>(width), static_cast<uint>(height), false);
  97. }
  98. void* getContainerId() const override
  99. {
  100. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr, nullptr);
  101. return fUI->getPtr();
  102. }
  103. #ifdef HAVE_X11
  104. void* getContainerId2() const override
  105. {
  106. CARLA_SAFE_ASSERT_RETURN(fUI != nullptr, nullptr);
  107. return fUI->getDisplay();
  108. }
  109. #endif
  110. // ---------------------------------------------------------------------
  111. protected:
  112. void handlePluginUIClosed() override
  113. {
  114. fIdling = false;
  115. }
  116. void handlePluginUIResized(uint,uint) override
  117. {
  118. }
  119. // ---------------------------------------------------------------------
  120. private:
  121. CarlaPluginUI* fUI;
  122. bool fIdling;
  123. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeToolkitPlugin)
  124. };
  125. // -------------------------------------------------------------------------
  126. CarlaBridgeToolkit* CarlaBridgeToolkit::createNew(CarlaBridgeClient* const client, const char* const windowTitle)
  127. {
  128. return new CarlaBridgeToolkitPlugin(client, windowTitle);
  129. }
  130. // -------------------------------------------------------------------------
  131. CARLA_BRIDGE_END_NAMESPACE
  132. #include "CarlaPluginUI.cpp"
  133. // -------------------------------------------------------------------------