|
-
- #include "LLFO.hpp"
- #include "dsp/pitch.hpp"
-
- void LLFO::onReset() {
- _resetTrigger.reset();
- _modulationStep = modulationSteps;
- }
-
- void LLFO::onSampleRateChange() {
- _phasor.setSampleRate(engineGetSampleRate());
- _modulationStep = modulationSteps;
- }
-
- void LLFO::step() {
- lights[SLOW_LIGHT].value = _slowMode = params[SLOW_PARAM].value > 0.5f;
-
- lights[SINE_LIGHT].value = _wave == SINE_WAVE;
- lights[TRIANGLE_LIGHT].value = _wave == TRIANGLE_WAVE;
- lights[RAMP_UP_LIGHT].value = _wave == RAMP_UP_WAVE;
- lights[RAMP_DOWN_LIGHT].value = _wave == RAMP_DOWN_WAVE;
- lights[SQUARE_LIGHT].value = _wave == SQUARE_WAVE;
- lights[PULSE_LIGHT].value = _wave == PULSE_WAVE;
- if (!outputs[OUT_OUTPUT].active) {
- return;
- }
-
- ++_modulationStep;
- if (_modulationStep >= modulationSteps) {
- _modulationStep = 0;
-
- float frequency = params[FREQUENCY_PARAM].value;
- if (inputs[PITCH_INPUT].active) {
- frequency += inputs[PITCH_INPUT].value;
- }
- if (_slowMode) {
- frequency -= 8.0f;
- }
- else {
- frequency -= 4.0f;
- }
- frequency = cvToFrequency(frequency);
- if (frequency > 2000.0f) {
- frequency = 2000.0f;
- }
- _phasor.setFrequency(frequency);
-
- _wave = (Wave)int32_t(params[WAVE_PARAM].value);
- _invert = false;
- switch (_wave) {
- case SINE_WAVE: {
- _oscillator = &_sine;
- break;
- }
- case TRIANGLE_WAVE: {
- _oscillator = &_triangle;
- break;
- }
- case RAMP_UP_WAVE: {
- _oscillator = &_ramp;
- break;
- }
- case RAMP_DOWN_WAVE: {
- _oscillator = &_ramp;
- _invert = true;
- break;
- }
- case SQUARE_WAVE: {
- _oscillator = &_square;
- _square.setPulseWidth(0.5f);
- break;
- }
- case PULSE_WAVE: {
- _oscillator = &_square;
- _square.setPulseWidth(0.1f);
- break;
- }
- }
-
- _offset = params[OFFSET_PARAM].value * 5.0f;
- _scale = params[SCALE_PARAM].value;
- }
-
- if (_resetTrigger.next(inputs[RESET_INPUT].value)) {
- _phasor.resetPhase();
- }
- _phasor.advancePhase();
- float sample = _oscillator->nextFromPhasor(_phasor) * amplitude * _scale;
- if (_invert) {
- sample = -sample;
- }
- sample += _offset;
- outputs[OUT_OUTPUT].value = sample;
- }
-
- struct LLFOWidget : ModuleWidget {
- static constexpr int hp = 3;
-
- LLFOWidget(LLFO* module) : ModuleWidget(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/LLFO.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 frequencyParamPosition = Vec(9.5, 27.0);
- auto slowParamPosition = Vec(34.0, 71.0);
- auto waveParamPosition = Vec(18.0, 126.0);
- auto offsetParamPosition = Vec(14.5, 158.5);
- auto scaleParamPosition = Vec(14.5, 199.5);
-
- auto pitchInputPosition = Vec(10.5, 231.0);
- auto resetInputPosition = Vec(10.5, 266.0);
-
- auto outOutputPosition = Vec(10.5, 304.0);
-
- auto slowLightPosition = Vec(2.0, 72.0);
- auto sineLightPosition = Vec(2.0, 89.0);
- auto rampUpLightPosition = Vec(2.0, 102.0);
- auto squareLightPosition = Vec(2.0, 115.0);
- auto triangleLightPosition = Vec(24.0, 89.0);
- auto rampDownLightPosition = Vec(24.0, 102.0);
- auto pulseLightPosition = Vec(24.0, 115.0);
- // end generated by svg_widgets.rb
-
- addParam(ParamWidget::create<Knob26>(frequencyParamPosition, module, LLFO::FREQUENCY_PARAM, -8.0, 5.0, 0.0));
- addParam(ParamWidget::create<StatefulButton9>(slowParamPosition, module, LLFO::SLOW_PARAM, 0.0, 1.0, 0.0));
- addParam(ParamWidget::create<StatefulButton9>(waveParamPosition, module, LLFO::WAVE_PARAM, 0.0, 5.0, 0.0));
- addParam(ParamWidget::create<Knob16>(offsetParamPosition, module, LLFO::OFFSET_PARAM, -1.0, 1.0, 0.0));
- addParam(ParamWidget::create<Knob16>(scaleParamPosition, module, LLFO::SCALE_PARAM, 0.0, 1.0, 1.0));
-
- addInput(Port::create<Port24>(pitchInputPosition, Port::INPUT, module, LLFO::PITCH_INPUT));
- addInput(Port::create<Port24>(resetInputPosition, Port::INPUT, module, LLFO::RESET_INPUT));
-
- addOutput(Port::create<Port24>(outOutputPosition, Port::OUTPUT, module, LLFO::OUT_OUTPUT));
-
- addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(slowLightPosition, module, LLFO::SLOW_LIGHT));
- addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(sineLightPosition, module, LLFO::SINE_LIGHT));
- addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(rampUpLightPosition, module, LLFO::RAMP_UP_LIGHT));
- addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(squareLightPosition, module, LLFO::SQUARE_LIGHT));
- addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(triangleLightPosition, module, LLFO::TRIANGLE_LIGHT));
- addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(rampDownLightPosition, module, LLFO::RAMP_DOWN_LIGHT));
- addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(pulseLightPosition, module, LLFO::PULSE_LIGHT));
- }
- };
-
- RACK_PLUGIN_MODEL_INIT(Bogaudio, LLFO) {
- Model *modelLLFO = createModel<LLFO, LLFOWidget>("Bogaudio-LLFO", "LLFO", "compact LFO", LFO_TAG);
- return modelLLFO;
- }
|