Add initial bits for Qt6 support
[carla.git] / source / native-plugins / cv-to-audio.c
blobfda6c89edeb77ccbe469931d6da65e0080319499
1 /*
2 * Carla Native Plugins
3 * Copyright (C) 2012-2020 Filipe Coelho <falktx@falktx.com>
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.
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.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #include "CarlaNative.h"
20 #include <math.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
25 // -----------------------------------------------------------------------
27 typedef enum {
28 // all versions
29 PARAM_LIMITER = 0,
30 PARAM_COUNT
31 } CvToAudioParams;
33 typedef struct {
34 bool limiterOn;
35 } CvToAudioHandle;
37 // -----------------------------------------------------------------------
39 static NativePluginHandle cv2audio_instantiate(const NativeHostDescriptor* host)
41 CvToAudioHandle* const handle = (CvToAudioHandle*)malloc(sizeof(CvToAudioHandle));
43 if (handle == NULL)
44 return NULL;
46 handle->limiterOn = true;
48 return handle;
50 // unused
51 (void)host;
54 #define handlePtr ((CvToAudioHandle*)handle)
56 static void cv2audio_cleanup(NativePluginHandle handle)
58 free(handlePtr);
61 static uint32_t cv2audio_get_parameter_count(NativePluginHandle handle)
63 return PARAM_COUNT;
65 // unused
66 (void)handle;
69 static const NativeParameter* cv2audio_get_parameter_info(NativePluginHandle handle, uint32_t index)
71 if (index > PARAM_COUNT)
72 return NULL;
74 static NativeParameter param;
76 param.hints = NATIVE_PARAMETER_IS_ENABLED|NATIVE_PARAMETER_IS_AUTOMATABLE;
77 param.unit = NULL;
78 param.scalePointCount = 0;
79 param.scalePoints = NULL;
81 switch (index)
83 case PARAM_LIMITER:
84 param.name = "Briwall Limiter";
85 param.hints |= NATIVE_PARAMETER_IS_BOOLEAN;
86 param.ranges.def = 1.0f;
87 param.ranges.min = 0.0f;
88 param.ranges.max = 1.0f;
89 param.ranges.step = 1.0f;
90 param.ranges.stepSmall = 1.0f;
91 param.ranges.stepLarge = 1.0f;
92 break;
95 return &param;
97 // unused
98 (void)handle;
101 static float cv2audio_get_parameter_value(NativePluginHandle handle, uint32_t index)
103 switch (index)
105 case PARAM_LIMITER:
106 return handlePtr->limiterOn ? 1.0f : 0.0f;
107 default:
108 return 0.0f;
112 static void cv2audio_set_parameter_value(NativePluginHandle handle, uint32_t index, float value)
114 switch (index)
116 case PARAM_LIMITER:
117 handlePtr->limiterOn = (value >= 0.5f);
118 break;
122 static const NativePortRange* cv2audio_get_buffer_port_range(NativePluginHandle handle, uint32_t index, bool isOutput)
124 if (isOutput)
125 return NULL;
127 static NativePortRange npr;
129 switch (index)
131 case 0:
132 npr.minimum = -1.0f;
133 npr.maximum = 1.0f;
134 return &npr;
135 default:
136 return NULL;
139 // unused
140 (void)handle;
143 static const char* cv2audio_get_buffer_port_name(NativePluginHandle handle, uint32_t index, bool isOutput)
145 if (index != 0)
146 return NULL;
148 return isOutput ? "Audio Output" : "CV Input";
150 // unused
151 (void)handle;
154 // FIXME for v3.0, use const for the input buffer
155 static void cv2audio_process(NativePluginHandle handle,
156 float** inBuffer, float** outBuffer, uint32_t frames,
157 const NativeMidiEvent* midiEvents, uint32_t midiEventCount)
159 const float* const inBuf = inBuffer[0];
160 /**/ float* const outBuf = outBuffer[0];
162 if (handlePtr->limiterOn)
164 for (uint32_t i=0; i<frames; ++i)
165 outBuf[i] = fmaxf(fminf(inBuf[i], 1.0f), -1.0f);
167 else
169 if (outBuf != inBuf)
170 memcpy(outBuf, inBuf, sizeof(float)*frames);
173 return;
175 // unused
176 (void)midiEvents;
177 (void)midiEventCount;
180 // -----------------------------------------------------------------------
182 static const NativePluginDescriptor cv2audioDesc = {
183 .category = NATIVE_PLUGIN_CATEGORY_UTILITY,
184 .hints = NATIVE_PLUGIN_IS_RTSAFE|NATIVE_PLUGIN_USES_CONTROL_VOLTAGE,
185 .supports = NATIVE_PLUGIN_SUPPORTS_NOTHING,
186 .audioIns = 0,
187 .audioOuts = 1,
188 .cvIns = 1,
189 .cvOuts = 0,
190 .midiIns = 0,
191 .midiOuts = 0,
192 .paramIns = PARAM_COUNT,
193 .paramOuts = 0,
194 .name = "CV to Audio",
195 .label = "cv2audio",
196 .maker = "falkTX",
197 .copyright = "GNU GPL v2+",
199 .instantiate = cv2audio_instantiate,
200 .cleanup = cv2audio_cleanup,
202 .get_parameter_count = cv2audio_get_parameter_count,
203 .get_parameter_info = cv2audio_get_parameter_info,
204 .get_parameter_value = cv2audio_get_parameter_value,
206 .get_midi_program_count = NULL,
207 .get_midi_program_info = NULL,
209 .set_parameter_value = cv2audio_set_parameter_value,
210 .set_midi_program = NULL,
211 .set_custom_data = NULL,
213 .get_buffer_port_name = cv2audio_get_buffer_port_name,
214 .get_buffer_port_range = cv2audio_get_buffer_port_range,
216 .ui_show = NULL,
217 .ui_idle = NULL,
219 .ui_set_parameter_value = NULL,
220 .ui_set_midi_program = NULL,
221 .ui_set_custom_data = NULL,
223 .activate = NULL,
224 .deactivate = NULL,
225 .process = cv2audio_process,
227 .get_state = NULL,
228 .set_state = NULL,
230 .dispatcher = NULL
233 // -----------------------------------------------------------------------
235 void carla_register_native_plugin_cv2audio(void);
237 void carla_register_native_plugin_cv2audio(void)
239 carla_register_native_plugin(&cv2audioDesc);
242 // -----------------------------------------------------------------------