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.

205 lines
5.4KB

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