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.

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