From 8db6aa98e290e3984d628cb9891b6f4602867dff Mon Sep 17 00:00:00 2001 From: falkTX Date: Mon, 13 Apr 2020 08:07:23 +0100 Subject: [PATCH] Allow carla-plugin to have full access to Host API Signed-off-by: falkTX --- source/includes/CarlaNativePlugin.h | 20 +++++++++++++++++--- source/plugin/carla-native-plugin.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/source/includes/CarlaNativePlugin.h b/source/includes/CarlaNativePlugin.h index 65014984e..9b1dca4c2 100644 --- a/source/includes/CarlaNativePlugin.h +++ b/source/includes/CarlaNativePlugin.h @@ -1,6 +1,6 @@ /* * Carla Plugin Host - * Copyright (C) 2011-2019 Filipe Coelho + * Copyright (C) 2011-2020 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 @@ -18,8 +18,8 @@ #ifndef CARLA_NATIVE_PLUGIN_H_INCLUDED #define CARLA_NATIVE_PLUGIN_H_INCLUDED -#include "CarlaBackend.h" #include "CarlaNative.h" +#include "CarlaHost.h" #ifndef CARLA_HOST_H_INCLUDED #ifndef CARLA_UTILS_H_INCLUDED @@ -65,11 +65,25 @@ CARLA_EXPORT const NativePluginDescriptor* carla_get_native_patchbay64_plugin(vo */ CARLA_EXPORT const NativePluginDescriptor* carla_get_native_patchbay_cv_plugin(void); +/*! + * Create a CarlaHostHandle suitable for CarlaHost API calls. + * Returned value must be freed by the caller when no longer needed. + */ +CARLA_EXPORT CarlaHostHandle carla_create_native_plugin_host_handle(const NativePluginDescriptor* desc, + NativePluginHandle handle); + +/*! + * Free memory created during carla_create_native_plugin_host_handle. + */ +CARLA_EXPORT void carla_host_handle_free(CarlaHostHandle handle); + #ifdef __cplusplus /*! * Get the internal CarlaEngine instance. + * @deprecated Please use carla_create_native_plugin_host_handle instead */ -CARLA_EXPORT CarlaBackend::CarlaEngine* carla_get_native_plugin_engine(const NativePluginDescriptor* desc, NativePluginHandle handle); +CARLA_EXPORT CarlaBackend::CarlaEngine* carla_get_native_plugin_engine(const NativePluginDescriptor* desc, + NativePluginHandle handle); #endif #endif /* CARLA_NATIVE_PLUGIN_H_INCLUDED */ diff --git a/source/plugin/carla-native-plugin.cpp b/source/plugin/carla-native-plugin.cpp index 8f5077a6b..61e0a1324 100644 --- a/source/plugin/carla-native-plugin.cpp +++ b/source/plugin/carla-native-plugin.cpp @@ -16,6 +16,7 @@ */ #include "CarlaNativePlugin.h" +#include "CarlaHostImpl.hpp" #include "CarlaEngine.hpp" #include "CarlaString.hpp" @@ -26,6 +27,32 @@ CARLA_BACKEND_USE_NAMESPACE // -------------------------------------------------------------------------------------------------------------------- +CarlaHostHandle carla_create_native_plugin_host_handle(const NativePluginDescriptor* desc, NativePluginHandle handle) +{ + CarlaEngine* const engine = carla_get_native_plugin_engine(desc, handle); + CARLA_SAFE_ASSERT_RETURN(engine, nullptr); + + CarlaHostHandleImpl* hosthandle; + + try { + hosthandle = new CarlaHostHandleImpl(); + } CARLA_SAFE_EXCEPTION_RETURN("carla_create_native_plugin_host_handle()", nullptr); + + hosthandle->engine = engine; + hosthandle->isPlugin = true; + return hosthandle; +} + +void carla_host_handle_free(CarlaHostHandle handle) +{ + CARLA_SAFE_ASSERT_RETURN(handle != nullptr,); + CARLA_SAFE_ASSERT_RETURN(handle->isPlugin,); + + delete (CarlaHostHandleImpl*)handle; +} + +// -------------------------------------------------------------------------------------------------------------------- + CarlaEngine* carla_get_native_plugin_engine(const NativePluginDescriptor* desc, NativePluginHandle handle) { CARLA_SAFE_ASSERT_RETURN(desc != nullptr, nullptr);