From 678505e87f7535d08f715a867f56a7e75881f1e7 Mon Sep 17 00:00:00 2001 From: falkTX Date: Mon, 13 Apr 2020 02:49:05 +0100 Subject: [PATCH] Add a simple cv2audio plugin, per user request Signed-off-by: falkTX --- source/native-plugins/Makefile | 1 + source/native-plugins/_all.c | 4 +- source/native-plugins/_data.cpp | 22 ++- source/native-plugins/cv-to-audio.c | 242 ++++++++++++++++++++++++++++ 4 files changed, 267 insertions(+), 2 deletions(-) create mode 100644 source/native-plugins/cv-to-audio.c diff --git a/source/native-plugins/Makefile b/source/native-plugins/Makefile index ddaf961c4..01b062d31 100644 --- a/source/native-plugins/Makefile +++ b/source/native-plugins/Makefile @@ -32,6 +32,7 @@ OBJS = \ $(OBJDIR)/_data.cpp.o \ $(OBJDIR)/audio-gain.c.o \ $(OBJDIR)/bypass.c.o \ + $(OBJDIR)/cv-to-audio.c.o \ $(OBJDIR)/lfo.c.o \ $(OBJDIR)/midi-channel-filter.c.o \ $(OBJDIR)/midi-channel-ab.c.o \ diff --git a/source/native-plugins/_all.c b/source/native-plugins/_all.c index 5cc851277..bb9407144 100644 --- a/source/native-plugins/_all.c +++ b/source/native-plugins/_all.c @@ -1,6 +1,6 @@ /* * Carla Native Plugins - * Copyright (C) 2012-2019 Filipe Coelho + * Copyright (C) 2012-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 @@ -23,6 +23,7 @@ // Simple plugins extern void carla_register_native_plugin_audiogain(void); extern void carla_register_native_plugin_bypass(void); +extern void carla_register_native_plugin_cv2audio(void); extern void carla_register_native_plugin_lfo(void); extern void carla_register_native_plugin_midi2cv(void); extern void carla_register_native_plugin_midichanab(void); @@ -61,6 +62,7 @@ void carla_register_all_native_plugins(void) // Simple plugins carla_register_native_plugin_audiogain(); carla_register_native_plugin_bypass(); + carla_register_native_plugin_cv2audio(); carla_register_native_plugin_lfo(); carla_register_native_plugin_midi2cv(); carla_register_native_plugin_midichanab(); diff --git a/source/native-plugins/_data.cpp b/source/native-plugins/_data.cpp index 68cd1d79d..052245955 100644 --- a/source/native-plugins/_data.cpp +++ b/source/native-plugins/_data.cpp @@ -1,6 +1,6 @@ /* * Carla Native Plugins - * Copyright (C) 2012-2019 Filipe Coelho + * Copyright (C) 2012-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 @@ -83,6 +83,26 @@ static const NativePluginDescriptor sNativePluginDescriptors[] = { /* copyright */ "GNU GPL v2+", DESCFUNCS_WITHOUTCV }, +{ + /* category */ NATIVE_PLUGIN_CATEGORY_UTILITY, + /* hints */ NATIVE_PLUGIN_IS_RTSAFE, + /* supports */ NATIVE_PLUGIN_SUPPORTS_NOTHING, + /* audioIns */ 0, + /* audioOuts */ 1, + /* midiIns */ 0, + /* midiOuts */ 0, + /* paramIns */ 1, + /* paramOuts */ 0, + /* name */ "CV to Audio", + /* label */ "cv2audio", + /* maker */ "falkTX", + /* copyright */ "GNU GPL v2+", + DESCFUNCS_WITHCV, + /* cvIns */ 1, + /* cvOuts */ 0, + /* bufnamefn */ nullptr, + /* bufrangefn */ nullptr +}, { /* category */ NATIVE_PLUGIN_CATEGORY_UTILITY, /* hints */ NATIVE_PLUGIN_IS_RTSAFE, diff --git a/source/native-plugins/cv-to-audio.c b/source/native-plugins/cv-to-audio.c new file mode 100644 index 000000000..bc86999d4 --- /dev/null +++ b/source/native-plugins/cv-to-audio.c @@ -0,0 +1,242 @@ +/* + * Carla Native Plugins + * Copyright (C) 2012-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 + * published by the Free Software Foundation; either version 2 of + * the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For a full copy of the GNU General Public License see the doc/GPL.txt file. + */ + +#include "CarlaNative.h" + +#include +#include +#include +#include + +// ----------------------------------------------------------------------- + +typedef enum { + // all versions + PARAM_LIMITER = 0, + PARAM_COUNT +} CvToAudioParams; + +typedef struct { + bool limiterOn; +} CvToAudioHandle; + +// ----------------------------------------------------------------------- + +static NativePluginHandle cv2audio_instantiate(const NativeHostDescriptor* host) +{ + CvToAudioHandle* const handle = (CvToAudioHandle*)malloc(sizeof(CvToAudioHandle)); + + if (handle == NULL) + return NULL; + + handle->limiterOn = true; + + return handle; + + // unused + (void)host; +} + +#define handlePtr ((CvToAudioHandle*)handle) + +static void cv2audio_cleanup(NativePluginHandle handle) +{ + free(handlePtr); +} + +static uint32_t cv2audio_get_parameter_count(NativePluginHandle handle) +{ + return PARAM_COUNT; + + // unused + (void)handle; +} + +static const NativeParameter* cv2audio_get_parameter_info(NativePluginHandle handle, uint32_t index) +{ + if (index > PARAM_COUNT) + return NULL; + + static NativeParameter param; + + param.hints = NATIVE_PARAMETER_IS_ENABLED|NATIVE_PARAMETER_IS_AUTOMABLE; + param.unit = NULL; + param.scalePointCount = 0; + param.scalePoints = NULL; + + switch (index) + { + case PARAM_LIMITER: + param.name = "Briwall Limiter"; + param.hints |= NATIVE_PARAMETER_IS_BOOLEAN; + param.ranges.def = 1.0f; + param.ranges.min = 0.0f; + param.ranges.max = 1.0f; + param.ranges.step = 1.0f; + param.ranges.stepSmall = 1.0f; + param.ranges.stepLarge = 1.0f; + break; + } + + return ¶m; + + // unused + (void)handle; +} + +static float cv2audio_get_parameter_value(NativePluginHandle handle, uint32_t index) +{ + switch (index) + { + case PARAM_LIMITER: + return handlePtr->limiterOn ? 1.0f : 0.0f; + default: + return 0.0f; + } +} + +static void cv2audio_set_parameter_value(NativePluginHandle handle, uint32_t index, float value) +{ + switch (index) + { + case PARAM_LIMITER: + handlePtr->limiterOn = (value >= 0.5f); + break; + } +} + +static const NativePortRange* cv2audio_get_buffer_port_range(NativePluginHandle handle, uint32_t index, bool isOutput) +{ + if (isOutput) + return NULL; + + static NativePortRange npr; + + switch (index) + { + case 0: + npr.minimum = -1.0f; + npr.maximum = 1.0f; + return ⊀ + default: + return NULL; + } + + // unused + (void)handle; +} + +static const char* cv2audio_get_buffer_port_name(NativePluginHandle handle, uint32_t index, bool isOutput) +{ + if (index != 0) + return NULL; + + return isOutput ? "Audio Output" : "CV Input"; + + // unused + (void)handle; +} + +// FIXME for v3.0, use const for the input buffer +static void cv2audio_process(NativePluginHandle handle, + float** inBuffer, float** outBuffer, uint32_t frames, + const NativeMidiEvent* midiEvents, uint32_t midiEventCount) +{ + const float* const inBuf = inBuffer[0]; + /**/ float* const outBuf = outBuffer[0]; + + if (handlePtr->limiterOn) + { + for (uint32_t i=0; i