Skip to content

Commit

Permalink
AUX Slew config in menu
Browse files Browse the repository at this point in the history
  • Loading branch information
docb committed Feb 24, 2023
1 parent cdb8102 commit 52153f5
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 55 deletions.
28 changes: 26 additions & 2 deletions src/AX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ struct AUX : Module {
for(int k=0;k<channels;k++) {
float cLvl=params[k].getValue();
if(inputs[LVL_INPUT].isConnected()) {
slewLimiter[k].setRiseFall(slew,slew);
float sl=(slew+0.001f)*1000.f;
slewLimiter[k].setRiseFall(1.f/sl,1.f/sl);
float lvl=slewLimiter[k].process(1.f,clamp(inputs[LVL_INPUT].getVoltage(k),0.f,10.f))*0.1f;
cLvl*=lvl;
}
Expand All @@ -57,7 +58,8 @@ struct AUX : Module {
}
float lvl=params[LEVEL_PARAM].getValue();
if(inputs[MAIN_INPUT].isConnected()) {
mainSlewLimiter.setRiseFall(slew,slew);
float sl=(slew+0.001f)*1000.f;
mainSlewLimiter.setRiseFall(1.f/sl,1.f/sl);
float mainLvl=mainSlewLimiter.process(1.f,clamp(inputs[MAIN_INPUT].getVoltage(),0.f,10.f))*0.1f;
lvl*=mainLvl;
}
Expand Down Expand Up @@ -90,6 +92,18 @@ struct AUX : Module {
lights[VU_LIGHTS_R+7].setBrightness(vuMeterR.getBrightness(-60,-48));
}
}

json_t *dataToJson() override {
json_t *data=json_object();
json_object_set_new(data,"slew",json_real(slew));
return data;
}

void dataFromJson(json_t *rootJ) override {
json_t *jSlew = json_object_get(rootJ,"slew");
if(jSlew!=nullptr) slew = json_real_value(jSlew);
}

};


Expand Down Expand Up @@ -145,6 +159,16 @@ struct AUXWidget : ModuleWidget {
addChild(createLight<SmallSimpleLight<GreenLight>>(mm2px(Vec(xL,y)),module,AUX::VU_LIGHTS_L+7));
addChild(createLight<SmallSimpleLight<GreenLight>>(mm2px(Vec(xR,y)),module,AUX::VU_LIGHTS_R+7));
}

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

menu->addChild(new MenuSeparator);

menu->addChild(new SlewMenuItem<AUX>(module));
}

};


Expand Down
54 changes: 1 addition & 53 deletions src/SKF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,58 +117,6 @@ struct SKF : Module {

};

struct SlewQuantity : Quantity {
SKF* module;

SlewQuantity(SKF* m) : module(m) {}

void setValue(float value) override {
value = clamp(value, getMinValue(), getMaxValue());
if (module) {
module->slew = value;
}
}

float getValue() override {
if (module) {
return module->slew;
}
return 0.5f;
}

float getMinValue() override { return 0.0f; }
float getMaxValue() override { return 1.0f; }
float getDefaultValue() override { return 1.f/16.f; }
float getDisplayValue() override { return getValue(); }
void setDisplayValue(float displayValue) override { setValue(displayValue); }
std::string getLabel() override { return "Slew"; }
std::string getUnit() override { return ""; }
};

struct SlewSlider : ui::Slider {
SlewSlider(SKF* module) {
quantity = new SlewQuantity(module);
box.size.x = 200.0f;
}
virtual ~SlewSlider() {
delete quantity;
}
};

struct SlewMenuItem : MenuItem {
SKF* module;

SlewMenuItem(SKF* m) : module(m) {
this->text = "Freq Input";
this->rightText = "";
}

Menu* createChildMenu() override {
Menu* menu = new Menu;
menu->addChild(new SlewSlider(module));
return menu;
}
};


struct SKFWidget : ModuleWidget {
Expand Down Expand Up @@ -205,7 +153,7 @@ struct SKFWidget : ModuleWidget {

menu->addChild(new MenuSeparator);

menu->addChild(new SlewMenuItem(module));
menu->addChild(new SlewMenuItem<SKF>(module));
}

};
Expand Down
53 changes: 53 additions & 0 deletions src/dcb.h
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,60 @@ struct DensMenuItem : MenuItem {
return menu;
}
};
template<typename T>
struct SlewQuantity : Quantity {
T *module;

SlewQuantity(T *m) : module(m) {}

void setValue(float value) override {
value = clamp(value, getMinValue(), getMaxValue());
if (module) {
module->slew = value;
}
}

float getValue() override {
if (module) {
return module->slew;
}
return 0.5f;
}

float getMinValue() override { return 0.0f; }
float getMaxValue() override { return 1.0f; }
float getDefaultValue() override { return 1.f/16.f; }
float getDisplayValue() override { return getValue(); }
void setDisplayValue(float displayValue) override { setValue(displayValue); }
std::string getLabel() override { return "Slew"; }
std::string getUnit() override { return ""; }
};
template<typename T>
struct SlewSlider : ui::Slider {
SlewSlider(T* module) {
quantity = new SlewQuantity<T>(module);
box.size.x = 200.0f;
}
virtual ~SlewSlider() {
delete quantity;
}
};

template<typename T>
struct SlewMenuItem : MenuItem {
T *module;

SlewMenuItem(T *m) : module(m) {
this->text = "Level Input";
this->rightText = "";
}

Menu* createChildMenu() override {
Menu* menu = new Menu;
menu->addChild(new SlewSlider<T>(module));
return menu;
}
};
struct IntSelectItem : MenuItem {
int *value;
int min;
Expand Down

0 comments on commit 52153f5

Please sign in to comment.