|
-
- #include "Offset.hpp"
-
- void Offset::step() {
- float offset = knobValue(params[OFFSET_PARAM], inputs[OFFSET_INPUT]);
- float scale = knobValue(params[SCALE_PARAM], inputs[SCALE_INPUT]);
- scale = scale < 0.0f ? -pow(scale, 2.0f) : pow(scale, 2.0f);
- scale *= 10.0;
-
- float out = inputs[IN_INPUT].value;
- out += 10.0f * offset;
- out *= scale;
- if (!_disableOutputLimit) {
- out = clamp(out, -12.0f, 12.0f);
- }
- outputs[OUT_OUTPUT].value = out;
- }
-
- float Offset::knobValue(const Param& knob, const Input& cv) const {
- float v = knob.value;
- if (cv.active) {
- v *= clamp(cv.value / 10.0f, -1.0f, 1.0f);
- }
- return v;
- }
-
- struct OffsetWidget : DisableOutputLimitModuleWidget {
- static constexpr int hp = 3;
-
- OffsetWidget(Offset* module) : DisableOutputLimitModuleWidget(module) {
- box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
-
- {
- SVGPanel *panel = new SVGPanel();
- panel->box.size = box.size;
- panel->setBackground(SVG::load(assetPlugin(plugin, "res/Offset.svg")));
- addChild(panel);
- }
-
- addChild(Widget::create<ScrewSilver>(Vec(0, 0)));
- addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 15, 365)));
-
- // generated by svg_widgets.rb
- auto offsetParamPosition = Vec(8.0, 40.0);
- auto scaleParamPosition = Vec(8.0, 152.0);
-
- auto offsetInputPosition = Vec(10.5, 81.0);
- auto scaleInputPosition = Vec(10.5, 193.0);
- auto inInputPosition = Vec(10.5, 243.0);
-
- auto outOutputPosition = Vec(10.5, 281.0);
- // end generated by svg_widgets.rb
-
- addParam(ParamWidget::create<Knob29>(offsetParamPosition, module, Offset::OFFSET_PARAM, -1.0, 1.0, 0.0));
- addParam(ParamWidget::create<Knob29>(scaleParamPosition, module, Offset::SCALE_PARAM, -1.0, 1.0, 0.316));
-
- addInput(Port::create<Port24>(offsetInputPosition, Port::INPUT, module, Offset::OFFSET_INPUT));
- addInput(Port::create<Port24>(scaleInputPosition, Port::INPUT, module, Offset::SCALE_INPUT));
- addInput(Port::create<Port24>(inInputPosition, Port::INPUT, module, Offset::IN_INPUT));
-
- addOutput(Port::create<Port24>(outOutputPosition, Port::OUTPUT, module, Offset::OUT_OUTPUT));
- }
- };
-
- RACK_PLUGIN_MODEL_INIT(Bogaudio, Offset) {
- Model *modelOffset = createModel<Offset, OffsetWidget>("Bogaudio-Offset", "Offset", "CV offset and scaler", ATTENUATOR_TAG);
- return modelOffset;
- }
|