Browse Source

Update VCO to Rack v1 API

tags/v1.0.1
Andrew Belt 5 years ago
parent
commit
cd5338e4ee
1 changed files with 48 additions and 32 deletions
  1. +48
    -32
      src/VCO.cpp

+ 48
- 32
src/VCO.cpp View File

@@ -60,7 +60,7 @@ struct VoltageControlledOscillator {
// Adjust pitch slew
if (++pitchSlewIndex > 32) {
const float pitchSlewTau = 100.0f; // Time constant for leaky integrator in seconds
pitchSlew += (randomNormal() - pitchSlew / pitchSlewTau) * engineGetSampleTime();
pitchSlew += (random::normal() - pitchSlew / pitchSlewTau) * context()->engine->getSampleTime();
pitchSlewIndex = 0;
}
}
@@ -140,7 +140,7 @@ struct VoltageControlledOscillator {

// Advance phase
phase += deltaPhase / OVERSAMPLE;
phase = eucmod(phase, 1.0f);
phase = eucMod(phase, 1.0f);
}
}

@@ -195,7 +195,16 @@ struct VCO : Module {

VoltageControlledOscillator<16, 16> oscillator;

VCO() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
VCO() {
setup(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
params[MODE_PARAM].setup(0.f, 1.f, 1.f);
params[SYNC_PARAM].setup(0.f, 1.f, 1.f);
params[FREQ_PARAM].setup(-54.0f, 54.0f, 0.0f, "Frequency", " Hz", std::pow(2, 1/12.f), 261.626f);
params[FINE_PARAM].setup(-1.0f, 1.0f, 0.0f, "Fine frequency");
params[FM_PARAM].setup(0.0f, 1.0f, 0.0f, "Frequency modulation");
params[PW_PARAM].setup(0.0f, 1.0f, 0.5f, "Pulse width", "%", 0.f, 100.f);
params[PWM_PARAM].setup(0.0f, 1.0f, 0.0f, "Pulse width modulation", "%", 0.f, 100.f);
}
void step() override;
};

@@ -213,7 +222,7 @@ void VCO::step() {
oscillator.setPulseWidth(params[PW_PARAM].value + params[PWM_PARAM].value * inputs[PW_INPUT].value / 10.0f);
oscillator.syncEnabled = inputs[SYNC_INPUT].active;

oscillator.process(engineGetSampleTime(), inputs[SYNC_INPUT].value);
oscillator.process(context()->engine->getSampleTime(), inputs[SYNC_INPUT].value);

// Set output
if (outputs[SIN_OUTPUT].active)
@@ -235,31 +244,31 @@ struct VCOWidget : ModuleWidget {
};

VCOWidget::VCOWidget(VCO *module) : ModuleWidget(module) {
setPanel(SVG::load(assetPlugin(plugin, "res/VCO-1.svg")));
setPanel(SVG::load(asset::plugin(plugin, "res/VCO-1.svg")));

addChild(createWidget<ScrewSilver>(Vec(15, 0)));
addChild(createWidget<ScrewSilver>(Vec(box.size.x-30, 0)));
addChild(createWidget<ScrewSilver>(Vec(15, 365)));
addChild(createWidget<ScrewSilver>(Vec(box.size.x-30, 365)));

addParam(createParam<CKSS>(Vec(15, 77), module, VCO::MODE_PARAM, 0.0f, 1.0f, 1.0f));
addParam(createParam<CKSS>(Vec(119, 77), module, VCO::SYNC_PARAM, 0.0f, 1.0f, 1.0f));
addParam(createParam<CKSS>(Vec(15, 77), module, VCO::MODE_PARAM));
addParam(createParam<CKSS>(Vec(119, 77), module, VCO::SYNC_PARAM));

addParam(createParam<RoundHugeBlackKnob>(Vec(47, 61), module, VCO::FREQ_PARAM, -54.0f, 54.0f, 0.0f));
addParam(createParam<RoundLargeBlackKnob>(Vec(23, 143), module, VCO::FINE_PARAM, -1.0f, 1.0f, 0.0f));
addParam(createParam<RoundLargeBlackKnob>(Vec(91, 143), module, VCO::PW_PARAM, 0.0f, 1.0f, 0.5f));
addParam(createParam<RoundLargeBlackKnob>(Vec(23, 208), module, VCO::FM_PARAM, 0.0f, 1.0f, 0.0f));
addParam(createParam<RoundLargeBlackKnob>(Vec(91, 208), module, VCO::PWM_PARAM, 0.0f, 1.0f, 0.0f));
addParam(createParam<RoundHugeBlackKnob>(Vec(47, 61), module, VCO::FREQ_PARAM));
addParam(createParam<RoundLargeBlackKnob>(Vec(23, 143), module, VCO::FINE_PARAM));
addParam(createParam<RoundLargeBlackKnob>(Vec(91, 143), module, VCO::PW_PARAM));
addParam(createParam<RoundLargeBlackKnob>(Vec(23, 208), module, VCO::FM_PARAM));
addParam(createParam<RoundLargeBlackKnob>(Vec(91, 208), module, VCO::PWM_PARAM));

addInput(createPort<PJ301MPort>(Vec(11, 276), PortWidget::INPUT, module, VCO::PITCH_INPUT));
addInput(createPort<PJ301MPort>(Vec(45, 276), PortWidget::INPUT, module, VCO::FM_INPUT));
addInput(createPort<PJ301MPort>(Vec(80, 276), PortWidget::INPUT, module, VCO::SYNC_INPUT));
addInput(createPort<PJ301MPort>(Vec(114, 276), PortWidget::INPUT, module, VCO::PW_INPUT));
addInput(createInput<PJ301MPort>(Vec(11, 276), module, VCO::PITCH_INPUT));
addInput(createInput<PJ301MPort>(Vec(45, 276), module, VCO::FM_INPUT));
addInput(createInput<PJ301MPort>(Vec(80, 276), module, VCO::SYNC_INPUT));
addInput(createInput<PJ301MPort>(Vec(114, 276), module, VCO::PW_INPUT));

addOutput(createPort<PJ301MPort>(Vec(11, 320), PortWidget::OUTPUT, module, VCO::SIN_OUTPUT));
addOutput(createPort<PJ301MPort>(Vec(45, 320), PortWidget::OUTPUT, module, VCO::TRI_OUTPUT));
addOutput(createPort<PJ301MPort>(Vec(80, 320), PortWidget::OUTPUT, module, VCO::SAW_OUTPUT));
addOutput(createPort<PJ301MPort>(Vec(114, 320), PortWidget::OUTPUT, module, VCO::SQR_OUTPUT));
addOutput(createOutput<PJ301MPort>(Vec(11, 320), module, VCO::SIN_OUTPUT));
addOutput(createOutput<PJ301MPort>(Vec(45, 320), module, VCO::TRI_OUTPUT));
addOutput(createOutput<PJ301MPort>(Vec(80, 320), module, VCO::SAW_OUTPUT));
addOutput(createOutput<PJ301MPort>(Vec(114, 320), module, VCO::SQR_OUTPUT));

addChild(createLight<SmallLight<GreenRedLight>>(Vec(99, 42.5f), module, VCO::PHASE_POS_LIGHT));
}
@@ -295,7 +304,14 @@ struct VCO2 : Module {

VoltageControlledOscillator<8, 8> oscillator;

VCO2() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
VCO2() {
setup(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
params[MODE_PARAM].setup(0.f, 1.f, 1.f);
params[SYNC_PARAM].setup(0.f, 1.f, 1.f);
params[FREQ_PARAM].setup(-54.0f, 54.0f, 0.0f, "Frequency", " Hz", std::pow(2, 1/12.f), 261.626f);
params[WAVE_PARAM].setup(0.0f, 3.0f, 1.5f, "Wave");
params[FM_PARAM].setup(0.0f, 1.0f, 0.0f, "Frequency modulation");
}
void step() override;
};

@@ -308,7 +324,7 @@ void VCO2::step() {
oscillator.setPitch(0.0f, pitchCv);
oscillator.syncEnabled = inputs[SYNC_INPUT].active;

oscillator.process(engineGetSampleTime(), inputs[SYNC_INPUT].value);
oscillator.process(context()->engine->getSampleTime(), inputs[SYNC_INPUT].value);

// Set output
float wave = clamp(params[WAVE_PARAM].value + inputs[WAVE_INPUT].value, 0.0f, 3.0f);
@@ -331,25 +347,25 @@ struct VCO2Widget : ModuleWidget {
};

VCO2Widget::VCO2Widget(VCO2 *module) : ModuleWidget(module) {
setPanel(SVG::load(assetPlugin(plugin, "res/VCO-2.svg")));
setPanel(SVG::load(asset::plugin(plugin, "res/VCO-2.svg")));

addChild(createWidget<ScrewSilver>(Vec(15, 0)));
addChild(createWidget<ScrewSilver>(Vec(box.size.x-30, 0)));
addChild(createWidget<ScrewSilver>(Vec(15, 365)));
addChild(createWidget<ScrewSilver>(Vec(box.size.x-30, 365)));

addParam(createParam<CKSS>(Vec(62, 150), module, VCO2::MODE_PARAM, 0.0f, 1.0f, 1.0f));
addParam(createParam<CKSS>(Vec(62, 215), module, VCO2::SYNC_PARAM, 0.0f, 1.0f, 1.0f));
addParam(createParam<CKSS>(Vec(62, 150), module, VCO2::MODE_PARAM));
addParam(createParam<CKSS>(Vec(62, 215), module, VCO2::SYNC_PARAM));

addParam(createParam<RoundHugeBlackKnob>(Vec(17, 60), module, VCO2::FREQ_PARAM, -54.0f, 54.0f, 0.0f));
addParam(createParam<RoundLargeBlackKnob>(Vec(12, 143), module, VCO2::WAVE_PARAM, 0.0f, 3.0f, 1.5f));
addParam(createParam<RoundLargeBlackKnob>(Vec(12, 208), module, VCO2::FM_PARAM, 0.0f, 1.0f, 0.0f));
addParam(createParam<RoundHugeBlackKnob>(Vec(17, 60), module, VCO2::FREQ_PARAM));
addParam(createParam<RoundLargeBlackKnob>(Vec(12, 143), module, VCO2::WAVE_PARAM));
addParam(createParam<RoundLargeBlackKnob>(Vec(12, 208), module, VCO2::FM_PARAM));

addInput(createPort<PJ301MPort>(Vec(11, 276), PortWidget::INPUT, module, VCO2::FM_INPUT));
addInput(createPort<PJ301MPort>(Vec(54, 276), PortWidget::INPUT, module, VCO2::SYNC_INPUT));
addInput(createPort<PJ301MPort>(Vec(11, 320), PortWidget::INPUT, module, VCO2::WAVE_INPUT));
addInput(createInput<PJ301MPort>(Vec(11, 276), module, VCO2::FM_INPUT));
addInput(createInput<PJ301MPort>(Vec(54, 276), module, VCO2::SYNC_INPUT));
addInput(createInput<PJ301MPort>(Vec(11, 320), module, VCO2::WAVE_INPUT));

addOutput(createPort<PJ301MPort>(Vec(54, 320), PortWidget::OUTPUT, module, VCO2::OUT_OUTPUT));
addOutput(createOutput<PJ301MPort>(Vec(54, 320), module, VCO2::OUT_OUTPUT));

addChild(createLight<SmallLight<GreenRedLight>>(Vec(68, 42.5f), module, VCO2::PHASE_POS_LIGHT));
}


Loading…
Cancel
Save