From 0c93fa1eead44e446d12d0be924fa654285cf0f1 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 19 Dec 2021 20:07:50 +0000 Subject: [PATCH] Add stubs for custom vst3 hosting Signed-off-by: falkTX --- source/backend/plugin/CarlaPluginVST2.cpp | 6 +- source/backend/plugin/CarlaPluginVST3.cpp | 162 ++++++++++++++++++++-- 2 files changed, 157 insertions(+), 11 deletions(-) diff --git a/source/backend/plugin/CarlaPluginVST2.cpp b/source/backend/plugin/CarlaPluginVST2.cpp index 141ff00fe..fd6c73765 100644 --- a/source/backend/plugin/CarlaPluginVST2.cpp +++ b/source/backend/plugin/CarlaPluginVST2.cpp @@ -64,7 +64,7 @@ static const pthread_t kNullThread = {nullptr, 0}; static const pthread_t kNullThread = 0; #endif -// ----------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- class CarlaPluginVST2 : public CarlaPlugin, private CarlaPluginUI::Callback @@ -2967,7 +2967,7 @@ CarlaPluginVST2* CarlaPluginVST2::sLastCarlaPluginVST2 = nullptr; CARLA_BACKEND_END_NAMESPACE -// ------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- CARLA_BACKEND_START_NAMESPACE @@ -2989,6 +2989,6 @@ CarlaPluginPtr CarlaPlugin::newVST2(const Initializer& init) return plugin; } -// ------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- CARLA_BACKEND_END_NAMESPACE diff --git a/source/backend/plugin/CarlaPluginVST3.cpp b/source/backend/plugin/CarlaPluginVST3.cpp index ba7c85ec0..f2c2e9aad 100644 --- a/source/backend/plugin/CarlaPluginVST3.cpp +++ b/source/backend/plugin/CarlaPluginVST3.cpp @@ -1,6 +1,6 @@ /* * Carla VST3 Plugin - * Copyright (C) 2014-2020 Filipe Coelho + * Copyright (C) 2014-2021 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -15,25 +15,171 @@ * For a full copy of the GNU General Public License see the doc/GPL.txt file. */ -#include "CarlaPlugin.hpp" +#include "CarlaPluginInternal.hpp" #include "CarlaEngine.hpp" -#include "CarlaUtils.hpp" +#include "AppConfig.h" + +#if defined(USING_JUCE) && JUCE_PLUGINHOST_VST3 +# define USE_JUCE_FOR_VST3 +#endif + +#include "CarlaVst3Utils.hpp" + +#include "CarlaPluginUI.hpp" CARLA_BACKEND_START_NAMESPACE -// ------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- + +class CarlaPluginVST3 : public CarlaPlugin, + private CarlaPluginUI::Callback +{ +public: + CarlaPluginVST3(CarlaEngine* const engine, const uint id) + : CarlaPlugin(engine, id), + fUI() + { + carla_debug("CarlaPluginVST3::CarlaPluginVST3(%p, %i)", engine, id); + } + + ~CarlaPluginVST3() override + { + carla_debug("CarlaPluginVST3::~CarlaPluginVST3()"); + + pData->singleMutex.lock(); + pData->masterMutex.lock(); + + if (pData->client != nullptr && pData->client->isActive()) + pData->client->deactivate(true); + + if (pData->active) + { + deactivate(); + pData->active = false; + } + } + + // ------------------------------------------------------------------- + // Information (base) + + PluginType getType() const noexcept override + { + return PLUGIN_VST3; + } + + // ------------------------------------------------------------------- + // Information (count) + + // nothing + + // ------------------------------------------------------------------- + // Information (per-plugin data) + + // ------------------------------------------------------------------- + // Set data (state) + + // nothing + + // ------------------------------------------------------------------- + // Set data (internal stuff) + + // ------------------------------------------------------------------- + // Set data (plugin-specific stuff) + + // ------------------------------------------------------------------- + // Set ui stuff + + // ------------------------------------------------------------------- + // Plugin state + + // ------------------------------------------------------------------- + // Plugin processing + + // ------------------------------------------------------------------- + // Plugin buffers + + // ------------------------------------------------------------------- + // Post-poned UI Stuff + + // nothing + + // ------------------------------------------------------------------- + +protected: + void handlePluginUIClosed() override + { + // CARLA_SAFE_ASSERT_RETURN(fUI.window != nullptr,); + carla_debug("CarlaPluginVST3::handlePluginUIClosed()"); + + showCustomUI(false); + pData->engine->callback(true, true, + ENGINE_CALLBACK_UI_STATE_CHANGED, + pData->id, + 0, + 0, 0, 0.0f, nullptr); + } + + void handlePluginUIResized(const uint width, const uint height) override + { + // CARLA_SAFE_ASSERT_RETURN(fUI.window != nullptr,); + carla_debug("CarlaPluginVST3::handlePluginUIResized(%u, %u)", width, height); + + return; // unused + (void)width; (void)height; + } + +private: + struct UI { + bool isEmbed; + bool isOpen; + bool isVisible; + CarlaPluginUI* window; + + UI() noexcept + : isEmbed(false), + isOpen(false), + isVisible(false), + window(nullptr) {} + + ~UI() + { + CARLA_ASSERT(isEmbed || ! isVisible); + + if (window != nullptr) + { + delete window; + window = nullptr; + } + } + + CARLA_DECLARE_NON_COPY_STRUCT(UI); + } fUI; + +}; + +// -------------------------------------------------------------------------------------------------------------------- CarlaPluginPtr CarlaPlugin::newVST3(const Initializer& init) { carla_debug("CarlaPlugin::newVST3({%p, \"%s\", \"%s\", " P_INT64 "})", init.engine, init.filename, init.name, init.uniqueId); -#ifdef USING_JUCE - return newJuce(init, "VST3"); -#else +#ifdef USE_JUCE_FOR_VST3 + if (std::getenv("CARLA_DO_NOT_USE_JUCE_FOR_VST3") == nullptr) + return newJuce(init, "VST3"); +#endif + init.engine->setLastError("VST3 support not available"); return nullptr; -#endif + + /* + std::shared_ptr plugin(new CarlaPluginVST2(init.engine, init.id)); + + if (! plugin->init(plugin, init.filename, init.name, init.uniqueId, init.options)) + return nullptr; + + return plugin; + */ } // -------------------------------------------------------------------------------------------------------------------