computerscare-vcv-modules

computerscare modules for VCV Rack
Log | Files | Refs

commit 62aa232b1637ec47c06e858fdbb4a81841056c6f
parent d46f6be01ff44ac3a983e4b4b62c1df275c71902
Author: Adam M <aemalone@gmail.com>
Date:   Sat, 12 Jan 2019 00:40:05 -0600

Fixed some ohpeas stuff.  old findEvenSpacing was causing a slowdown

Diffstat:
Ares/computerscare-small-knob-effed.svg | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/Computerscare.hpp | 5+++++
Msrc/ComputerscareOhPeas.cpp | 27+++++++++++++--------------
Msrc/dtpulse.cpp | 5++++-
Msrc/dtpulse.hpp | 7+++++--
5 files changed, 101 insertions(+), 17 deletions(-)

diff --git a/res/computerscare-small-knob-effed.svg b/res/computerscare-small-knob-effed.svg @@ -0,0 +1,74 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + id="Layer_1" + data-name="Layer 1" + viewBox="0 0 18 18" + version="1.1" + sodipodi:docname="computerscare-small-knob-effed.svg" + inkscape:version="0.92.2 5c3e80d, 2017-08-06" + width="18" + height="18"> + <metadata + id="metadata1289"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title>01 Big Knob</dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1398" + inkscape:window-height="834" + id="namedview1287" + showgrid="false" + inkscape:zoom="22.378007" + inkscape:cx="7.0612099" + inkscape:cy="9.9790231" + inkscape:window-x="0" + inkscape:window-y="0" + inkscape:window-maximized="0" + inkscape:current-layer="Big_Knob" /> + <defs + id="defs1279"> + <style + id="style1277">.cls-1{fill:#245559;}.cls-2{fill:none;stroke:#24c9a6;stroke-miterlimit:10;stroke-width:3px;}</style> + </defs> + <title + id="title1281">01 Big Knob</title> + <g + id="Big_Knob" + data-name="Big Knob" + transform="translate(0,-42)"> + <path + style="fill:#24c9a6;fill-opacity:1;stroke:#000000;stroke-width:0.794;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none" + d="m 17.306156,50.928799 c 0.547144,6.492783 -3.674677,9.295802 -8.5188736,8.849665 -4.4544548,-0.410243 -9.25218903,-4.158274 -8.1261913,-8.808316 1.8128765,-7.48665 4.5399117,-8.489838 8.8083151,-8.808316 0.2710372,-0.02022 0.4944121,-0.0716 0.6174528,0.01303 0.851296,0.585106 -1.6051492,2.237455 4.408529,3.087358 0,0 2.658576,3.860647 2.810768,5.666637 z" + id="Big_Button_Circle" + inkscape:connector-curvature="0" + sodipodi:nodetypes="sssssss" /> + <path + style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#245559;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.14128505;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:10;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" + d="m 9.7828699,42.24466 c -0.1119802,0.710525 -0.3019306,2.198982 -0.3019306,2.198982 l -0.1777448,0.588651 -0.2034123,0.598305 -0.015928,0.735707 0.3232394,0.557847 0.2878686,0.63051 -0.677338,2.045933 c 0.8672158,0.08816 0.899553,0.07243 1.6385118,-0.476766 l -0.360153,-1.171141 -0.186429,-0.959997 -0.01518,-0.940737 0.118954,-0.407286 0.01716,-0.507655 -0.10054,-2.914717 c -0.3472123,0.13136 -0.3516893,-0.0043 -0.3540543,0.06194 -0.00161,0.04384 0.026642,-0.157446 0.00682,-0.03954 0,0 -0.03003,0.03963 -0.037906,0.02583 -0.0077,-0.0138 0.037884,-0.02583 0.037884,-0.02583 z" + id="Button_Pointer" + inkscape:connector-curvature="0" + sodipodi:nodetypes="cccccccccccccccscacc" /> + </g> +</svg> diff --git a/src/Computerscare.hpp b/src/Computerscare.hpp @@ -143,6 +143,11 @@ struct SmoothKnob : RoundKnob { setSVG(SVG::load(assetPlugin(plugin, "res/computerscare-medium-knob-effed.svg"))); } }; +struct SmallKnob : RoundKnob { + SmallKnob() { + setSVG(SVG::load(assetPlugin(plugin, "res/computerscare-small-knob-effed.svg"))); + } +}; struct BigSmoothKnob : RoundKnob { BigSmoothKnob() { setSVG(SVG::load(assetPlugin(plugin, "res/computerscare-big-knob-effed.svg"))); diff --git a/src/ComputerscareOhPeas.cpp b/src/ComputerscareOhPeas.cpp @@ -113,12 +113,15 @@ struct ComputerscareOhPeas : Module { SchmittTrigger manualClearTrigger; Quantizer quantizers[numChannels]; + Quantizer quant; + std::vector<float> vvv = {0.f, 0.4f, 0.7f, 0.95f}; ComputerscareOhPeas() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { for(int i = 0; i < numChannels; i++) { quantizers[i] = Quantizer("2212221",12,0); } + quant = quantizers[0]; } void step() override; @@ -138,27 +141,23 @@ struct ComputerscareOhPeas : Module { void ComputerscareOhPeas::step() { - float A,B,C,D,Q,a,b,c,d; + float A,B,C,D,Q,a,b,c,d,octavePart; for(int i = 0; i < numChannels; i++) { a = params[SCALE_VAL+i].value; b = params[SCALE_TRIM+i].value; B = inputs[SCALE_CV+i].value; - - A = inputs[CHANNEL_INPUT+i].value; c = params[OFFSET_TRIM+i].value; C = inputs[OFFSET_CV+i].value; - d = params[OFFSET_VAL+i].value; - D = (b*B + a)*A + (c*C + d); - Q = quantizers[0].quantize(D); + Q = quant.quantizeEven(D); outputs[SCALED_OUTPUT + i].value = D; outputs[QUANTIZED_OUTPUT + i].value = Q; @@ -244,15 +243,15 @@ struct ComputerscareOhPeasWidget : ModuleWidget { double x = 0.2; double y = 7; - double dy = 18.4; + //double dy = 18.4; double dx = 9.95; double xx; - double yy; + double yy=18; - ParamWidget* rootKnob = ParamWidget::create<SmoothKnob>(mm2px(Vec(10,10)), module, ComputerscareOhPeas::GLOBAL_TRANSPOSE , 7.f, 7.f, 0.0f); + ParamWidget* rootKnob = ParamWidget::create<SmoothKnob>(mm2px(Vec(30,yy)), module, ComputerscareOhPeas::GLOBAL_TRANSPOSE , -7.f, 7.f, 0.0f); addParam(rootKnob); - textFieldTemp = Widget::create<PeasTextField>(mm2px(Vec(x,y+10))); + textFieldTemp = Widget::create<PeasTextField>(mm2px(Vec(x,y+20))); textFieldTemp->setModule(module); textFieldTemp->box.size = mm2px(Vec(38, 7)); textFieldTemp->multiline = false; @@ -272,15 +271,15 @@ struct ComputerscareOhPeasWidget : ModuleWidget { }*/ - ParamWidget* scaleTrimKnob = ParamWidget::create<SmoothKnob>(mm2px(Vec(xx,y+20)), module, ComputerscareOhPeas::SCALE_TRIM +i, -1.f, 1.f, 0.0f); + ParamWidget* scaleTrimKnob = ParamWidget::create<SmallKnob>(mm2px(Vec(xx+2,y+34)), module, ComputerscareOhPeas::SCALE_TRIM +i, -1.f, 1.f, 0.0f); addParam(scaleTrimKnob); - addInput(Port::create<InPort>(mm2px(Vec(xx, y+30)), Port::INPUT, module, ComputerscareOhPeas::SCALE_CV+i)); + addInput(Port::create<InPort>(mm2px(Vec(xx, y+40)), Port::INPUT, module, ComputerscareOhPeas::SCALE_CV+i)); - ParamWidget* scaleKnob = ParamWidget::create<SmoothKnob>(mm2px(Vec(xx,y+40)), module, ComputerscareOhPeas::SCALE_VAL +i, -1.f, 1.f, 0.0f); + ParamWidget* scaleKnob = ParamWidget::create<SmoothKnob>(mm2px(Vec(xx,y+50)), module, ComputerscareOhPeas::SCALE_VAL +i, -1.f, 1.f, 0.0f); addParam(scaleKnob); - ParamWidget* offsetTrimKnob = ParamWidget::create<SmoothKnob>(mm2px(Vec(xx,y+60)), module, ComputerscareOhPeas::OFFSET_TRIM +i, -1.f, 1.f, 0.0f); + ParamWidget* offsetTrimKnob = ParamWidget::create<SmallKnob>(mm2px(Vec(xx+2,y+64)), module, ComputerscareOhPeas::OFFSET_TRIM +i, -1.f, 1.f, 0.0f); addParam(offsetTrimKnob); addInput(Port::create<InPort>(mm2px(Vec(xx, y+70)), Port::INPUT, module, ComputerscareOhPeas::OFFSET_CV+i)); diff --git a/src/dtpulse.cpp b/src/dtpulse.cpp @@ -1183,6 +1183,9 @@ std::vector<float> Quantizer::generateMappedValues() { float Quantizer::findEvenSpacingValue(float input, std::vector<float> allowedValues) { return allowedValues[floor(input*allowedValues.size())]; } +float Quantizer::findEvenSpacingImpure(float input) { + return mappedValues[floor(input*numSteps)]; +} float Quantizer::findClosestValue(float input,std::vector<float> allowedValues) { float closestValue = 10.f; float smallestDiff = 10.f; @@ -1208,7 +1211,7 @@ float Quantizer::quantize(float input) { float Quantizer::quantizeEven(float input) { float octavePart = floor(input); float fractionalPart = input-octavePart; - float quantizedFractional = findEvenSpacingValue(fractionalPart,mappedValues); + float quantizedFractional = findEvenSpacingImpure(fractionalPart); float quantizedPreTranspose = octavePart + quantizedFractional; float quantizedVal = quantizedPreTranspose + fTranspose; return quantizedVal; diff --git a/src/dtpulse.hpp b/src/dtpulse.hpp @@ -121,6 +121,10 @@ class Quantizer { Quantizer(); float quantize(float val); float quantizeEven(float val); + float findEvenSpacingValue(float input, std::vector<float> allowedValues); + float findEvenSpacingImpure(float input); + + std::vector<float> mappedValues; int numDivisions; int transpose; bool parseError; @@ -129,8 +133,7 @@ class Quantizer { private: Parser scaleParser; float findClosestValue(float input, std::vector<float> allowedValues); - float findEvenSpacingValue(float input, std::vector<float> allowedValues); - std::vector<float> mappedValues; + std::vector<float> generateMappedValues(); }; bool matchesAny(std::string val, std::vector<std::string> whitelist);