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.

156 lines
3.6KB

  1. /*
  2. * Carla Plugin bridge code
  3. * Copyright (C) 2012 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 COPYING file
  16. */
  17. #include "carla_bridge_client.hpp"
  18. #include "carla_bridge_toolkit.hpp"
  19. #include "carla_plugin.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. qDebug("CarlaBridgeToolkitPlugin::CarlaBridgeToolkitPlugin(%p, \"%s\")", client, uiTitle);
  32. app = nullptr;
  33. gui = nullptr;
  34. m_uiQuit = false;
  35. init();
  36. }
  37. ~CarlaBridgeToolkitPlugin()
  38. {
  39. qDebug("CarlaBridgeToolkitPlugin::~CarlaBridgeToolkitPlugin()");
  40. CARLA_ASSERT(! app);
  41. CARLA_ASSERT(! gui);
  42. }
  43. void init()
  44. {
  45. qDebug("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. qDebug("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. qDebug("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. qDebug("CarlaBridgeToolkitPlugin::show()");
  92. CARLA_ASSERT(gui);
  93. if (gui && m_uiShow)
  94. gui->setVisible(true);
  95. }
  96. void hide()
  97. {
  98. qDebug("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. qDebug("CarlaBridgeToolkitPlugin::resize(%i, %i)", width, height);
  106. CARLA_ASSERT(gui);
  107. if (gui)
  108. gui->setNewSize(width, height);
  109. }
  110. protected:
  111. QApplication* app;
  112. CarlaBackend::CarlaPluginGUI* gui;
  113. void guiClosedCallback();
  114. private:
  115. bool m_uiQuit;
  116. };
  117. // -------------------------------------------------------------------------
  118. CarlaBridgeToolkit* CarlaBridgeToolkit::createNew(CarlaBridgeClient* const client, const char* const uiTitle)
  119. {
  120. return new CarlaBridgeToolkitPlugin(client, uiTitle);
  121. }
  122. CARLA_BRIDGE_END_NAMESPACE