From 3980a1c9662945676df10549868cd402de333c42 Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Wed, 11 Sep 2024 23:25:41 +0100 Subject: [PATCH] correct parameter generation --- plugin/chassis.cpp | 41 ++---------------- plugin/parameters.cpp | 96 ++++++++++++++++++++++++++++++++----------- plugin/voice.cpp | 2 +- 3 files changed, 77 insertions(+), 62 deletions(-) diff --git a/plugin/chassis.cpp b/plugin/chassis.cpp index 7e805c5..9f037ce 100644 --- a/plugin/chassis.cpp +++ b/plugin/chassis.cpp @@ -40,42 +40,7 @@ void Chassis::initProgramName(uint32_t index, String &programName) { } void Chassis::loadProgram(uint32_t index) { - - uint8_t paramOrder[16] = { - paramLFORate, - paramLFODelay, - paramVCOLFO, - paramPWMLFO, - paramNoise, - paramVCFFreq, - paramVCFReso, - paramVCFEnv, - paramVCFLFO, - paramVCFKey, - paramVCALevel, - paramAttack, - paramDecay, - paramSustain, - paramRelease, - paramSub}; - for (uint i = 0; i < 16; i++) { - setParameterValue(paramOrder[i], (float)patchData[index][i]); - } - - switch (patchData[index][16] & 0x07) { - case 1: setParameterValue(paramVCORange, 0); break; - case 4: setParameterValue(paramVCORange, 2); break; - default: setParameterValue(paramVCORange, 1); break; - } - - setParameterValue(paramSaw, (patchData[index][16] & 0x10) ? 1.0f : 0.0f); - setParameterValue(paramSqr, (patchData[index][16] & 0x08) ? 1.0f : 0.0f); - // FIXME chorus switch settings - - setParameterValue(paramPWMMode, (patchData[index][17] & 0x01) ? 0.0f : 1.0f); - setParameterValue(paramVCFMode, (patchData[index][17] & 0x02) ? 0.0f : 1.0f); - setParameterValue(paramEnvGate, (patchData[index][17] & 0x04) ? 0.0f : 1.0f); - setParameterValue(paramHPF, (patchData[index][17] & 0x18) >> 3); + memmove(&s.patchRam, (uint8_t *)patchData + (index *18), 18); } // Processing functions @@ -181,10 +146,10 @@ void Chassis::run(const float **, float **outputs, uint32_t frames, const MidiEv s.voice[i].calcPitch(s); switch (s.patchRam.switch1 & 0x07) { - case 1: + case 0: s.voice[i].omega /= 2; break; - case 4: + case 2: s.voice[i].omega *= 2; default: break; diff --git a/plugin/parameters.cpp b/plugin/parameters.cpp index 5ff5367..c24c759 100644 --- a/plugin/parameters.cpp +++ b/plugin/parameters.cpp @@ -18,7 +18,7 @@ #include "chassis.hpp" -void Chassis::initParameter(uint32_t index, Parameter ¶meter) { +void Chassis::initParameter(uint32_t index, Parameter& parameter) { switch (index) { case paramLFORate: parameter.hints = kParameterIsAutomatable; @@ -48,6 +48,19 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.ranges.max = 2.0f; parameter.ranges.def = 1.0f; parameter.midiCC = 12; + parameter.enumValues.count = 3; + parameter.enumValues.restrictedMode = true; + { + ParameterEnumerationValue* const enumValues = new ParameterEnumerationValue[3]; + enumValues[0].value = 0.0f; + enumValues[0].label = "16'"; + enumValues[1].value = 1.0f; + enumValues[1].label = "8'"; + enumValues[2].value = 2.0f; + enumValues[2].label = "4'"; + parameter.enumValues.values = enumValues; + } + break; case paramVCOLFO: @@ -78,6 +91,17 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.ranges.max = 1.0f; parameter.ranges.def = 1.0f; parameter.midiCC = 15; + parameter.enumValues.count = 2; + parameter.enumValues.restrictedMode = true; + { + ParameterEnumerationValue* const enumValues = new ParameterEnumerationValue[2]; + enumValues[0].value = 0.0f; + enumValues[0].label = "LFO"; + enumValues[1].value = 1.0f; + enumValues[1].label = "MAN"; + parameter.enumValues.values = enumValues; + } + break; case paramSaw: @@ -149,13 +173,24 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.midiCC = 71; break; case paramVCFMode: - parameter.hints = kParameterIsAutomatable | kParameterIsBoolean; + parameter.hints = kParameterIsAutomatable | kParameterIsInteger; parameter.name = "Polarity"; parameter.symbol = "ch_vcfmode"; parameter.ranges.min = 0.0f; parameter.ranges.max = 1.0f; parameter.ranges.def = 1.0f; parameter.midiCC = 21; + parameter.enumValues.count = 2; + parameter.enumValues.restrictedMode = true; + { + ParameterEnumerationValue* const enumValues = new ParameterEnumerationValue[2]; + enumValues[0].value = 0.0f; + enumValues[0].label = "POS"; + enumValues[1].value = 1.0f; + enumValues[1].label = "INV"; + parameter.enumValues.values = enumValues; + } + break; case paramVCFEnv: parameter.hints = kParameterIsAutomatable; @@ -226,13 +261,23 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { break; case paramEnvGate: - parameter.hints = kParameterIsAutomatable | kParameterIsBoolean; + parameter.hints = kParameterIsAutomatable | kParameterIsInteger; // | kParameterIsBoolean; parameter.name = "Env-Gate"; parameter.symbol = "ch_envgate"; parameter.ranges.min = 0.0f; parameter.ranges.max = 1.0f; parameter.ranges.def = 1.0f; parameter.midiCC = 25; + parameter.enumValues.count = 2; + parameter.enumValues.restrictedMode = true; + { + ParameterEnumerationValue* const enumValues = new ParameterEnumerationValue[2]; + enumValues[0].value = 0.0f; + enumValues[0].label = "ENV"; + enumValues[1].value = 1.0f; + enumValues[1].label = "GATE"; + parameter.enumValues.values = enumValues; + } break; case paramVCALevel: @@ -263,7 +308,7 @@ void Chassis::setParameterValue(uint32_t index, float value) { if (value < 0.0f) value = 0.0f; if (value > 127.0f) value = 127.0f; - //printf("setparam %d %f\n", index, value); + printf("setparam %d %f\n", index, value); switch (index) { case paramLFORate: @@ -323,16 +368,16 @@ void Chassis::setParameterValue(uint32_t index, float value) { case paramVCORange: // bits 0-2 of switch 1 // doesn't look great in Carla because of odd behaviour with small integer knobs s.patchRam.switch1 &= 0xf8; - s.patchRam.switch1 |= (1 << (int)(value-1)); + s.patchRam.switch1 |= (1 << (int)(value - 1)); break; case paramSqr: // bit 3 of switch 1 s.patchRam.switch1 &= 0xf7; - s.patchRam.switch1 |= (value >= 0.5 ) << 3; + s.patchRam.switch1 |= (value >= 0.5) << 3; break; case paramSaw: // bit 4 of switch 1 s.patchRam.switch1 &= 0xef; - s.patchRam.switch1 |= (value >= 0.5) << 4; + s.patchRam.switch1 |= (value >= 0.5) << 4; break; // missing chorus switch @@ -340,23 +385,25 @@ void Chassis::setParameterValue(uint32_t index, float value) { // switch 2 params case paramPWMMode: // bit 0 of switch 2 s.patchRam.switch2 &= 0xfe; - s.patchRam.switch2 |= (value < 0.5); + s.patchRam.switch2 |= (value >= 0.5); break; case paramVCFMode: // bit 1 of switch 2 s.patchRam.switch2 &= 0xfd; - s.patchRam.switch2 |= (value < 0.5) << 1; + s.patchRam.switch2 |= (value >= 0.5) << 1; break; case paramEnvGate: + //printf("setting envgate %f %02x", value, s.patchRam.switch2); s.patchRam.switch2 &= 0xfb; - s.patchRam.switch2 |= (value < 0.5) << 2; + s.patchRam.switch2 |= (value >= 0.5) << 2; + // printf(" set envgate %f %02x", value, s.patchRam.switch2); break; case paramHPF: // bits 3-4 of switch 2 // doesn't look great in Carla because of odd behaviour with small integer knobs if (value > 3) value = 3; s.patchRam.switch2 &= 0xf3; - s.patchRam.switch2 |= (int)value << 2; + s.patchRam.switch2 |= (int)value << 3; break; case paramModWheel: @@ -377,9 +424,14 @@ float Chassis::getParameterValue(uint32_t index) const { case paramVCORange: // FIXME this needs to be better generally switch (s.patchRam.switch1 & 0x07) { - case 1: return 0; break; - case 4: return 2; break; - default: return 1; + case 1: + return 0; + break; + case 4: + return 2; + break; + default: + return 1; } break; case paramVCOLFO: @@ -388,17 +440,15 @@ float Chassis::getParameterValue(uint32_t index) const { case paramPWMLFO: return s.patchRam.pwmLfo * 1.27f; break; - - // the "slide switches" appear inverted because up is on + case paramPWMMode: - return (s.patchRam.switch2 & 0x01) ? 0.0f : 1.0f; + return (s.patchRam.switch2 & 0x01) != 0; break; case paramSaw: - return (s.patchRam.switch1 & 0x10) ? 1.0f : 0.0f; + return (s.patchRam.switch1 & 0x10) != 0; break; case paramSqr: - return (s.patchRam.switch1 & 0x08) ? 1.0f : 0.0f; - break; + return (s.patchRam.switch1 & 0x08) != 0; case paramSub: return s.patchRam.sub; @@ -425,7 +475,7 @@ float Chassis::getParameterValue(uint32_t index) const { return s.patchRam.vcfKey; break; case paramVCFMode: - return (s.patchRam.switch2 & 0x02) ? 0.0f : 1.0f; + return (s.patchRam.switch2 & 0x02) != 0; break; case paramAttack: @@ -442,8 +492,8 @@ float Chassis::getParameterValue(uint32_t index) const { break; case paramEnvGate: - return (s.patchRam.switch2 & 0x04) ? 0.0f : 1.0f; - break; + //printf("envgate %d\n", s.patchRam.switch2 & 0x04); + return (s.patchRam.switch2 & 0x04) != 0; case paramVCALevel: return s.patchRam.vca; diff --git a/plugin/voice.cpp b/plugin/voice.cpp index 859ef30..70213a2 100644 --- a/plugin/voice.cpp +++ b/plugin/voice.cpp @@ -123,7 +123,7 @@ void Voice::run(Synth &s, float *buffer, uint32_t samples) { vr58c106 += ((vcaEnv - vr58c106) * 0.005); lastpw = pw; - out = b4 * (0.5); + out = b4 * (0.25); buffer[i] += (gain * out * vr58c106); }