Skip to content

Commit

Permalink
do overall code cleanup with Cppcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcBoule committed Oct 9, 2023
1 parent bfb2e48 commit 772ade1
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 78 deletions.
10 changes: 5 additions & 5 deletions src/BlackHoles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct BlackHoles : Module {
}


void onReset() override {
void onReset() override final {
isExponential[0] = false;
isExponential[1] = false;
wormhole = true;
Expand Down Expand Up @@ -304,7 +304,7 @@ struct BlackHolesWidget : ModuleWidget {
std::shared_ptr<window::Svg> dark_svg;

void appendContextMenu(Menu *menu) override {
BlackHoles *module = dynamic_cast<BlackHoles*>(this->module);
BlackHoles *module = static_cast<BlackHoles*>(this->module);
assert(module);

createPanelThemeMenu(menu, &(module->panelTheme));
Expand All @@ -316,7 +316,7 @@ struct BlackHolesWidget : ModuleWidget {
// Main panels from Inkscape
light_svg = APP->window->loadSvg(asset::plugin(pluginInstance, "res/WhiteLight/BlackHoles-WL.svg"));
dark_svg = APP->window->loadSvg(asset::plugin(pluginInstance, "res/DarkMatter/BlackHoles-DM.svg"));
int panelTheme = isDark(module ? (&(((BlackHoles*)module)->panelTheme)) : NULL) ? 1 : 0;// need this here since step() not called for module browser
int panelTheme = isDark(module ? (&((static_cast<BlackHoles*>(module))->panelTheme)) : NULL) ? 1 : 0;// need this here since step() not called for module browser
setPanel(panelTheme == 0 ? light_svg : dark_svg);

// Screws
Expand Down Expand Up @@ -416,10 +416,10 @@ struct BlackHolesWidget : ModuleWidget {
}

void step() override {
int panelTheme = isDark(module ? (&(((BlackHoles*)module)->panelTheme)) : NULL) ? 1 : 0;
int panelTheme = isDark(module ? (&((static_cast<BlackHoles*>(module))->panelTheme)) : NULL) ? 1 : 0;
if (lastPanelTheme != panelTheme) {
lastPanelTheme = panelTheme;
SvgPanel* panel = (SvgPanel*)getPanel();
SvgPanel* panel = static_cast<SvgPanel*>(getPanel());
panel->setBackground(panelTheme == 0 ? light_svg : dark_svg);
panel->fb->dirty = true;
}
Expand Down
10 changes: 5 additions & 5 deletions src/BlankInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct BlankInfo : Module {
panelTheme = loadDarkAsDefault();
}

void onReset() override {
void onReset() override final {
}

void onRandomize() override {
Expand Down Expand Up @@ -53,7 +53,7 @@ struct BlankInfoWidget : ModuleWidget {
std::shared_ptr<window::Svg> dark_svg;

void appendContextMenu(Menu *menu) override {
BlankInfo *module = dynamic_cast<BlankInfo*>(this->module);
BlankInfo *module = static_cast<BlankInfo*>(this->module);
assert(module);

createPanelThemeMenu(menu, &(module->panelTheme));
Expand All @@ -66,18 +66,18 @@ struct BlankInfoWidget : ModuleWidget {
// Main panels from Inkscape
light_svg = APP->window->loadSvg(asset::plugin(pluginInstance, "res/WhiteLight/BlankInfo-WL.svg"));
dark_svg = APP->window->loadSvg(asset::plugin(pluginInstance, "res/DarkMatter/BlankInfo-DM.svg"));
int panelTheme = isDark(module ? (&(((BlankInfo*)module)->panelTheme)) : NULL) ? 1 : 0;// need this here since step() not called for module browser
int panelTheme = isDark(module ? (&((static_cast<BlankInfo*>(module))->panelTheme)) : NULL) ? 1 : 0;// need this here since step() not called for module browser
setPanel(panelTheme == 0 ? light_svg : dark_svg);

// Screws
// part of svg panel, no code required
}

void step() override {
int panelTheme = isDark(module ? (&(((BlankInfo*)module)->panelTheme)) : NULL) ? 1 : 0;
int panelTheme = isDark(module ? (&((static_cast<BlankInfo*>(module))->panelTheme)) : NULL) ? 1 : 0;
if (lastPanelTheme != panelTheme) {
lastPanelTheme = panelTheme;
SvgPanel* panel = (SvgPanel*)getPanel();
SvgPanel* panel = static_cast<SvgPanel*>(getPanel());
panel->setBackground(panelTheme == 0 ? light_svg : dark_svg);
panel->fb->dirty = true;
}
Expand Down
24 changes: 14 additions & 10 deletions src/BlankLogo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ struct LowFrequencyOscillator {
float phase = 0.0f;
float freq = 1.0f;

LowFrequencyOscillator() {}
LowFrequencyOscillator() {
reset();
}
void reset() {
phase = 0.0f;
}
void setPitch(float pitch) {
pitch = std::fmin(pitch, 8.0f);
freq = std::pow(2.0f, pitch);
Expand Down Expand Up @@ -62,18 +67,17 @@ struct BlankLogo : Module {
// none

// No need to save, with reset
float clkValue;
LowFrequencyOscillator oscillatorClk;
int stepIndex;

// No need to save, no reset
LowFrequencyOscillator oscillatorClk;
Trigger clkTrigger;


BlankLogo() {
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);

configParam(CLK_FREQ_PARAM, -2.0f, 4.0f, 1.0f, "CLK freq", " BPM", 2.0f, 60.0f);// 120 BMP when default value (120 = 60*2^1) diplay params
configParam(CLK_FREQ_PARAM, -2.0f, 4.0f, 1.0f, "CLK freq", " BPM", 2.0f, 60.0f);// 120 BMP when default value (120 = 60*2^1) display params

configOutput(OUT_OUTPUT, "Mystery");

Expand All @@ -84,11 +88,11 @@ struct BlankLogo : Module {
}


void onReset() override {
void onReset() override final {
resetNonJson();
}
void resetNonJson() {
clkValue = 0.0f;
oscillatorClk.reset();
stepIndex = 0;
}

Expand Down Expand Up @@ -141,7 +145,7 @@ struct BlankLogoWidget : ModuleWidget {
std::shared_ptr<window::Svg> dark_svg;

void appendContextMenu(Menu *menu) override {
BlankLogo *module = dynamic_cast<BlankLogo*>(this->module);
BlankLogo *module = static_cast<BlankLogo*>(this->module);
assert(module);

createPanelThemeMenu(menu, &(module->panelTheme));
Expand All @@ -153,7 +157,7 @@ struct BlankLogoWidget : ModuleWidget {
// Main panels from Inkscape
light_svg = APP->window->loadSvg(asset::plugin(pluginInstance, "res/WhiteLight/BlankLogo-WL.svg"));
dark_svg = APP->window->loadSvg(asset::plugin(pluginInstance, "res/DarkMatter/BlankLogo-DM.svg"));
int panelTheme = isDark(module ? (&(((BlankLogo*)module)->panelTheme)) : NULL) ? 1 : 0;// need this here since step() not called for module browser
int panelTheme = isDark(module ? (&((static_cast<BlankLogo*>(module))->panelTheme)) : NULL) ? 1 : 0;// need this here since step() not called for module browser
setPanel(panelTheme == 0 ? light_svg : dark_svg);

// Screws
Expand All @@ -164,10 +168,10 @@ struct BlankLogoWidget : ModuleWidget {
}

void step() override {
int panelTheme = isDark(module ? (&(((BlankLogo*)module)->panelTheme)) : NULL) ? 1 : 0;
int panelTheme = isDark(module ? (&((static_cast<BlankLogo*>(module))->panelTheme)) : NULL) ? 1 : 0;
if (lastPanelTheme != panelTheme) {
lastPanelTheme = panelTheme;
SvgPanel* panel = (SvgPanel*)getPanel();
SvgPanel* panel = static_cast<SvgPanel*>(getPanel());
panel->setBackground(panelTheme == 0 ? light_svg : dark_svg);
panel->fb->dirty = true;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Branes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ struct Branes : Module {
}


void onReset() override {
void onReset() override final {
for (int i = 0; i < 2; i++) {
vibrations[i] = 0;
noiseRange[i] = false;
Expand Down Expand Up @@ -493,7 +493,7 @@ struct BranesWidget : ModuleWidget {
std::shared_ptr<window::Svg> dark_svg;

void appendContextMenu(Menu *menu) override {
Branes *module = dynamic_cast<Branes*>(this->module);
Branes *module = static_cast<Branes*>(this->module);
assert(module);

createPanelThemeMenu(menu, &(module->panelTheme));
Expand Down Expand Up @@ -528,7 +528,7 @@ struct BranesWidget : ModuleWidget {
// Main panels from Inkscape
light_svg = APP->window->loadSvg(asset::plugin(pluginInstance, "res/WhiteLight/Branes-WL.svg"));
dark_svg = APP->window->loadSvg(asset::plugin(pluginInstance, "res/DarkMatter/Branes-DM.svg"));
int panelTheme = isDark(module ? (&(((Branes*)module)->panelTheme)) : NULL) ? 1 : 0;// need this here since step() not called for module browser
int panelTheme = isDark(module ? (&((static_cast<Branes*>(module))->panelTheme)) : NULL) ? 1 : 0;// need this here since step() not called for module browser
setPanel(panelTheme == 0 ? light_svg : dark_svg);

// Screws
Expand Down Expand Up @@ -613,10 +613,10 @@ struct BranesWidget : ModuleWidget {
}

void step() override {
int panelTheme = isDark(module ? (&(((Branes*)module)->panelTheme)) : NULL) ? 1 : 0;
int panelTheme = isDark(module ? (&((static_cast<Branes*>(module))->panelTheme)) : NULL) ? 1 : 0;
if (lastPanelTheme != panelTheme) {
lastPanelTheme = panelTheme;
SvgPanel* panel = (SvgPanel*)getPanel();
SvgPanel* panel = static_cast<SvgPanel*>(getPanel());
panel->setBackground(panelTheme == 0 ? light_svg : dark_svg);
panel->fb->dirty = true;
}
Expand Down
15 changes: 7 additions & 8 deletions src/DarkEnergy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ struct DarkEnergy : Module {
float resetLight0 = 0.0f;
float resetLight1 = 0.0f;
Trigger planckTriggers[2];
Trigger modtypeTriggers[2];
Trigger resetTriggers[3];// M inut, C input, button (trigs both)
Trigger modeTrigger;
Trigger multEnableTrigger;
Expand Down Expand Up @@ -160,7 +159,7 @@ struct DarkEnergy : Module {
}


void onReset() override {
void onReset() override final {
for (int c = 0; c < N_POLY; c++) {
oscM[c].onReset();
oscC[c].onReset();
Expand All @@ -186,7 +185,7 @@ struct DarkEnergy : Module {
void onRandomize() override {
}

void onSampleRateChange() override {
void onSampleRateChange() override final {
float sampleRate = APP->engine->getSampleRate();
for (int c = 0; c < N_POLY; c++) {
oscM[c].onSampleRateChange(sampleRate);
Expand Down Expand Up @@ -366,7 +365,7 @@ struct DarkEnergy : Module {

// vocts
float base = inputs[FREQCV_INPUT].getVoltage(c);
float vocts[2] = {base + modSignals[0][c], base + modSignals[1][c]};
const float vocts[2] = {base + modSignals[0][c], base + modSignals[1][c]};

// oscillators
float oscMout = oscM[c].step(vocts[0], feedbacks[0][c] * 0.3f, depths[0][c], oscC[c]._feedbackDelayedSample);
Expand Down Expand Up @@ -536,7 +535,7 @@ struct DarkEnergyWidget : ModuleWidget {
std::shared_ptr<window::Svg> dark_svg;

void appendContextMenu(Menu *menu) override {
DarkEnergy *module = dynamic_cast<DarkEnergy*>(this->module);
DarkEnergy *module = static_cast<DarkEnergy*>(this->module);
assert(module);

createPanelThemeMenu(menu, &(module->panelTheme));
Expand All @@ -548,7 +547,7 @@ struct DarkEnergyWidget : ModuleWidget {
// Main panels from Inkscape
light_svg = APP->window->loadSvg(asset::plugin(pluginInstance, "res/WhiteLight/DarkEnergy-WL.svg"));
dark_svg = APP->window->loadSvg(asset::plugin(pluginInstance, "res/DarkMatter/DarkEnergy-DM.svg"));
int panelTheme = isDark(module ? (&(((DarkEnergy*)module)->panelTheme)) : NULL) ? 1 : 0;// need this here since step() not called for module browser
int panelTheme = isDark(module ? (&((static_cast<DarkEnergy*>(module))->panelTheme)) : NULL) ? 1 : 0;// need this here since step() not called for module browser
setPanel(panelTheme == 0 ? light_svg : dark_svg);

// Screws
Expand Down Expand Up @@ -650,10 +649,10 @@ struct DarkEnergyWidget : ModuleWidget {
}

void step() override {
int panelTheme = isDark(module ? (&(((DarkEnergy*)module)->panelTheme)) : NULL) ? 1 : 0;
int panelTheme = isDark(module ? (&((static_cast<DarkEnergy*>(module))->panelTheme)) : NULL) ? 1 : 0;
if (lastPanelTheme != panelTheme) {
lastPanelTheme = panelTheme;
SvgPanel* panel = (SvgPanel*)getPanel();
SvgPanel* panel = static_cast<SvgPanel*>(getPanel());
panel->setBackground(panelTheme == 0 ? light_svg : dark_svg);
panel->fb->dirty = true;
}
Expand Down
14 changes: 7 additions & 7 deletions src/Energy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ struct Energy : Module {
}


void onReset() override {
void onReset() override final {
for (int c = 0; c < N_POLY; c++) {
oscM[c].onReset();
oscC[c].onReset();
Expand All @@ -140,7 +140,7 @@ struct Energy : Module {
}


void onSampleRateChange() override {
void onSampleRateChange() override final {
float sampleRate = APP->engine->getSampleRate();
for (int c = 0; c < N_POLY; c++) {
oscM[c].onSampleRateChange(sampleRate);
Expand Down Expand Up @@ -280,7 +280,7 @@ struct Energy : Module {
}

// vocts
float vocts[2] = {modSignals[0][c] + inputs[FREQCV_INPUT].getVoltage(c), modSignals[1][c] + inputs[FREQCV_INPUT].getVoltage(c)};
const float vocts[2] = {modSignals[0][c] + inputs[FREQCV_INPUT].getVoltage(c), modSignals[1][c] + inputs[FREQCV_INPUT].getVoltage(c)};

// oscillators
float oscMout = oscM[c].step(vocts[0], feedbacks[0][c] * 0.3f);
Expand Down Expand Up @@ -409,7 +409,7 @@ struct EnergyWidget : ModuleWidget {
std::shared_ptr<window::Svg> dark_svg;

void appendContextMenu(Menu *menu) override {
Energy *module = dynamic_cast<Energy*>(this->module);
Energy *module = static_cast<Energy*>(this->module);
assert(module);

createPanelThemeMenu(menu, &(module->panelTheme));
Expand All @@ -421,7 +421,7 @@ struct EnergyWidget : ModuleWidget {
// Main panels from Inkscape
light_svg = APP->window->loadSvg(asset::plugin(pluginInstance, "res/WhiteLight/Energy-WL.svg"));
dark_svg = APP->window->loadSvg(asset::plugin(pluginInstance, "res/DarkMatter/Energy-DM.svg"));
int panelTheme = isDark(module ? (&(((Energy*)module)->panelTheme)) : NULL) ? 1 : 0;// need this here since step() not called for module browser
int panelTheme = isDark(module ? (&((static_cast<Energy*>(module))->panelTheme)) : NULL) ? 1 : 0;// need this here since step() not called for module browser
setPanel(panelTheme == 0 ? light_svg : dark_svg);

// Screws
Expand Down Expand Up @@ -495,10 +495,10 @@ struct EnergyWidget : ModuleWidget {
}

void step() override {
int panelTheme = isDark(module ? (&(((Energy*)module)->panelTheme)) : NULL) ? 1 : 0;
int panelTheme = isDark(module ? (&((static_cast<Energy*>(module))->panelTheme)) : NULL) ? 1 : 0;
if (lastPanelTheme != panelTheme) {
lastPanelTheme = panelTheme;
SvgPanel* panel = (SvgPanel*)getPanel();
SvgPanel* panel = static_cast<SvgPanel*>(getPanel());
panel->setBackground(panelTheme == 0 ? light_svg : dark_svg);
panel->fb->dirty = true;
}
Expand Down
22 changes: 22 additions & 0 deletions src/EnergyOsc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ CICDecimator::~CICDecimator() {
delete[] _combs;
}

CICDecimator::CICDecimator(const CICDecimator& srcc) {
copyFrom(srcc);
}
void CICDecimator::copyFrom(const CICDecimator& srcc) {
// just dummy for now, finish implementing if needed
_stages = srcc._stages;
if (_integrators != nullptr) {
delete[] _integrators;
}
_integrators = new T[_stages + 1] {};// should copy
if (_combs != nullptr) {
delete[] _combs;
}
_combs = new T[_stages] {};// should copy
setParams(0.0f, srcc._factor);
}

CICDecimator& CICDecimator::operator=(const CICDecimator& srcc) {
copyFrom(srcc);
return *this;
}

void CICDecimator::setParams(float _sampleRate, int factor) {
assert(factor > 0);
if (_factor != factor) {
Expand Down
12 changes: 7 additions & 5 deletions src/EnergyOsc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,17 @@ struct CICDecimator : Decimator {
typedef int64_t T;
static constexpr T scale = ((T)1) << 32;
int _stages;
T* _integrators;
T* _combs;
T* _integrators = nullptr;
T* _combs = nullptr;
int _factor = 0;
float _gainCorrection;

CICDecimator(int stages = 4, int factor = 8);
virtual ~CICDecimator();

void setParams(float sampleRate, int factor) override;
CICDecimator(const CICDecimator& srcc);
void copyFrom(const CICDecimator& srcc);
CICDecimator& operator=(const CICDecimator& srcc);
void setParams(float sampleRate, int factor) override final;
float next(const float* buf) override;
};

Expand Down Expand Up @@ -237,7 +239,7 @@ struct Phasor : OscillatorGenerator {
void setPhase(phase_t givenPhase) {_phase = givenPhase;}
float nextFromPhasor(const Phasor& phasor, phase_delta_t offset = 0);
inline float nextForPhase(phase_t phase) { return _nextForPhase(phase); }
virtual void _update();
void _update();
inline void advancePhase() { _phase += _delta; }
inline void advancePhase(int n) { assert(n > 0); _phase += n * _delta; }
float _next() override final;
Expand Down
Loading

0 comments on commit 772ade1

Please sign in to comment.