BogaudioModules

BogaudioModules for VCV Rack
Log | Files | Refs | README | LICENSE

commit da3cf55165e8582b90fc97df9b7e4db8ce305712
parent aa735b5599ca16413051ad1142e426c2acd986d0
Author: Matt Demanett <matt@demanett.net>
Date:   Sun, 17 Nov 2019 21:41:54 -0500

Merge branch 'master' of github.com:bogaudio/BogaudioModules

Diffstat:
Mres-src/VCO-src.svg | 8++++++++
Msrc/VCO.cpp | 49++++++++++++++++++++++++++++++++++++++++++++++---
Msrc/VCO.hpp | 9++++++++-
3 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/res-src/VCO-src.svg b/res-src/VCO-src.svg @@ -269,6 +269,14 @@ <!-- <rect width="90" height="10" fill="#0f0" transform="translate(0 7)" /> --> </g> + <g transform="translate(82 168.5)"> + <!-- <polyline points="0,3.2 70,3.2" stroke="#0f0" stroke-width="1" fill="none" /> --> + <use id="LINEAR_PARAM" xlink:href="#button-small" transform="translate(40 -1.3)" /> + <use id="LINEAR_LIGHT" xlink:href="#light-small" transform="translate(0 0)" /> + <text font-size="6pt" letter-spacing="2px" transform="translate(14 6.1)">LIN</text> + <!-- <rect width="90" height="10" fill="#0f0" transform="translate(0 7)" /> --> + </g> + <!-- <rect width="100" height="7" fill="#0f0" transform="translate(10 172)" /> --> <g transform="translate(44 188)"> diff --git a/src/VCO.cpp b/src/VCO.cpp @@ -7,6 +7,34 @@ float VCO::VCOFrequencyParamQuantity::offset() { return vco->_slowMode ? vco->slowModeOffset : 0.0f; } +float VCO::VCOFrequencyParamQuantity::getDisplayValue() { + float v = getValue(); + if (!module) { + return v; + } + + VCO* vco = dynamic_cast<VCO*>(module); + return vco->_linearMode ? (vco->_slowMode ? v : v * 1000.0f) : FrequencyParamQuantity::getDisplayValue(); +} + +void VCO::VCOFrequencyParamQuantity::setDisplayValue(float v) { + if (!module) { + return; + } + + VCO* vco = dynamic_cast<VCO*>(module); + if (vco->_linearMode) { + if (vco->_slowMode) { + setValue(v / 1000.0f); + } + else { + setValue(v); + } + } else { + FrequencyParamQuantity::setDisplayValue(v); + } +} + void VCO::Engine::reset() { syncTrigger.reset(); } @@ -85,10 +113,20 @@ void VCO::modulateChannel(int c) { if (inputs[PITCH_INPUT].isConnected()) { e.baseVOct += clamp(inputs[PITCH_INPUT].getVoltage(c), -5.0f, 5.0f); } - if (_slowMode) { - e.baseVOct += slowModeOffset; + if (_linearMode) { + if (_slowMode) { + e.baseHz = e.baseVOct; + } + else { + e.baseHz = e.baseVOct*1000.0f; + } + } + else { + if (_slowMode) { + e.baseVOct += slowModeOffset; + } + e.baseHz = cvToFrequency(e.baseVOct); } - e.baseHz = cvToFrequency(e.baseVOct); float pw = params[PW_PARAM].getValue(); if (inputs[PW_INPUT].isConnected()) { @@ -102,6 +140,7 @@ void VCO::modulateChannel(int c) { void VCO::always(const ProcessArgs& args) { lights[SLOW_LIGHT].value = _slowMode = params[SLOW_PARAM].getValue() > 0.5f; + lights[LINEAR_LIGHT].value = _linearMode = params[LINEAR_PARAM].getValue() > 0.5f; } void VCO::processChannel(const ProcessArgs& args, int c) { @@ -215,6 +254,7 @@ struct VCOWidget : ModuleWidget { auto frequencyParamPosition = Vec(41.0, 45.0); auto fineParamPosition = Vec(48.0, 153.0); auto slowParamPosition = Vec(122.0, 157.2); + auto linearParamPosition = Vec(122.0, 167.2); auto pwParamPosition = Vec(62.0, 188.0); auto fmParamPosition = Vec(62.0, 230.0); auto fmTypeParamPosition = Vec(100.5, 231.5); @@ -230,6 +270,7 @@ struct VCOWidget : ModuleWidget { auto sineOutputPosition = Vec(111.0, 318.0); auto slowLightPosition = Vec(82.0, 158.5); + auto linearLightPosition = Vec(82.0, 168.5); // end generated by svg_widgets.rb addParam(createParam<Knob68>(frequencyParamPosition, module, VCO::FREQUENCY_PARAM)); @@ -238,6 +279,7 @@ struct VCOWidget : ModuleWidget { addParam(createParam<Knob26>(pwParamPosition, module, VCO::PW_PARAM)); addParam(createParam<Knob26>(fmParamPosition, module, VCO::FM_PARAM)); addParam(createParam<SliderSwitch2State14>(fmTypeParamPosition, module, VCO::FM_TYPE_PARAM)); + addParam(createParam<StatefulButton9>(linearParamPosition, module, VCO::LINEAR_PARAM)); addInput(createInput<Port24>(pitchInputPosition, module, VCO::PITCH_INPUT)); addInput(createInput<Port24>(syncInputPosition, module, VCO::SYNC_INPUT)); @@ -250,6 +292,7 @@ struct VCOWidget : ModuleWidget { addOutput(createOutput<Port24>(sineOutputPosition, module, VCO::SINE_OUTPUT)); addChild(createLight<SmallLight<GreenLight>>(slowLightPosition, module, VCO::SLOW_LIGHT)); + addChild(createLight<SmallLight<GreenLight>>(linearLightPosition, module, VCO::LINEAR_LIGHT)); } }; diff --git a/src/VCO.hpp b/src/VCO.hpp @@ -19,6 +19,7 @@ struct VCO : BGModule { PW_PARAM, FM_PARAM, FM_TYPE_PARAM, + LINEAR_PARAM, NUM_PARAMS }; @@ -40,18 +41,20 @@ struct VCO : BGModule { enum LightsIds { SLOW_LIGHT, + LINEAR_LIGHT, NUM_LIGHTS }; struct Engine { static constexpr int oversample = 8; - float frequency = 0.0f; + float frequency = NAN; float baseVOct = 0.0f; float baseHz = 0.0f; Phasor phasor; BandLimitedSquareOscillator square; + BandLimitedSawOscillator saw; TriangleOscillator triangle; SineTableOscillator sine; @@ -78,11 +81,14 @@ struct VCO : BGModule { Engine* _engines[maxChannels] {}; float _oversampleThreshold = 0.0f; bool _slowMode = false; + bool _linearMode = false; float _fmDepth = 0.0f; bool _fmLinearMode = false; struct VCOFrequencyParamQuantity : FrequencyParamQuantity { float offset() override; + float getDisplayValue() override; + void setDisplayValue(float v) override; }; VCO() { @@ -93,6 +99,7 @@ struct VCO : BGModule { configParam(PW_PARAM, -1.0f, 1.0f, 0.0f, "Pulse width", "%", 0.0f, 100.0f*0.5f*(1.0f - 2.0f * SquareOscillator::minPulseWidth), 50.0f); configParam(FM_PARAM, 0.0f, 1.0f, 0.0f, "FM depth", "%", 0.0f, 100.0f); configParam(FM_TYPE_PARAM, 0.0f, 1.0f, 1.0f, "FM mode"); + configParam(LINEAR_PARAM, 0.0f, 1.0f, 0.0f, "Linear Freq"); } void reset() override;