broke out parameter code to a separate source file because it's getting a tad unruly in there

This commit is contained in:
Gordon JC Pearce 2024-09-08 21:55:46 +01:00
parent 0274204809
commit 3c9edede8d
3 changed files with 337 additions and 314 deletions

View File

@ -10,6 +10,7 @@
NAME = chassis NAME = chassis
FILES_DSP = \ FILES_DSP = \
parameters.cpp \
chassis.cpp \ chassis.cpp \
voice.cpp voice.cpp

View File

@ -25,320 +25,6 @@ Chassis::Chassis() : Plugin(parameterCount, 0, 0), sampleRate(getSampleRate()) {
// Initialisation functions // Initialisation functions
void Chassis::initParameter(uint32_t index, Parameter &parameter) {
switch (index) {
case paramLFORate:
parameter.hints = kParameterIsAutomatable;
parameter.name = "LFO Rate";
parameter.symbol = "ch_lforate";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 57.0f;
parameter.midiCC = 3;
break;
case paramLFODelay:
parameter.hints = kParameterIsAutomatable;
parameter.name = "LFO Delay";
parameter.symbol = "ch_lfodelay";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 45.0f;
parameter.midiCC = 9;
break;
case paramVCORange:
parameter.hints = kParameterIsAutomatable | kParameterIsInteger;
parameter.name = "Range";
parameter.symbol = "ch_vcorange";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 4.0f;
parameter.ranges.def = 2.0f;
parameter.midiCC = 12;
break;
case paramVCOLFO:
parameter.hints = kParameterIsAutomatable;
parameter.name = "LFO";
parameter.symbol = "ch_lfo";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 13;
break;
case paramPWMLFO:
parameter.hints = kParameterIsAutomatable;
parameter.name = "PWM";
parameter.symbol = "ch_pwm";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 55.0f;
parameter.midiCC = 14;
break;
case paramPWMMode:
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
parameter.name = "LFO/Manual";
parameter.symbol = "ch_pwmmode";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 15;
break;
case paramSaw:
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
parameter.name = "Saw";
parameter.symbol = "ch_saw";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 127.0f;
parameter.midiCC = 17;
break;
case paramSqr:
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
parameter.name = "Square";
parameter.symbol = "ch_sqr";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 127.0f;
parameter.midiCC = 16;
break;
case paramSub:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Sub Osc";
parameter.symbol = "ch_sub";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 18;
break;
case paramNoise:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Noise";
parameter.symbol = "ch_noise";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 19;
break;
case paramHPF:
parameter.hints = kParameterIsAutomatable | kParameterIsInteger;
parameter.name = "HPF";
parameter.symbol = "ch_hpf";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 4.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 20;
break;
case paramVCFFreq:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Freq";
parameter.symbol = "ch_freq";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 74;
break;
case paramVCFReso:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Res";
parameter.symbol = "ch_reso";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 74;
break;
case paramVCFMode:
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
parameter.name = "Polarity";
parameter.symbol = "ch_vcfmode";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 21;
break;
case paramVCFEnv:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Env";
parameter.symbol = "ch_vcfenv";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 22;
break;
case paramVCFLFO:
parameter.hints = kParameterIsAutomatable;
parameter.name = "LFO";
parameter.symbol = "ch_vcflfo";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 23;
break;
case paramVCFKey:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Kybd";
parameter.symbol = "ch_vcfkey";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 24;
break;
case paramAttack:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Attack";
parameter.symbol = "ch_attack";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 59.0f;
parameter.midiCC = 73;
break;
case paramDecay:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Decay";
parameter.symbol = "ch_decay";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 32.0f;
parameter.midiCC = 75;
break;
case paramSustain:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Sustain";
parameter.symbol = "ch_sustain";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 86.0f;
parameter.midiCC = 27;
break;
case paramRelease:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Release";
parameter.symbol = "ch_release";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 40.0f;
parameter.midiCC = 72;
break;
case paramEnvGate:
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
parameter.name = "Env / Gate";
parameter.symbol = "ch_envgate";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 25;
break;
case paramVCALevel:
parameter.hints = kParameterIsAutomatable;
parameter.name = "VCA Level";
parameter.symbol = "ch_vcalevel";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 40.0f;
parameter.midiCC = 26;
break;
}
}
void Chassis::setParameterValue(uint32_t index, float value) {
// should be trapped by host, but let's be safe
if (value < 0.0f) value = 0.0f;
if (value > 127.0f) value = 127.0f;
switch (index) {
case paramLFORate:
s.patchRam.lfoRate = value;
break;
case paramLFODelay:
s.patchRam.lfoDelay = value;
break;
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);
break;
case paramVCOLFO:
s.patchRam.vcoLfo = value;
break;
case paramPWMLFO:
s.patchRam.pwmLfo = value;
break;
case paramSaw:
s.patchRam.switch1 &= 0xef;
s.patchRam.switch1 |= (value > 63) << 4;
break;
case paramSqr:
s.patchRam.switch1 &= 0xf7;
s.patchRam.switch1 |= (value > 63) << 3;
break;
case paramSub:
s.patchRam.sub = value;
break;
case paramAttack:
s.patchRam.env_a = value;
break;
case paramDecay:
s.patchRam.env_d = value;
break;
case paramSustain:
s.patchRam.env_s = value;
break;
case paramRelease:
s.patchRam.env_r = value;
break;
case paramEnvGate:
s.patchRam.switch2 &= 0xfb;
s.patchRam.switch2 |= (value > 63) << 2;
break;
case paramVCALevel:
s.patchRam.vca = value;
break;
}
}
float Chassis::getParameterValue(uint32_t index) const {
// printf("getparametervalue %d\n", index);
switch (index) {
case paramSaw:
return (s.patchRam.switch1 & 0x10) ? 127.0f : 0.0f;
break;
case paramSqr:
return (s.patchRam.switch1 & 0x08) ? 127.0f : 0.0f;
break;
case paramAttack:
return s.patchRam.env_a;
break;
case paramDecay:
return s.patchRam.env_d;
break;
case paramSustain:
return s.patchRam.env_s;
break;
case paramRelease:
return s.patchRam.env_r;
break;
}
return 0;
}
void Chassis::initAudioPort(bool input, uint32_t index, AudioPort &port) { void Chassis::initAudioPort(bool input, uint32_t index, AudioPort &port) {
port.groupId = kPortGroupStereo; port.groupId = kPortGroupStereo;

336
plugin/parameters.cpp Normal file
View File

@ -0,0 +1,336 @@
/*
Chassis polysynth framework
Copyright 2024 Gordon JC Pearce <gordonjcp@gjcp.net>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "chassis.hpp"
void Chassis::initParameter(uint32_t index, Parameter &parameter) {
switch (index) {
case paramLFORate:
parameter.hints = kParameterIsAutomatable;
parameter.name = "LFO Rate";
parameter.symbol = "ch_lforate";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 57.0f;
parameter.midiCC = 3;
break;
case paramLFODelay:
parameter.hints = kParameterIsAutomatable;
parameter.name = "LFO Delay";
parameter.symbol = "ch_lfodelay";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 45.0f;
parameter.midiCC = 9;
break;
case paramVCORange:
parameter.hints = kParameterIsAutomatable | kParameterIsInteger;
parameter.name = "Range";
parameter.symbol = "ch_vcorange";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 4.0f;
parameter.ranges.def = 2.0f;
parameter.midiCC = 12;
break;
case paramVCOLFO:
parameter.hints = kParameterIsAutomatable;
parameter.name = "LFO";
parameter.symbol = "ch_lfo";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 13;
break;
case paramPWMLFO:
parameter.hints = kParameterIsAutomatable;
parameter.name = "PWM";
parameter.symbol = "ch_pwm";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 55.0f;
parameter.midiCC = 14;
break;
case paramPWMMode:
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
parameter.name = "LFO/Manual";
parameter.symbol = "ch_pwmmode";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 15;
break;
case paramSaw:
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
parameter.name = "Saw";
parameter.symbol = "ch_saw";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 127.0f;
parameter.midiCC = 17;
break;
case paramSqr:
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
parameter.name = "Square";
parameter.symbol = "ch_sqr";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 127.0f;
parameter.midiCC = 16;
break;
case paramSub:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Sub Osc";
parameter.symbol = "ch_sub";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 18;
break;
case paramNoise:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Noise";
parameter.symbol = "ch_noise";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 19;
break;
case paramHPF:
parameter.hints = kParameterIsAutomatable | kParameterIsInteger;
parameter.name = "HPF";
parameter.symbol = "ch_hpf";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 4.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 20;
break;
case paramVCFFreq:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Freq";
parameter.symbol = "ch_freq";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 74;
break;
case paramVCFReso:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Res";
parameter.symbol = "ch_reso";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 74;
break;
case paramVCFMode:
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
parameter.name = "Polarity";
parameter.symbol = "ch_vcfmode";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 21;
break;
case paramVCFEnv:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Env";
parameter.symbol = "ch_vcfenv";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 22;
break;
case paramVCFLFO:
parameter.hints = kParameterIsAutomatable;
parameter.name = "LFO";
parameter.symbol = "ch_vcflfo";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 23;
break;
case paramVCFKey:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Kybd";
parameter.symbol = "ch_vcfkey";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 24;
break;
case paramAttack:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Attack";
parameter.symbol = "ch_attack";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 59.0f;
parameter.midiCC = 73;
break;
case paramDecay:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Decay";
parameter.symbol = "ch_decay";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 32.0f;
parameter.midiCC = 75;
break;
case paramSustain:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Sustain";
parameter.symbol = "ch_sustain";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 86.0f;
parameter.midiCC = 27;
break;
case paramRelease:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Release";
parameter.symbol = "ch_release";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 40.0f;
parameter.midiCC = 72;
break;
case paramEnvGate:
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
parameter.name = "Env / Gate";
parameter.symbol = "ch_envgate";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 25;
break;
case paramVCALevel:
parameter.hints = kParameterIsAutomatable;
parameter.name = "VCA Level";
parameter.symbol = "ch_vcalevel";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f;
parameter.ranges.def = 40.0f;
parameter.midiCC = 26;
break;
}
}
void Chassis::setParameterValue(uint32_t index, float value) {
// should be trapped by host, but let's be safe
if (value < 0.0f) value = 0.0f;
if (value > 127.0f) value = 127.0f;
switch (index) {
case paramLFORate:
s.patchRam.lfoRate = value;
break;
case paramLFODelay:
s.patchRam.lfoDelay = value;
break;
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);
break;
case paramVCOLFO:
s.patchRam.vcoLfo = value;
break;
case paramPWMLFO:
s.patchRam.pwmLfo = value;
break;
case paramSaw:
s.patchRam.switch1 &= 0xef;
s.patchRam.switch1 |= (value > 63) << 4;
break;
case paramSqr:
s.patchRam.switch1 &= 0xf7;
s.patchRam.switch1 |= (value > 63) << 3;
break;
case paramSub:
s.patchRam.sub = value;
break;
case paramAttack:
s.patchRam.env_a = value;
break;
case paramDecay:
s.patchRam.env_d = value;
break;
case paramSustain:
s.patchRam.env_s = value;
break;
case paramRelease:
s.patchRam.env_r = value;
break;
case paramEnvGate:
s.patchRam.switch2 &= 0xfb;
s.patchRam.switch2 |= (value > 63) << 2;
break;
case paramVCALevel:
s.patchRam.vca = value;
break;
}
}
float Chassis::getParameterValue(uint32_t index) const {
// printf("getparametervalue %d\n", index);
switch (index) {
case paramSaw:
return (s.patchRam.switch1 & 0x10) ? 127.0f : 0.0f;
break;
case paramSqr:
return (s.patchRam.switch1 & 0x08) ? 127.0f : 0.0f;
break;
case paramAttack:
return s.patchRam.env_a;
break;
case paramDecay:
return s.patchRam.env_d;
break;
case paramSustain:
return s.patchRam.env_s;
break;
case paramRelease:
return s.patchRam.env_r;
break;
}
return 0;
}