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.

154 lines
3.7KB

  1. /*
  2. * Carla Bridge Toolkit, Plugin version
  3. * Copyright (C) 2011-2013 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 GPL.txt file
  16. */
  17. #include "CarlaBridgeClient.hpp"
  18. #include "CarlaBridgeToolkit.hpp"
  19. #include "CarlaPlugin.hpp"
  20. CARLA_BRIDGE_START_NAMESPACE
  21. static int qargc = 0;
  22. static char* qargv[0] = {};
  23. // -------------------------------------------------------------------------
  24. class CarlaBridgeToolkitPlugin : public CarlaBridgeToolkit/*,
  25. public CarlaBackend::CarlaPluginGUI::Callback*/
  26. {
  27. public:
  28. CarlaBridgeToolkitPlugin(CarlaBridgeClient* const client, const char* const uiTitle)
  29. : CarlaBridgeToolkit(client, uiTitle)
  30. {
  31. carla_debug("CarlaBridgeToolkitPlugin::CarlaBridgeToolkitPlugin(%p, \"%s\")", client, uiTitle);
  32. app = nullptr;
  33. gui = nullptr;
  34. m_uiQuit = false;
  35. init();
  36. }
  37. ~CarlaBridgeToolkitPlugin()
  38. {
  39. carla_debug("CarlaBridgeToolkitPlugin::~CarlaBridgeToolkitPlugin()");
  40. CARLA_ASSERT(! app);
  41. CARLA_ASSERT(! gui);
  42. }
  43. void init()
  44. {
  45. carla_debug("CarlaBridgeToolkitPlugin::init()");
  46. CARLA_ASSERT(! app);
  47. CARLA_ASSERT(! gui);
  48. app = new QApplication(qargc, qargv);
  49. gui = new CarlaBackend::CarlaPluginGUI(nullptr, this);
  50. }
  51. void exec(const bool showGui)
  52. {
  53. carla_debug("CarlaBridgeToolkitPlugin::exec(%s)", bool2str(showGui));
  54. CARLA_ASSERT(app);
  55. CARLA_ASSERT(gui);
  56. CARLA_ASSERT(client);
  57. if (showGui)
  58. {
  59. show();
  60. }
  61. else
  62. {
  63. app->setQuitOnLastWindowClosed(false);
  64. client->sendOscUpdate();
  65. client->sendOscBridgeUpdate();
  66. }
  67. m_uiQuit = showGui;
  68. // Main loop
  69. app->exec();
  70. }
  71. void quit()
  72. {
  73. carla_debug("CarlaBridgeToolkitPlugin::quit()");
  74. CARLA_ASSERT(app);
  75. if (gui)
  76. {
  77. gui->close();
  78. delete gui;
  79. gui = nullptr;
  80. }
  81. if (app)
  82. {
  83. if (! app->closingDown())
  84. app->quit();
  85. delete app;
  86. app = nullptr;
  87. }
  88. }
  89. void show()
  90. {
  91. carla_debug("CarlaBridgeToolkitPlugin::show()");
  92. CARLA_ASSERT(gui);
  93. if (gui && m_uiShow)
  94. gui->setVisible(true);
  95. }
  96. void hide()
  97. {
  98. carla_debug("CarlaBridgeToolkitPlugin::hide()");
  99. CARLA_ASSERT(gui);
  100. if (gui && m_uiShow)
  101. gui->setVisible(false);
  102. }
  103. void resize(const int width, const int height)
  104. {
  105. carla_debug("CarlaBridgeToolkitPlugin::resize(%i, %i)", width, height);
  106. CARLA_ASSERT(gui);
  107. if (gui)
  108. gui->setNewSize(width, height);
  109. }
  110. private:
  111. QApplication* fApp;
  112. bool fQuit;
  113. //CarlaBackend::CarlaPluginGUI* gui;
  114. //void guiClosedCallback();
  115. };
  116. // -------------------------------------------------------------------------
  117. CarlaBridgeToolkit* CarlaBridgeToolkit::createNew(CarlaBridgeClient* const client, const char* const uiTitle)
  118. {
  119. return new CarlaBridgeToolkitPlugin(client, uiTitle);
  120. }
  121. CARLA_BRIDGE_END_NAMESPACE