Skip to content

Commit

Permalink
more small clean and refactor PM and EQ
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcBoule committed Oct 14, 2023
1 parent 0d5270f commit a0c2097
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 93 deletions.
40 changes: 23 additions & 17 deletions src/EqMaster/EqMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct EqMaster : Module {
MfeExpInterface expMessages[2];// messages from eq-expander, see enum in EqCommon.hpp

// Constants
int numChannels16 = 16;// avoids warning that happens when hardcode 16 (static const or directly use 16 in code below)
const int numChannels16 = 16;// avoids warning that happens when hardcode 16 (static const or directly use 16 in code below)
int8_t cloakedMode = 0x0;

// Need to save, no reset
Expand All @@ -44,7 +44,7 @@ struct EqMaster : Module {
char trackLabels[24 * 4 + 1];// needs to be saved in case we are detached
int8_t trackLabelColors[24];
int8_t trackVuColors[24];
TrackEq trackEqs[24];
std::vector<TrackEq> trackEqs;// size 24
PackedBytes4 miscSettings;// cc4[0] is ShowBandCurvesEQ, cc4[1] is fft type (0 = off, 1 = pre, 2 = post, 3 = freeze), cc4[2] is momentaryCvButtons (1 = yes (original rising edge only version), 0 = level sensitive (emulated with rising and falling detection)), cc4[3] is detailsShow
PackedBytes4 miscSettings2;// cc4[0] is band label colours, cc4[1] is decay rate (0 = slow, 1 = med, 2 = fast), cc[2] is hide eq curves when bypassed, cc[3] is unused
PackedBytes4 showFreqAsNotes;
Expand Down Expand Up @@ -150,7 +150,11 @@ struct EqMaster : Module {
configBypass(SIG_INPUTS + i, SIG_OUTPUTS + i);
}

onReset();
trackEqs.reserve(24);
float sr = APP->engine->getSampleRate();
for (int t = 0; t < 24; t++) {
trackEqs.push_back(TrackEq(t, sr, &cvConnected));
}

ffts = pffft_new_setup(FFT_N, PFFFT_REAL);
fftIn[0] = static_cast<float*>(pffft_aligned_malloc(FFT_N * 4));
Expand All @@ -164,6 +168,8 @@ struct EqMaster : Module {
drawBufLin[i] = 0.0f;
}
windowFunc = allocateAndCalcWindowFunc();

onReset();
}

~EqMaster() {
Expand All @@ -185,15 +191,15 @@ struct EqMaster : Module {

void onReset() override final {
mappedId = 0;
initTrackLabelsAndColors();
initTrackLabelsAndColors();// trackLabels[], trackLabelColors[], trackVuColors[]
for (int t = 0; t < 24; t++) {
trackEqs[t].init(t, APP->engine->getSampleRate(), &cvConnected);
trackEqs[t].onReset();
}
miscSettings.cc4[0] = 0x1;// show band curves by default
miscSettings.cc4[1] = SPEC_MASK_ON | SPEC_MASK_POST;
miscSettings.cc4[2] = 0x1; // momentary by default
miscSettings.cc4[3] = 0x7; // detailsShow
miscSettings2.cc4[0] = 0;// band label colours
miscSettings2.cc4[0] = 0;// band label colors
miscSettings2.cc4[1] = 2;// decay rate fast
miscSettings2.cc4[2] = 0;// hide eq curves when bypassed
miscSettings2.cc4[3] = 0;// unused
Expand Down Expand Up @@ -900,23 +906,23 @@ struct EqMasterWidget : ModuleWidget {
trackLabel->mappedId = &(module->mappedId);
trackLabel->trackLabelsSrc = module->trackLabels;
trackLabel->trackParamSrc = &(module->params[TRACK_PARAM]);
trackLabel->trackEqsSrc = module->trackEqs;
trackLabel->trackEqsSrc = &(module->trackEqs[0]);
trackLabel->updateTrackLabelRequestSrc = &(module->updateTrackLabelRequest);
}
// Track knob
TrackKnob* trackKnob;
addParam(trackKnob = createParamCentered<TrackKnob>(mm2px(Vec(leftX, 22.7f)), module, TRACK_PARAM));
if (module) {
trackKnob->updateTrackLabelRequestSrc = &(module->updateTrackLabelRequest);
trackKnob->trackEqsSrc = module->trackEqs;
trackKnob->trackEqsSrc = &(module->trackEqs[0]);
trackKnob->polyInputs = &(module->inputs[EqMaster::SIG_INPUTS]);
}
// Active switch
ActiveSwitch* activeSwitch;
addParam(activeSwitch = createParamCentered<ActiveSwitch>(mm2px(Vec(leftX, 48.775f)), module, TRACK_ACTIVE_PARAM));
if (module) {
activeSwitch->trackParamSrc = &(module->params[TRACK_PARAM]);
activeSwitch->trackEqsSrc = module->trackEqs;
activeSwitch->trackEqsSrc = &(module->trackEqs[0]);
}
// Global bypass switch
addParam(createParamCentered<MmBypassButton>(mm2px(Vec(leftX, 67.7f)), module, GLOBAL_BYPASS_PARAM));
Expand All @@ -943,7 +949,7 @@ struct EqMasterWidget : ModuleWidget {
addChild(eqCurveAndGrid = createWidgetCentered<EqCurveAndGrid>(mm2px(Vec(71.12f, 45.47f - 0.5f))));
if (module) {
eqCurveAndGrid->trackParamSrc = &(module->params[TRACK_PARAM]);
eqCurveAndGrid->trackEqsSrc = module->trackEqs;
eqCurveAndGrid->trackEqsSrc = &(module->trackEqs[0]);
eqCurveAndGrid->miscSettingsSrc = &(module->miscSettings);
eqCurveAndGrid->miscSettings2Src = &(module->miscSettings2);
eqCurveAndGrid->globalBypassParamSrc = &(module->params[GLOBAL_BYPASS_PARAM]);
Expand All @@ -960,7 +966,7 @@ struct EqMasterWidget : ModuleWidget {
addChild(bigNumbersEq = createWidgetCentered<BigNumbersEq>(mm2px(Vec(71.12f, 68.0f))));
if (module) {
bigNumbersEq->trackParamSrc = &(module->params[TRACK_PARAM]);
bigNumbersEq->trackEqsSrc = module->trackEqs;
bigNumbersEq->trackEqsSrc = &(module->trackEqs[0]);
bigNumbersEq->lastMovedKnobIdSrc = &lastMovedKnobId;
bigNumbersEq->lastMovedKnobTimeSrc = &lastMovedKnobTime;
}
Expand All @@ -983,7 +989,7 @@ struct EqMasterWidget : ModuleWidget {
if (module) {
for (int b = 0; b < 4; b++) {
peakShelfSwitches[b]->trackParamSrc = &(module->params[TRACK_PARAM]);
peakShelfSwitches[b]->trackEqsSrc = module->trackEqs;
peakShelfSwitches[b]->trackEqsSrc = &(module->trackEqs[0]);
peakShelfSwitches[b]->isLF = (b < 2);
}
}
Expand All @@ -998,7 +1004,7 @@ struct EqMasterWidget : ModuleWidget {
for (int b = 0; b < 4; b++) {
bandSwitches[b]->trackParamSrc = &(module->params[TRACK_PARAM]);
bandSwitches[b]->freqActiveParamsSrc = &(module->params[FREQ_ACTIVE_PARAMS]);
bandSwitches[b]->trackEqsSrc = module->trackEqs;
bandSwitches[b]->trackEqsSrc = &(module->trackEqs[0]);
}
}

Expand Down Expand Up @@ -1032,7 +1038,7 @@ struct EqMasterWidget : ModuleWidget {
bandKnobs[c]->cloakedModeSrc = &cloakedMode;
bandKnobs[c]->detailsShowSrc = &(module->miscSettings.cc4[3]);
bandKnobs[c]->trackParamSrc = &(module->params[TRACK_PARAM]);
bandKnobs[c]->trackEqsSrc = module->trackEqs;
bandKnobs[c]->trackEqsSrc = &(module->trackEqs[0]);
bandKnobs[c]->lastMovedKnobIdSrc = & lastMovedKnobId;
bandKnobs[c]->lastMovedKnobTimeSrc = &lastMovedKnobTime;
}
Expand All @@ -1049,7 +1055,7 @@ struct EqMasterWidget : ModuleWidget {
for (int i = 0; i < 12; i++) {
bandLabels[i]->bandLabelColorsSrc = &(module->miscSettings2.cc4[0]);
bandLabels[i]->trackParamSrc = &(module->params[TRACK_PARAM]);
bandLabels[i]->trackEqsSrc = module->trackEqs;
bandLabels[i]->trackEqsSrc = &(module->trackEqs[0]);
bandLabels[i]->band = (i % 4);
}
for (int i = 0; i < 4; i++) {
Expand All @@ -1075,7 +1081,7 @@ struct EqMasterWidget : ModuleWidget {
addParam(trackGainKnob = createParamCentered<TrackGainKnob>(mm2px(Vec(rightX, 67.0f)), module, TRACK_GAIN_PARAM));
if (module) {
trackGainKnob->trackParamSrc = &(module->params[TRACK_PARAM]);
trackGainKnob->trackEqsSrc = module->trackEqs;
trackGainKnob->trackEqsSrc = &(module->trackEqs[0]);
trackGainKnob->detailsShowSrc = &(module->miscSettings.cc4[3]);
trackGainKnob->cloakedModeSrc = &(module->cloakedMode);
}
Expand Down Expand Up @@ -1179,7 +1185,7 @@ struct EqMasterWidget : ModuleWidget {
if (message.tm.tmSep[0] != 0 && message.tm.tmTot != module->lastTrackMove) {
// has valid and fresh move
module->lastTrackMove = message.tm.tmTot;// avoids doing the move again until a new fresh move is detected
moveTrack(module->trackEqs, message.tm.tmSep[1], message.tm.tmSep[2]);
moveTrack(&(module->trackEqs[0]), message.tm.tmSep[1], message.tm.tmSep[2]);
// DEBUG("Track move from %i to %i", message.tm.tmSep[1], message.tm.tmSep[2]);
}

Expand Down
73 changes: 35 additions & 38 deletions src/EqMaster/EqMasterCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct MfeExpInterface {// for messages to mother from expander
int trackCvsIndex6 = 0;
int trackEnableIndex = 0;
int trackCvsConnected = 0;// only 4 lsbits used
float trackCvs[16 * 4] = {0.0f};// room for 4 poly cables
float trackCvs[16 * 4] = {};// room for 4 poly cables
float trackEnable = 0.0f;// one of the 24+1 enable cvs
};

Expand Down Expand Up @@ -71,17 +71,17 @@ static const NVGcolor SCHEME_GRAY = nvgRGB(130, 130, 130);
class TrackEq {
static constexpr float antipopSlewLogHz = 8.0f;// calibrated to properly slew a log(Hz) float in the rough range 1.3f to 4.3f (but less since freq knobs not full spectrum)
static constexpr float antipopSlewDb = 200.0f;// calibrated to properly slew a dB float in the range -20.0f to 20.0f for antipop
int trackNum = 0;
float sampleRate = 0.0f;
float sampleTime = 0.0f;
uint32_t *cvConnected = nullptr;
int trackNum;
float sampleRate;
float sampleTime;
uint32_t *cvConnected;

// automatically managed internally by member functions
int dirty;// 4 bits, one for each band (automatically managed by member methods, no need to handle in init() and copyFrom())
QuattroBiQuad::Type bandTypes[4]; // only [0] and [3] are dependants, [1] and [2] are set to their permanent values in init()
QuattroBiQuad::Type bandTypes[4]; // only [0] and [3] are dependents, [1] and [2] are set to their permanent values in init()

// need saving
bool trackActive = false;
bool trackActive;
simd::float_4 bandActive;// 0.0f or 1.0f values: frequency band's eq is active, one for LF, LMF, HMF, HF
simd::float_4 freq;// in log(Hz) to match params, converted to scaled linear freq before pushing params to eq
simd::float_4 gain;// in dB to match params, is converted to linear before pushing params to eqs
Expand All @@ -101,7 +101,7 @@ class TrackEq {
simd::float_4 gainCv;// adding-type cvs
simd::float_4 qCv;// adding-type cvs

// dependants
// dependents
QuattroBiQuad eqs;
TSlewLimiterSingle<simd::float_4> freqSlewers;// in log(Hz)
TSlewLimiterSingle<simd::float_4> gainSlewers;// in dB
Expand All @@ -110,44 +110,29 @@ class TrackEq {

public:

TrackEq() {
lowPeak = !DEFAULT_lowPeak;// to force bandTypes[0] to be set when first init() will call setLowPeak()
TrackEq(int _trackNum, float _sampleRate, uint32_t *_cvConnected) {
trackNum = _trackNum;
updateSampleRate(_sampleRate);// sampleRate, sampleTime
cvConnected = _cvConnected;

dirty = 0xF;
bandTypes[1] = QuattroBiQuad::PEAK;
bandTypes[2] = QuattroBiQuad::PEAK;
highPeak = !DEFAULT_highPeak;// to force bandTypes[3] to be set when first init() will call setLowPeak()
trackGain = 0.0f;
freqSlewers.setRiseFall(simd::float_4(antipopSlewLogHz)); // slew rate is in input-units per second (ex: V/s)
gainSlewers.setRiseFall(simd::float_4(antipopSlewDb)); // slew rate is in input-units per second (ex: V/s)
trackGainSlewer.setRiseFall(antipopSlewDb);

// the following are just set here to dummy values since there are test and sets in their initializations further below, and this is just to get rid of uninit warning, good values will be set in init()'s onReset()
trackActive = false;
dirty = 0xF;
bandActive = simd::float_4(0.0f);
freq = simd::float_4(0.0f);
gain = simd::float_4(0.0f);
q = simd::float_4(0.0f);
}

void init(int _trackNum, float _sampleRate, uint32_t *_cvConnected) {
trackNum = _trackNum;
sampleRate = _sampleRate;
sampleTime = 1.0f / sampleRate;
cvConnected = _cvConnected;
lowPeak = !DEFAULT_lowPeak;// to force bandTypes[0] to be set when first onReset() will call setLowPeak()
highPeak = !DEFAULT_highPeak;// to force bandTypes[3] to be set when first onReset() will call setLowPeak()
freqSlewers.setRiseFall(simd::float_4(antipopSlewLogHz)); // slew rate is in input-units per second (ex: V/s)
gainSlewers.setRiseFall(simd::float_4(antipopSlewDb)); // slew rate is in input-units per second (ex: V/s)
trackGainSlewer.setRiseFall(antipopSlewDb);

onReset();

// don't need saving
freqCv = 0.0f;
gainCv = 0.0f;
qCv = 0.0f;

// dependants
eqs.reset();
freqSlewers.reset();
gainSlewers.reset();
trackGainSlewer.reset();
}

void onReset() {
// need saving
setTrackActive(DEFAULT_trackActive);
Expand All @@ -156,13 +141,25 @@ class TrackEq {
setFreq(i, DEFAULT_logFreq[i]);
setGain(i, DEFAULT_gain);
setQ(i, DEFAULT_q[i]);
freqCvAtten[i] = 1.0f;
gainCvAtten[i] = 1.0f;
qCvAtten[i] = 1.0f;
}
setLowPeak(DEFAULT_lowPeak);
setHighPeak(DEFAULT_highPeak);
setTrackGain(DEFAULT_trackGain);

freqCvAtten = simd::float_4(1.0f);
gainCvAtten = simd::float_4(1.0f);
qCvAtten = simd::float_4(1.0f);

// don't need saving
freqCv = 0.0f;
gainCv = 0.0f;
qCv = 0.0f;

// dependents
eqs.reset();
freqSlewers.reset();
gainSlewers.reset();
trackGainSlewer.reset();
}

bool getTrackActive() {return trackActive;}
Expand Down
2 changes: 1 addition & 1 deletion src/EqMaster/EqMenus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ struct CopyTrackSettingsItem : MenuItem {

void moveTrack(TrackEq *trackEqsSrc, int trackNumSrc, int trackNumDest) {
// does not check for trackNumSrc == trackNumDest
TrackEq buffer1;
TrackEq buffer1(0, 0.0f, nullptr);

buffer1.copyFrom(&trackEqsSrc[trackNumSrc]);
if (trackNumDest < trackNumSrc) {
Expand Down
6 changes: 3 additions & 3 deletions src/MindMeldModular.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ struct SlewLimiterFast {
};

struct HoldDetect {
long modeHoldDetect;// 0 when not detecting, downward counter when detecting
long modeHoldDetect = 0l;// 0 when not detecting, downward counter when detecting

void reset() {
modeHoldDetect = 0l;
Expand All @@ -207,7 +207,7 @@ struct HoldDetect {
};

struct DispTwoColorItem : MenuItem {
int8_t *srcColor;
int8_t *srcColor = nullptr;

Menu *createChildMenu() override {
Menu *menu = new Menu;
Expand All @@ -225,7 +225,7 @@ struct DispTwoColorItem : MenuItem {

// poly stereo menu item
struct PolyStereoItem : MenuItem {
int8_t *polyStereoSrc;
int8_t *polyStereoSrc = nullptr;

Menu *createChildMenu() override {
Menu *menu = new Menu;
Expand Down
Loading

0 comments on commit a0c2097

Please sign in to comment.