| @@ -27,13 +27,14 @@ struct _8vert : Module { | |||||
| } | } | ||||
| void step() override { | void step() override { | ||||
| float deltaTime = APP->engine->getSampleTime(); | |||||
| float lastIn = 10.f; | float lastIn = 10.f; | ||||
| for (int i = 0; i < 8; i++) { | for (int i = 0; i < 8; i++) { | ||||
| lastIn = inputs[i].getNormalVoltage(lastIn); | lastIn = inputs[i].getNormalVoltage(lastIn); | ||||
| float out = lastIn * params[i].value; | float out = lastIn * params[i].value; | ||||
| outputs[i].value = out; | outputs[i].value = out; | ||||
| lights[2*i + 0].setBrightnessSmooth(std::max(0.f, out / 5.f)); | |||||
| lights[2*i + 1].setBrightnessSmooth(std::max(0.f, -out / 5.f)); | |||||
| lights[2*i + 0].setSmoothBrightness(out / 5.f, deltaTime); | |||||
| lights[2*i + 1].setSmoothBrightness(-out / 5.f, deltaTime); | |||||
| } | } | ||||
| } | } | ||||
| }; | }; | ||||
| @@ -36,10 +36,10 @@ struct ADSR : Module { | |||||
| ADSR() { | ADSR() { | ||||
| config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); | config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); | ||||
| params[ATTACK_PARAM].config(0.f, 1.f, 0.5f); | |||||
| params[DECAY_PARAM].config(0.f, 1.f, 0.5f); | |||||
| params[SUSTAIN_PARAM].config(0.f, 1.f, 0.5f); | |||||
| params[RELEASE_PARAM].config(0.f, 1.f, 0.5f); | |||||
| params[ATTACK_PARAM].config(0.f, 1.f, 0.5f, "Attack"); | |||||
| params[DECAY_PARAM].config(0.f, 1.f, 0.5f, "Decay"); | |||||
| params[SUSTAIN_PARAM].config(0.f, 1.f, 0.5f, "Sustain"); | |||||
| params[RELEASE_PARAM].config(0.f, 1.f, 0.5f, "Release"); | |||||
| } | } | ||||
| void step() override { | void step() override { | ||||
| @@ -108,11 +108,12 @@ struct LFO : Module { | |||||
| } | } | ||||
| void step() override { | void step() override { | ||||
| float deltaTime = APP->engine->getSampleTime(); | |||||
| oscillator.setPitch(params[FREQ_PARAM].value + params[FM1_PARAM].value * inputs[FM1_INPUT].value + params[FM2_PARAM].value * inputs[FM2_INPUT].value); | oscillator.setPitch(params[FREQ_PARAM].value + params[FM1_PARAM].value * inputs[FM1_INPUT].value + params[FM2_PARAM].value * inputs[FM2_INPUT].value); | ||||
| oscillator.setPulseWidth(params[PW_PARAM].value + params[PWM_PARAM].value * inputs[PW_INPUT].value / 10.f); | oscillator.setPulseWidth(params[PW_PARAM].value + params[PWM_PARAM].value * inputs[PW_INPUT].value / 10.f); | ||||
| oscillator.offset = (params[OFFSET_PARAM].value > 0.f); | oscillator.offset = (params[OFFSET_PARAM].value > 0.f); | ||||
| oscillator.invert = (params[INVERT_PARAM].value <= 0.f); | oscillator.invert = (params[INVERT_PARAM].value <= 0.f); | ||||
| oscillator.step(APP->engine->getSampleTime()); | |||||
| oscillator.step(deltaTime); | |||||
| oscillator.setReset(inputs[RESET_INPUT].value); | oscillator.setReset(inputs[RESET_INPUT].value); | ||||
| outputs[SIN_OUTPUT].value = 5.f * oscillator.sin(); | outputs[SIN_OUTPUT].value = 5.f * oscillator.sin(); | ||||
| @@ -120,8 +121,8 @@ struct LFO : Module { | |||||
| outputs[SAW_OUTPUT].value = 5.f * oscillator.saw(); | outputs[SAW_OUTPUT].value = 5.f * oscillator.saw(); | ||||
| outputs[SQR_OUTPUT].value = 5.f * oscillator.sqr(); | outputs[SQR_OUTPUT].value = 5.f * oscillator.sqr(); | ||||
| lights[PHASE_POS_LIGHT].setBrightnessSmooth(std::max(0.f, oscillator.light())); | |||||
| lights[PHASE_NEG_LIGHT].setBrightnessSmooth(std::max(0.f, -oscillator.light())); | |||||
| lights[PHASE_POS_LIGHT].setSmoothBrightness(oscillator.light(), deltaTime); | |||||
| lights[PHASE_NEG_LIGHT].setSmoothBrightness(-oscillator.light(), deltaTime); | |||||
| } | } | ||||
| }; | }; | ||||
| @@ -202,10 +203,11 @@ struct LFO2 : Module { | |||||
| } | } | ||||
| void step() override { | void step() override { | ||||
| float deltaTime = APP->engine->getSampleTime(); | |||||
| oscillator.setPitch(params[FREQ_PARAM].value + params[FM_PARAM].value * inputs[FM_INPUT].value); | oscillator.setPitch(params[FREQ_PARAM].value + params[FM_PARAM].value * inputs[FM_INPUT].value); | ||||
| oscillator.offset = (params[OFFSET_PARAM].value > 0.f); | oscillator.offset = (params[OFFSET_PARAM].value > 0.f); | ||||
| oscillator.invert = (params[INVERT_PARAM].value <= 0.f); | oscillator.invert = (params[INVERT_PARAM].value <= 0.f); | ||||
| oscillator.step(APP->engine->getSampleTime()); | |||||
| oscillator.step(deltaTime); | |||||
| oscillator.setReset(inputs[RESET_INPUT].value); | oscillator.setReset(inputs[RESET_INPUT].value); | ||||
| float wave = params[WAVE_PARAM].value + inputs[WAVE_INPUT].value; | float wave = params[WAVE_PARAM].value + inputs[WAVE_INPUT].value; | ||||
| @@ -219,8 +221,8 @@ struct LFO2 : Module { | |||||
| interp = crossfade(oscillator.saw(), oscillator.sqr(), wave - 2.f); | interp = crossfade(oscillator.saw(), oscillator.sqr(), wave - 2.f); | ||||
| outputs[INTERP_OUTPUT].value = 5.f * interp; | outputs[INTERP_OUTPUT].value = 5.f * interp; | ||||
| lights[PHASE_POS_LIGHT].setBrightnessSmooth(std::max(0.f, oscillator.light())); | |||||
| lights[PHASE_NEG_LIGHT].setBrightnessSmooth(std::max(0.f, -oscillator.light())); | |||||
| lights[PHASE_POS_LIGHT].setSmoothBrightness(oscillator.light(), deltaTime); | |||||
| lights[PHASE_NEG_LIGHT].setSmoothBrightness(-oscillator.light(), deltaTime); | |||||
| } | } | ||||
| }; | }; | ||||
| @@ -118,6 +118,8 @@ struct SEQ3 : Module { | |||||
| } | } | ||||
| void step() override { | void step() override { | ||||
| float deltaTime = APP->engine->getSampleTime(); | |||||
| // Run | // Run | ||||
| if (runningTrigger.process(params[RUN_PARAM].value)) { | if (runningTrigger.process(params[RUN_PARAM].value)) { | ||||
| running = !running; | running = !running; | ||||
| @@ -135,7 +137,7 @@ struct SEQ3 : Module { | |||||
| else { | else { | ||||
| // Internal clock | // Internal clock | ||||
| float clockTime = std::pow(2.0f, params[CLOCK_PARAM].value + inputs[CLOCK_INPUT].value); | float clockTime = std::pow(2.0f, params[CLOCK_PARAM].value + inputs[CLOCK_INPUT].value); | ||||
| phase += clockTime * APP->engine->getSampleTime(); | |||||
| phase += clockTime * deltaTime; | |||||
| if (phase >= 1.0f) { | if (phase >= 1.0f) { | ||||
| setIndex(index + 1); | setIndex(index + 1); | ||||
| } | } | ||||
| @@ -154,7 +156,7 @@ struct SEQ3 : Module { | |||||
| gates[i] = !gates[i]; | gates[i] = !gates[i]; | ||||
| } | } | ||||
| outputs[GATE_OUTPUT + i].value = (running && gateIn && i == index && gates[i]) ? 10.0f : 0.0f; | outputs[GATE_OUTPUT + i].value = (running && gateIn && i == index && gates[i]) ? 10.0f : 0.0f; | ||||
| lights[GATE_LIGHTS + i].setBrightnessSmooth((gateIn && i == index) ? (gates[i] ? 1.f : 0.33) : (gates[i] ? 0.66 : 0.0)); | |||||
| lights[GATE_LIGHTS + i].setSmoothBrightness((gateIn && i == index) ? (gates[i] ? 1.f : 0.33) : (gates[i] ? 0.66 : 0.0), deltaTime); | |||||
| } | } | ||||
| // Outputs | // Outputs | ||||
| @@ -163,8 +165,8 @@ struct SEQ3 : Module { | |||||
| outputs[ROW3_OUTPUT].value = params[ROW3_PARAM + index].value; | outputs[ROW3_OUTPUT].value = params[ROW3_PARAM + index].value; | ||||
| outputs[GATES_OUTPUT].value = (gateIn && gates[index]) ? 10.0f : 0.0f; | outputs[GATES_OUTPUT].value = (gateIn && gates[index]) ? 10.0f : 0.0f; | ||||
| lights[RUNNING_LIGHT].value = (running); | lights[RUNNING_LIGHT].value = (running); | ||||
| lights[RESET_LIGHT].setBrightnessSmooth(resetTrigger.isHigh()); | |||||
| lights[GATES_LIGHT].setBrightnessSmooth(gateIn); | |||||
| lights[RESET_LIGHT].setSmoothBrightness(resetTrigger.isHigh(), deltaTime); | |||||
| lights[GATES_LIGHT].setSmoothBrightness(gateIn, deltaTime); | |||||
| lights[ROW_LIGHTS].value = outputs[ROW1_OUTPUT].value / 10.0f; | lights[ROW_LIGHTS].value = outputs[ROW1_OUTPUT].value / 10.0f; | ||||
| lights[ROW_LIGHTS + 1].value = outputs[ROW2_OUTPUT].value / 10.0f; | lights[ROW_LIGHTS + 1].value = outputs[ROW2_OUTPUT].value / 10.0f; | ||||
| lights[ROW_LIGHTS + 2].value = outputs[ROW3_OUTPUT].value / 10.0f; | lights[ROW_LIGHTS + 2].value = outputs[ROW3_OUTPUT].value / 10.0f; | ||||
| @@ -21,7 +21,7 @@ struct Sum : Module { | |||||
| }; | }; | ||||
| int frame = 0; | int frame = 0; | ||||
| dsp::VUMeter2 vuMeter; | |||||
| dsp::VuMeter2 vuMeter; | |||||
| Sum() { | Sum() { | ||||
| config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); | config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); | ||||
| @@ -8,9 +8,8 @@ struct Unity : Module { | |||||
| NUM_PARAMS | NUM_PARAMS | ||||
| }; | }; | ||||
| enum InputIds { | enum InputIds { | ||||
| IN1_INPUT, | |||||
| IN2_INPUT = IN1_INPUT + 6, | |||||
| NUM_INPUTS = IN2_INPUT + 6 | |||||
| ENUMS(IN_INPUTS, 2 * 6), | |||||
| NUM_INPUTS | |||||
| }; | }; | ||||
| enum OutputIds { | enum OutputIds { | ||||
| MIX1_OUTPUT, | MIX1_OUTPUT, | ||||
| @@ -20,28 +19,32 @@ struct Unity : Module { | |||||
| NUM_OUTPUTS | NUM_OUTPUTS | ||||
| }; | }; | ||||
| enum LightIds { | enum LightIds { | ||||
| VU1_LIGHT, | |||||
| VU2_LIGHT = VU1_LIGHT + 5, | |||||
| NUM_LIGHTS = VU2_LIGHT + 5 | |||||
| ENUMS(VU_LIGHTS, 2 * 5), | |||||
| NUM_LIGHTS | |||||
| }; | }; | ||||
| bool merge = false; | bool merge = false; | ||||
| dsp::VuMeter2 vuMeters[2]; | |||||
| dsp::Counter vuCounter; | |||||
| Unity() { | Unity() { | ||||
| config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); | config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); | ||||
| params[AVG1_PARAM].config(0.0, 1.0, 0.0, "Ch 1 average mode"); | params[AVG1_PARAM].config(0.0, 1.0, 0.0, "Ch 1 average mode"); | ||||
| params[AVG2_PARAM].config(0.0, 1.0, 0.0, "Ch 2 average mode"); | params[AVG2_PARAM].config(0.0, 1.0, 0.0, "Ch 2 average mode"); | ||||
| vuCounter.setPeriod(256); | |||||
| } | } | ||||
| void step() override { | void step() override { | ||||
| float deltaTime = APP->engine->getSampleTime(); | |||||
| float mix[2] = {}; | float mix[2] = {}; | ||||
| int count[2] = {}; | int count[2] = {}; | ||||
| for (int i = 0; i < 2; i++) { | for (int i = 0; i < 2; i++) { | ||||
| // Inputs | // Inputs | ||||
| for (int j = 0; j < 6; j++) { | for (int j = 0; j < 6; j++) { | ||||
| mix[i] += inputs[IN1_INPUT + 6*i + j].value; | |||||
| if (inputs[IN1_INPUT + 6*i + j].active) | |||||
| mix[i] += inputs[IN_INPUTS + 6 * i + j].value; | |||||
| if (inputs[IN_INPUTS + 6 * i + j].active) | |||||
| count[i]++; | count[i]++; | ||||
| } | } | ||||
| } | } | ||||
| @@ -56,18 +59,22 @@ struct Unity : Module { | |||||
| for (int i = 0; i < 2; i++) { | for (int i = 0; i < 2; i++) { | ||||
| // Params | // Params | ||||
| if ((int) params[AVG1_PARAM + i].value == 1 && count[i] > 0) | |||||
| if (count[i] > 0 && (int) std::round(params[AVG1_PARAM + i].value) == 1) | |||||
| mix[i] /= count[i]; | mix[i] /= count[i]; | ||||
| // Outputs | // Outputs | ||||
| outputs[MIX1_OUTPUT + 2*i].value = mix[i]; | |||||
| outputs[INV1_OUTPUT + 2*i].value = -mix[i]; | |||||
| outputs[MIX1_OUTPUT + 2 * i].value = mix[i]; | |||||
| outputs[INV1_OUTPUT + 2 * i].value = -mix[i]; | |||||
| vuMeters[i].process(deltaTime, mix[i] / 10.f); | |||||
| } | |||||
| if (vuCounter.process()) { | |||||
| // Lights | // Lights | ||||
| dsp::VUMeter vuMeter; | |||||
| vuMeter.dBInterval = 6.0f; | |||||
| vuMeter.setValue(mix[i] / 10.0f); | |||||
| for (int j = 0; j < 5; j++) { | |||||
| lights[VU1_LIGHT + 5*i + j].setBrightnessSmooth(vuMeter.getBrightness(j)); | |||||
| for (int i = 0; i < 2; i++) { | |||||
| lights[VU_LIGHTS + 5 * i + 0].setBrightness(vuMeters[i].getBrightness(0.f, 0.f)); | |||||
| for (int j = 1; j < 5; j++) { | |||||
| lights[VU_LIGHTS + 5 * i + j].setBrightness(vuMeters[i].getBrightness(-6.f * (j + 1), -6.f * j)); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -116,34 +123,34 @@ struct UnityWidget : ModuleWidget { | |||||
| addParam(createParam<CKSS>(mm2px(Vec(12.867, 52.961)), module, Unity::AVG1_PARAM)); | addParam(createParam<CKSS>(mm2px(Vec(12.867, 52.961)), module, Unity::AVG1_PARAM)); | ||||
| addParam(createParam<CKSS>(mm2px(Vec(12.867, 107.006)), module, Unity::AVG2_PARAM)); | addParam(createParam<CKSS>(mm2px(Vec(12.867, 107.006)), module, Unity::AVG2_PARAM)); | ||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(2.361, 17.144)), module, Unity::IN1_INPUT + 0)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(19.907, 17.144)), module, Unity::IN1_INPUT + 1)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(2.361, 28.145)), module, Unity::IN1_INPUT + 2)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(19.907, 28.145)), module, Unity::IN1_INPUT + 3)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(2.361, 39.145)), module, Unity::IN1_INPUT + 4)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(19.907, 39.145)), module, Unity::IN1_INPUT + 5)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(2.361, 71.145)), module, Unity::IN2_INPUT + 0)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(19.907, 71.145)), module, Unity::IN2_INPUT + 1)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(2.361, 82.145)), module, Unity::IN2_INPUT + 2)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(19.907, 82.145)), module, Unity::IN2_INPUT + 3)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(2.361, 93.144)), module, Unity::IN2_INPUT + 4)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(19.907, 93.144)), module, Unity::IN2_INPUT + 5)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(2.361, 17.144)), module, Unity::IN_INPUTS + 0 * 6 + 0)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(19.907, 17.144)), module, Unity::IN_INPUTS + 0 * 6 + 1)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(2.361, 28.145)), module, Unity::IN_INPUTS + 0 * 6 + 2)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(19.907, 28.145)), module, Unity::IN_INPUTS + 0 * 6 + 3)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(2.361, 39.145)), module, Unity::IN_INPUTS + 0 * 6 + 4)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(19.907, 39.145)), module, Unity::IN_INPUTS + 0 * 6 + 5)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(2.361, 71.145)), module, Unity::IN_INPUTS + 1 * 6 + 0)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(19.907, 71.145)), module, Unity::IN_INPUTS + 1 * 6 + 1)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(2.361, 82.145)), module, Unity::IN_INPUTS + 1 * 6 + 2)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(19.907, 82.145)), module, Unity::IN_INPUTS + 1 * 6 + 3)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(2.361, 93.144)), module, Unity::IN_INPUTS + 1 * 6 + 4)); | |||||
| addInput(createInput<PJ301MPort>(mm2px(Vec(19.907, 93.144)), module, Unity::IN_INPUTS + 1 * 6 + 5)); | |||||
| addOutput(createOutput<PJ301MPort>(mm2px(Vec(2.361, 54.15)), module, Unity::MIX1_OUTPUT)); | addOutput(createOutput<PJ301MPort>(mm2px(Vec(2.361, 54.15)), module, Unity::MIX1_OUTPUT)); | ||||
| addOutput(createOutput<PJ301MPort>(mm2px(Vec(19.907, 54.15)), module, Unity::INV1_OUTPUT)); | addOutput(createOutput<PJ301MPort>(mm2px(Vec(19.907, 54.15)), module, Unity::INV1_OUTPUT)); | ||||
| addOutput(createOutput<PJ301MPort>(mm2px(Vec(2.361, 108.144)), module, Unity::MIX2_OUTPUT)); | addOutput(createOutput<PJ301MPort>(mm2px(Vec(2.361, 108.144)), module, Unity::MIX2_OUTPUT)); | ||||
| addOutput(createOutput<PJ301MPort>(mm2px(Vec(19.907, 108.144)), module, Unity::INV2_OUTPUT)); | addOutput(createOutput<PJ301MPort>(mm2px(Vec(19.907, 108.144)), module, Unity::INV2_OUTPUT)); | ||||
| addChild(createLight<MediumLight<RedLight>>(mm2px(Vec(13.652, 19.663)), module, Unity::VU1_LIGHT + 0)); | |||||
| addChild(createLight<MediumLight<YellowLight>>(mm2px(Vec(13.652, 25.163)), module, Unity::VU1_LIGHT + 1)); | |||||
| addChild(createLight<MediumLight<GreenLight>>(mm2px(Vec(13.652, 30.663)), module, Unity::VU1_LIGHT + 2)); | |||||
| addChild(createLight<MediumLight<GreenLight>>(mm2px(Vec(13.652, 36.162)), module, Unity::VU1_LIGHT + 3)); | |||||
| addChild(createLight<MediumLight<GreenLight>>(mm2px(Vec(13.652, 41.662)), module, Unity::VU1_LIGHT + 4)); | |||||
| addChild(createLight<MediumLight<RedLight>>(mm2px(Vec(13.652, 73.663)), module, Unity::VU2_LIGHT + 0)); | |||||
| addChild(createLight<MediumLight<YellowLight>>(mm2px(Vec(13.652, 79.163)), module, Unity::VU2_LIGHT + 1)); | |||||
| addChild(createLight<MediumLight<GreenLight>>(mm2px(Vec(13.652, 84.663)), module, Unity::VU2_LIGHT + 2)); | |||||
| addChild(createLight<MediumLight<GreenLight>>(mm2px(Vec(13.652, 90.162)), module, Unity::VU2_LIGHT + 3)); | |||||
| addChild(createLight<MediumLight<GreenLight>>(mm2px(Vec(13.652, 95.662)), module, Unity::VU2_LIGHT + 4)); | |||||
| addChild(createLight<MediumLight<RedLight>>(mm2px(Vec(13.652, 19.663)), module, Unity::VU_LIGHTS + 0 * 5 + 0)); | |||||
| addChild(createLight<MediumLight<YellowLight>>(mm2px(Vec(13.652, 25.163)), module, Unity::VU_LIGHTS + 0 * 5 + 1)); | |||||
| addChild(createLight<MediumLight<GreenLight>>(mm2px(Vec(13.652, 30.663)), module, Unity::VU_LIGHTS + 0 * 5 + 2)); | |||||
| addChild(createLight<MediumLight<GreenLight>>(mm2px(Vec(13.652, 36.162)), module, Unity::VU_LIGHTS + 0 * 5 + 3)); | |||||
| addChild(createLight<MediumLight<GreenLight>>(mm2px(Vec(13.652, 41.662)), module, Unity::VU_LIGHTS + 0 * 5 + 4)); | |||||
| addChild(createLight<MediumLight<RedLight>>(mm2px(Vec(13.652, 73.663)), module, Unity::VU_LIGHTS + 1 * 5 + 0)); | |||||
| addChild(createLight<MediumLight<YellowLight>>(mm2px(Vec(13.652, 79.163)), module, Unity::VU_LIGHTS + 1 * 5 + 1)); | |||||
| addChild(createLight<MediumLight<GreenLight>>(mm2px(Vec(13.652, 84.663)), module, Unity::VU_LIGHTS + 1 * 5 + 2)); | |||||
| addChild(createLight<MediumLight<GreenLight>>(mm2px(Vec(13.652, 90.162)), module, Unity::VU_LIGHTS + 1 * 5 + 3)); | |||||
| addChild(createLight<MediumLight<GreenLight>>(mm2px(Vec(13.652, 95.662)), module, Unity::VU_LIGHTS + 1 * 5 + 4)); | |||||
| } | } | ||||
| void appendContextMenu(Menu *menu) override { | void appendContextMenu(Menu *menu) override { | ||||
| @@ -80,11 +80,11 @@ struct VCF : Module { | |||||
| VCF() { | VCF() { | ||||
| config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS); | config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS); | ||||
| params[FREQ_PARAM].config(0.f, 1.f, 0.5f); | |||||
| params[FINE_PARAM].config(0.f, 1.f, 0.5f); | |||||
| params[RES_PARAM].config(0.f, 1.f, 0.f); | |||||
| params[FREQ_CV_PARAM].config(-1.f, 1.f, 0.f); | |||||
| params[DRIVE_PARAM].config(0.f, 1.f, 0.f); | |||||
| params[FREQ_PARAM].config(0.f, 1.f, 0.5f, "Frequency"); | |||||
| params[FINE_PARAM].config(0.f, 1.f, 0.5f, "Fine frequency"); | |||||
| params[RES_PARAM].config(0.f, 1.f, 0.f, "Resonance"); | |||||
| params[FREQ_CV_PARAM].config(-1.f, 1.f, 0.f, "Frequency modulation"); | |||||
| params[DRIVE_PARAM].config(0.f, 1.f, 0.f, "Drive"); | |||||
| } | } | ||||
| void onReset() override { | void onReset() override { | ||||
| @@ -205,6 +205,7 @@ struct VCO : Module { | |||||
| } | } | ||||
| void step() override { | void step() override { | ||||
| float deltaTime = APP->engine->getSampleTime(); | |||||
| oscillator.analog = params[MODE_PARAM].value > 0.f; | oscillator.analog = params[MODE_PARAM].value > 0.f; | ||||
| oscillator.soft = params[SYNC_PARAM].value <= 0.f; | oscillator.soft = params[SYNC_PARAM].value <= 0.f; | ||||
| @@ -217,7 +218,7 @@ struct VCO : Module { | |||||
| oscillator.setPulseWidth(params[PW_PARAM].value + params[PWM_PARAM].value * inputs[PW_INPUT].value / 10.f); | oscillator.setPulseWidth(params[PW_PARAM].value + params[PWM_PARAM].value * inputs[PW_INPUT].value / 10.f); | ||||
| oscillator.syncEnabled = inputs[SYNC_INPUT].active; | oscillator.syncEnabled = inputs[SYNC_INPUT].active; | ||||
| oscillator.process(APP->engine->getSampleTime(), inputs[SYNC_INPUT].value); | |||||
| oscillator.process(deltaTime, inputs[SYNC_INPUT].value); | |||||
| // Set output | // Set output | ||||
| if (outputs[SIN_OUTPUT].active) | if (outputs[SIN_OUTPUT].active) | ||||
| @@ -229,8 +230,8 @@ struct VCO : Module { | |||||
| if (outputs[SQR_OUTPUT].active) | if (outputs[SQR_OUTPUT].active) | ||||
| outputs[SQR_OUTPUT].value = 5.f * oscillator.sqr(); | outputs[SQR_OUTPUT].value = 5.f * oscillator.sqr(); | ||||
| lights[PHASE_POS_LIGHT].setBrightnessSmooth(std::fmax(0.f, oscillator.light())); | |||||
| lights[PHASE_NEG_LIGHT].setBrightnessSmooth(std::fmax(0.f, -oscillator.light())); | |||||
| lights[PHASE_POS_LIGHT].setSmoothBrightness(oscillator.light(), deltaTime); | |||||
| lights[PHASE_NEG_LIGHT].setSmoothBrightness(-oscillator.light(), deltaTime); | |||||
| } | } | ||||
| }; | }; | ||||
| @@ -309,6 +310,7 @@ struct VCO2 : Module { | |||||
| } | } | ||||
| void step() override { | void step() override { | ||||
| float deltaTime = APP->engine->getSampleTime(); | |||||
| oscillator.analog = params[MODE_PARAM].value > 0.f; | oscillator.analog = params[MODE_PARAM].value > 0.f; | ||||
| oscillator.soft = params[SYNC_PARAM].value <= 0.f; | oscillator.soft = params[SYNC_PARAM].value <= 0.f; | ||||
| @@ -316,7 +318,7 @@ struct VCO2 : Module { | |||||
| oscillator.setPitch(0.f, pitchCv); | oscillator.setPitch(0.f, pitchCv); | ||||
| oscillator.syncEnabled = inputs[SYNC_INPUT].active; | oscillator.syncEnabled = inputs[SYNC_INPUT].active; | ||||
| oscillator.process(APP->engine->getSampleTime(), inputs[SYNC_INPUT].value); | |||||
| oscillator.process(deltaTime, inputs[SYNC_INPUT].value); | |||||
| // Set output | // Set output | ||||
| float wave = clamp(params[WAVE_PARAM].value + inputs[WAVE_INPUT].value, 0.f, 3.f); | float wave = clamp(params[WAVE_PARAM].value + inputs[WAVE_INPUT].value, 0.f, 3.f); | ||||
| @@ -329,8 +331,8 @@ struct VCO2 : Module { | |||||
| out = crossfade(oscillator.saw(), oscillator.sqr(), wave - 2.f); | out = crossfade(oscillator.saw(), oscillator.sqr(), wave - 2.f); | ||||
| outputs[OUT_OUTPUT].value = 5.f * out; | outputs[OUT_OUTPUT].value = 5.f * out; | ||||
| lights[PHASE_POS_LIGHT].setBrightnessSmooth(std::fmax(0.f, oscillator.light())); | |||||
| lights[PHASE_NEG_LIGHT].setBrightnessSmooth(std::fmax(0.f, -oscillator.light())); | |||||
| lights[PHASE_POS_LIGHT].setSmoothBrightness(oscillator.light(), deltaTime); | |||||
| lights[PHASE_NEG_LIGHT].setSmoothBrightness(-oscillator.light(), deltaTime); | |||||
| } | } | ||||
| }; | }; | ||||
| @@ -18,43 +18,26 @@ struct Viz : Module { | |||||
| }; | }; | ||||
| int channels = 0; | int channels = 0; | ||||
| dsp::VUMeter2 vuMeter[16]; | |||||
| int frame = 0; | int frame = 0; | ||||
| dsp::Counter counter; | |||||
| Viz() { | Viz() { | ||||
| config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); | config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); | ||||
| for (int c = 0; c < 16; c++) { | |||||
| vuMeter[c].lambda = 1 / 0.1f; | |||||
| } | |||||
| counter.period = 16; | |||||
| } | } | ||||
| void step() override { | void step() override { | ||||
| if (frame % 16 == 0) { | |||||
| if (counter.process()) { | |||||
| channels = inputs[POLY_INPUT].getChannels(); | channels = inputs[POLY_INPUT].getChannels(); | ||||
| float deltaTime = APP->engine->getSampleTime() * 16; | |||||
| float deltaTime = APP->engine->getSampleTime() * counter.period; | |||||
| // Process VU meters | |||||
| for (int c = 0; c < channels; c++) { | |||||
| float value = inputs[POLY_INPUT].getVoltage(c) / 10.f; | |||||
| vuMeter[c].process(deltaTime, value); | |||||
| } | |||||
| for (int c = channels; c < 16; c++) { | |||||
| vuMeter[c].reset(); | |||||
| } | |||||
| } | |||||
| if (frame % 256 == 0) { | |||||
| // Set lights | |||||
| for (int c = 0; c < 16; c++) { | for (int c = 0; c < 16; c++) { | ||||
| float green = vuMeter[c].getBrightness(-24.f, -6.f); | |||||
| float red = vuMeter[c].getBrightness(-6.f, 0.f); | |||||
| lights[VU_LIGHTS + c*2 + 0].setBrightness(green - red); | |||||
| lights[VU_LIGHTS + c*2 + 1].setBrightness(red); | |||||
| float v = inputs[POLY_INPUT].getVoltage(c) / 10.f; | |||||
| lights[VU_LIGHTS + c*2 + 0].setSmoothBrightness(v, deltaTime); | |||||
| lights[VU_LIGHTS + c*2 + 1].setSmoothBrightness(-v, deltaTime); | |||||
| } | } | ||||
| } | } | ||||
| frame++; | |||||
| } | } | ||||
| }; | }; | ||||