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"
25 // -----------------------------------------------------------------------
37 // -----------------------------------------------------------------------
39 static NativePluginHandle
cv2audio_instantiate(const NativeHostDescriptor
* host
)
41 CvToAudioHandle
* const handle
= (CvToAudioHandle
*)malloc(sizeof(CvToAudioHandle
));
46 handle
->limiterOn
= true;
54 #define handlePtr ((CvToAudioHandle*)handle)
56 static void cv2audio_cleanup(NativePluginHandle handle
)
61 static uint32_t cv2audio_get_parameter_count(NativePluginHandle handle
)
69 static const NativeParameter
* cv2audio_get_parameter_info(NativePluginHandle handle
, uint32_t index
)
71 if (index
> PARAM_COUNT
)
74 static NativeParameter param
;
76 param
.hints
= NATIVE_PARAMETER_IS_ENABLED
|NATIVE_PARAMETER_IS_AUTOMATABLE
;
78 param
.scalePointCount
= 0;
79 param
.scalePoints
= NULL
;
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
;
101 static float cv2audio_get_parameter_value(NativePluginHandle handle
, uint32_t index
)
106 return handlePtr
->limiterOn
? 1.0f
: 0.0f
;
112 static void cv2audio_set_parameter_value(NativePluginHandle handle
, uint32_t index
, float value
)
117 handlePtr
->limiterOn
= (value
>= 0.5f
);
122 static const NativePortRange
* cv2audio_get_buffer_port_range(NativePluginHandle handle
, uint32_t index
, bool isOutput
)
127 static NativePortRange npr
;
143 static const char* cv2audio_get_buffer_port_name(NativePluginHandle handle
, uint32_t index
, bool isOutput
)
148 return isOutput
? "Audio Output" : "CV Input";
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
);
170 memcpy(outBuf
, inBuf
, sizeof(float)*frames
);
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
,
192 .paramIns
= PARAM_COUNT
,
194 .name
= "CV to Audio",
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
,
219 .ui_set_parameter_value
= NULL
,
220 .ui_set_midi_program
= NULL
,
221 .ui_set_custom_data
= NULL
,
225 .process
= cv2audio_process
,
233 // -----------------------------------------------------------------------
235 void carla_register_native_plugin_cv2audio(void);
237 void carla_register_native_plugin_cv2audio(void)
239 carla_register_native_plugin(&cv2audioDesc
);
242 // -----------------------------------------------------------------------