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.

187 lines
5.2KB

  1. /*
  2. * Carla VST3 Plugin
  3. * Copyright (C) 2014-2021 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 "CarlaPluginInternal.hpp"
  18. #include "CarlaEngine.hpp"
  19. #include "AppConfig.h"
  20. #if defined(USING_JUCE) && JUCE_PLUGINHOST_VST3
  21. # define USE_JUCE_FOR_VST3
  22. #endif
  23. #include "CarlaVst3Utils.hpp"
  24. #include "CarlaPluginUI.hpp"
  25. CARLA_BACKEND_START_NAMESPACE
  26. // --------------------------------------------------------------------------------------------------------------------
  27. class CarlaPluginVST3 : public CarlaPlugin,
  28. private CarlaPluginUI::Callback
  29. {
  30. public:
  31. CarlaPluginVST3(CarlaEngine* const engine, const uint id)
  32. : CarlaPlugin(engine, id),
  33. fUI()
  34. {
  35. carla_debug("CarlaPluginVST3::CarlaPluginVST3(%p, %i)", engine, id);
  36. }
  37. ~CarlaPluginVST3() override
  38. {
  39. carla_debug("CarlaPluginVST3::~CarlaPluginVST3()");
  40. pData->singleMutex.lock();
  41. pData->masterMutex.lock();
  42. if (pData->client != nullptr && pData->client->isActive())
  43. pData->client->deactivate(true);
  44. if (pData->active)
  45. {
  46. deactivate();
  47. pData->active = false;
  48. }
  49. }
  50. // -------------------------------------------------------------------
  51. // Information (base)
  52. PluginType getType() const noexcept override
  53. {
  54. return PLUGIN_VST3;
  55. }
  56. // -------------------------------------------------------------------
  57. // Information (count)
  58. // nothing
  59. // -------------------------------------------------------------------
  60. // Information (per-plugin data)
  61. // -------------------------------------------------------------------
  62. // Set data (state)
  63. // nothing
  64. // -------------------------------------------------------------------
  65. // Set data (internal stuff)
  66. // -------------------------------------------------------------------
  67. // Set data (plugin-specific stuff)
  68. // -------------------------------------------------------------------
  69. // Set ui stuff
  70. // -------------------------------------------------------------------
  71. // Plugin state
  72. // -------------------------------------------------------------------
  73. // Plugin processing
  74. // -------------------------------------------------------------------
  75. // Plugin buffers
  76. // -------------------------------------------------------------------
  77. // Post-poned UI Stuff
  78. // nothing
  79. // -------------------------------------------------------------------
  80. protected:
  81. void handlePluginUIClosed() override
  82. {
  83. // CARLA_SAFE_ASSERT_RETURN(fUI.window != nullptr,);
  84. carla_debug("CarlaPluginVST3::handlePluginUIClosed()");
  85. showCustomUI(false);
  86. pData->engine->callback(true, true,
  87. ENGINE_CALLBACK_UI_STATE_CHANGED,
  88. pData->id,
  89. 0,
  90. 0, 0, 0.0f, nullptr);
  91. }
  92. void handlePluginUIResized(const uint width, const uint height) override
  93. {
  94. // CARLA_SAFE_ASSERT_RETURN(fUI.window != nullptr,);
  95. carla_debug("CarlaPluginVST3::handlePluginUIResized(%u, %u)", width, height);
  96. return; // unused
  97. (void)width; (void)height;
  98. }
  99. private:
  100. struct UI {
  101. bool isEmbed;
  102. bool isOpen;
  103. bool isVisible;
  104. CarlaPluginUI* window;
  105. UI() noexcept
  106. : isEmbed(false),
  107. isOpen(false),
  108. isVisible(false),
  109. window(nullptr) {}
  110. ~UI()
  111. {
  112. CARLA_ASSERT(isEmbed || ! isVisible);
  113. if (window != nullptr)
  114. {
  115. delete window;
  116. window = nullptr;
  117. }
  118. }
  119. CARLA_DECLARE_NON_COPY_STRUCT(UI);
  120. } fUI;
  121. };
  122. // --------------------------------------------------------------------------------------------------------------------
  123. CarlaPluginPtr CarlaPlugin::newVST3(const Initializer& init)
  124. {
  125. carla_debug("CarlaPlugin::newVST3({%p, \"%s\", \"%s\", " P_INT64 "})",
  126. init.engine, init.filename, init.name, init.uniqueId);
  127. #ifdef USE_JUCE_FOR_VST3
  128. if (std::getenv("CARLA_DO_NOT_USE_JUCE_FOR_VST3") == nullptr)
  129. return newJuce(init, "VST3");
  130. #endif
  131. init.engine->setLastError("VST3 support not available");
  132. return nullptr;
  133. /*
  134. std::shared_ptr<CarlaPluginVST2> plugin(new CarlaPluginVST2(init.engine, init.id));
  135. if (! plugin->init(plugin, init.filename, init.name, init.uniqueId, init.options))
  136. return nullptr;
  137. return plugin;
  138. */
  139. }
  140. // -------------------------------------------------------------------------------------------------------------------
  141. CARLA_BACKEND_END_NAMESPACE