From c688a0e209fd674ae3117c0b9b84a0f4e7be5900 Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Tue, 20 Feb 2024 11:27:03 +0100 Subject: [PATCH] fixed rounding and test warning --- templates/android/src/jni.cpp | 2 +- templates/cmd/src/main.c | 2 +- templates/daisy-seed/src/main.cpp | 2 +- templates/ios/src/native.mm | 2 +- templates/lv2/src/lv2.c | 2 +- templates/vst3/src/vst3.c | 2 +- test/plugin.h | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/templates/android/src/jni.cpp b/templates/android/src/jni.cpp index ebabd45..f482d65 100644 --- a/templates/android/src/jni.cpp +++ b/templates/android/src/jni.cpp @@ -328,7 +328,7 @@ JNI_FUNC(nativeSetParameter)(JNIEnv* env, jobject thiz, jint i, jfloat v) { if (param_data[i].flags & (PARAM_BYPASS | PARAM_TOGGLED)) v = v > 0.5f ? 1.f : 0.f; else if (param_data[i].flags & PARAM_INTEGER) - v = (int32_t)(v + 0.5f); + v = (int32_t)(v + (v >= 0.? : 0.5f : -0.5f)); v = std::min(std::max(v, param_data[i].min), param_data[i].max); #if PARAMETERS_N > 0 mutex.lock(); diff --git a/templates/cmd/src/main.c b/templates/cmd/src/main.c index 3883be9..9cc0f72 100644 --- a/templates/cmd/src/main.c +++ b/templates/cmd/src/main.c @@ -293,7 +293,7 @@ int main(int argc, char * argv[]) { if (param_data[i].flags & (PARAM_BYPASS | PARAM_TOGGLED)) v = v > 0.5f ? 1.f : 0.f; else if (param_data[i].flags & PARAM_INTEGER) - v = (int32_t)(v + 0.5f); + v = (int32_t)(v + (v >= 0.f ? 0.5f : -0.5f)); param_values[i] = clampf(v, param_data[i].min, param_data[i].max); } diff --git a/templates/daisy-seed/src/main.cpp b/templates/daisy-seed/src/main.cpp index 1307adb..4540917 100644 --- a/templates/daisy-seed/src/main.cpp +++ b/templates/daisy-seed/src/main.cpp @@ -64,7 +64,7 @@ static float parameterUnmap(int i, float v) { static float parameterAdjust(int i, float v) { v = param_data[i].flags & (PARAM_BYPASS | PARAM_TOGGLED) ? (v >= 0.5f ? 1.f : 0.f) - : (param_data[i].flags & PARAM_INTEGER ? (int32_t)(v + 0.5f) : v); + : (param_data[i].flags & PARAM_INTEGER ? (int32_t)(v + (v >= 0.f ? 0.5f : -0.5f)) : v); return clampf(v, param_data[i].min, param_data[i].max); } diff --git a/templates/ios/src/native.mm b/templates/ios/src/native.mm index c6a977f..5219110 100644 --- a/templates/ios/src/native.mm +++ b/templates/ios/src/native.mm @@ -343,7 +343,7 @@ void setParameter(int i, float v) { if (param_data[i].flags & (PARAM_BYPASS | PARAM_TOGGLED)) v = v > 0.5f ? 1.f : 0.f; else if (param_data[i].flags & PARAM_INTEGER) - v = (int32_t)(v + 0.5f); + v = (int32_t)(v + (v >= 0.f ? 0.5f : -0.5f)); v = std::min(std::max(v, param_data[i].min), param_data[i].max); #if PARAMETERS_N > 0 mutex.lock(); diff --git a/templates/lv2/src/lv2.c b/templates/lv2/src/lv2.c index 3356ef5..d1182c4 100644 --- a/templates/lv2/src/lv2.c +++ b/templates/lv2/src/lv2.c @@ -190,7 +190,7 @@ static void run(LV2_Handle instance, uint32_t sample_count) { else if (param_data[j].flags & DATA_PARAM_TOGGLED) v = *i->c[k] > 0.f ? 1.f : 0.f; else if (param_data[j].flags & DATA_PARAM_INTEGER) - v = (int32_t)(*i->c[k] + 0.5f); + v = (int32_t)(*i->c[k] + (*i->c[k] >= 0.f ? 0.5f : -0.5f)); else v = *i->c[k]; diff --git a/templates/vst3/src/vst3.c b/templates/vst3/src/vst3.c index 5f40660..0e021ca 100644 --- a/templates/vst3/src/vst3.c +++ b/templates/vst3/src/vst3.c @@ -44,7 +44,7 @@ static double parameterUnmap(Steinberg_Vst_ParamID id, double v) { static double parameterAdjust(Steinberg_Vst_ParamID id, double v) { v = parameterData[id].flags & (DATA_PARAM_BYPASS | DATA_PARAM_TOGGLED) ? (v >= 0.5 ? 1.0 : 0.0) - : (parameterData[id].flags & DATA_PARAM_INTEGER ? (int32_t)(v + 0.5) : v); + : (parameterData[id].flags & DATA_PARAM_INTEGER ? (int32_t)(v + (v >= 0.0 ? 0.5 : -0.5)) : v); return clamp(v, parameterData[id].min, parameterData[id].max); } diff --git a/test/plugin.h b/test/plugin.h index 64bdea0..7a083be 100644 --- a/test/plugin.h +++ b/test/plugin.h @@ -91,7 +91,7 @@ static void plugin_process(plugin *instance, const float **inputs, float **outpu static void plugin_midi_msg_in(plugin *instance, size_t index, const uint8_t * data) { (void)index; - if ((data[0] & 0xf0 == 0x90) && (data[2] != 0)) + if (((data[0] & 0xf0) == 0x90) && (data[2] != 0)) //approx instance->cutoff_k = powf(2.f, (1.f / 12.f) * (note - 60)); instance->cutoff_k = data[1] < 64 ? (-0.19558034980097166f * data[1] - 2.361735109225749f) / (data[1] - 75.57552349522389f) : (393.95397927344214f - 7.660826245588588f * data[1]) / (data[1] - 139.0755234952239f); }