Browse Source

Add Random Values modules.

tags/v2.6.0
Andrew Belt 1 year ago
parent
commit
f03e461c5e
5 changed files with 413 additions and 0 deletions
  1. +12
    -0
      plugin.json
  2. +240
    -0
      res/RandomValues.svg
  3. +159
    -0
      src/RandomValues.cpp
  4. +1
    -0
      src/plugin.cpp
  5. +1
    -0
      src/plugin.hpp

+ 12
- 0
plugin.json View File

@@ -359,6 +359,7 @@
"name": "Mult",
"description": "Copies a signal to 8 outputs",
"tags": [
"Multiple",
"Utility",
"Polyphonic"
]
@@ -368,6 +369,17 @@
"name": "Rescale",
"description": "Rescales voltages with gain and offset",
"tags": [
"Attenuator",
"Utility",
"Polyphonic"
]
},
{
"slug": "RandomValues",
"name": "Random Values",
"description": "Generates random fixed voltages",
"tags": [
"Random",
"Utility",
"Polyphonic"
]


+ 240
- 0
res/RandomValues.svg View File

@@ -0,0 +1,240 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
width="45"
height="380"
viewBox="0 0 45 380"
version="1.1"
id="svg74"
sodipodi:docname="RANDOM_VALUES.svg"
inkscape:version="1.2.1 (9c6d41e410, 2022-07-14)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview76"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
showgrid="false"
inkscape:zoom="2.1815789"
inkscape:cx="-1.145959"
inkscape:cy="186.56212"
inkscape:window-width="1920"
inkscape:window-height="1009"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="svg74" />
<defs
id="defs7">
<linearGradient
id="uuid-7bd8f438-e4e0-4a2c-9d3e-9cac64cdaec8"
x1="22.5"
y1="0"
x2="22.5"
y2="380"
gradientUnits="userSpaceOnUse">
<stop
offset="0"
stop-color="#ebebeb"
id="stop2" />
<stop
offset="1"
stop-color="#e1e1e1"
id="stop4" />
</linearGradient>
</defs>
<g
id="uuid-7e4af04a-b17d-4a9a-8c74-1ac4fa237de5"
data-name="FND BG">
<rect
width="45"
height="380"
fill="url(#uuid-7bd8f438-e4e0-4a2c-9d3e-9cac64cdaec8)"
id="rect9" />
</g>
<g
id="uuid-37043c0b-2dd1-423f-beec-b506135b3c10"
data-name="FND GRAPH">
<rect
x="8.2287"
y="129.60466"
width="28.55155"
height="218.42431"
rx="2.83465"
ry="2.83465"
fill="#1f1f1f"
id="rect12" />
<path
d="m22.83321,85.38804l1.65796-2.87167c.14313-.24791-.03578-.55779-.32204-.55779h-3.31592c-.28626,0-.46517.30989-.32204.55779l1.65796,2.87167c.14313.24791.50096.24791.64409,0Z"
fill="#1f1f1f"
id="path14" />
<g
id="g24">
<circle
cx="23.00165"
cy="355.83101"
r="1.18571"
fill="#1f1f1f"
id="circle16" />
<path
d="m14.35927,359.75298c-.34551,0-.66126-.1952-.8158-.50419l-2.96428-5.92856c-.22526-.45057-.04266-.99844.40794-1.2237.45008-.22535.99831-.04271,1.22366.4079l2.14848,4.29696,2.14848-4.29696c.22526-.45057.77314-.63325,1.22366-.4079.45061.22526.63321.77314.40794,1.2237l-2.96428,5.92856c-.15454.30899-.47029.50419-.8158.50419Z"
fill="#1f1f1f"
id="path18" />
<path
d="m30.64073,359.75298c-.34551,0-.66126-.1952-.8158-.50419l-2.96428-5.92856c-.22526-.45057-.04266-.99844.40794-1.2237.45016-.22535.9984-.04271,1.22366.4079l2.14848,4.29696,2.14848-4.29696c.22526-.45057.77305-.63325,1.22366-.4079.45061.22526.63321.77314.40794,1.2237l-2.96428,5.92856c-.15454.30899-.47029.50419-.8158.50419Z"
fill="#1f1f1f"
id="path20" />
<path
d="m22.94242,359.75298c-2.13744,0-3.87637-1.73893-3.87637-3.87637s1.73893-3.87637,3.87637-3.87637c.84653,0,1.65102.26819,2.32653.77554.40278.30253.48401.87428.18153,1.27705-.30248.40273-.87432.48401-1.2771.18148-.357-.26815-.78267-.4099-1.23096-.4099-1.13156,0-2.05219.92059-2.05219,2.05219s.92064,2.05219,2.05219,2.05219c.44829,0,.87396-.14176,1.23096-.4099.40269-.30271.97444-.22125,1.2771.18148.30248.40278.22125.97453-.18153,1.27705-.67551.50735-1.48.77554-2.32653.77554Z"
fill="#1f1f1f"
id="path22" />
</g>
</g>
<g
id="uuid-41f20fc6-0837-401a-806b-c54537fc5096"
data-name="FND TXT">
<g
id="g33">
<path
d="m15.03711,135.26367c0-.2915.22998-.52197.52148-.52197h1.64648c.60254,0,1.07031.16943,1.38184.48096.26416.26416.40625.63672.40625,1.08398v.01367c0,.74512-.37256,1.20605-.94824,1.44287l.7251.88086c.10156.12842.16943.23682.16943.3999,0,.29102-.24414.48096-.49463.48096-.2373,0-.39307-.11523-.51514-.271l-1.01611-1.28711h-.8335v1.03613c0,.2915-.23047.52197-.52148.52197-.2915,0-.52148-.23047-.52148-.52197v-3.73926Zm2.1001,1.78125c.50781,0,.79932-.27051.79932-.67041v-.01367c0-.44678-.31152-.67725-.81982-.67725h-1.03662v1.36133h1.05713Z"
fill="#f0f0f0"
id="path27" />
<path
d="m20.19043,135.23633c0-.2915.23047-.52148.52197-.52148h.1084c.25049,0,.3999.12158.54199.30469l2.01221,2.64209v-2.4458c0-.28418.23047-.51465.51465-.51465.28467,0,.51514.23047.51514.51465v3.77344c0,.2915-.23047.52197-.52197.52197h-.03369c-.25049,0-.3999-.12207-.54199-.30518l-2.08643-2.73682v2.54053c0,.28467-.23047.51514-.51514.51514s-.51514-.23047-.51514-.51514v-3.77344Z"
fill="#f0f0f0"
id="path29" />
<path
d="m25.79883,135.26367c0-.2915.22998-.52197.52148-.52197h1.32764c1.49072,0,2.52051,1.02295,2.52051,2.35791v.01318c0,1.33447-1.02979,2.37158-2.52051,2.37158h-1.32764c-.2915,0-.52148-.23047-.52148-.52197v-3.69873Zm1.84912,3.27881c.854,0,1.42969-.57568,1.42969-1.41602v-.01367c0-.83984-.57568-1.4292-1.42969-1.4292h-.80615v2.85889h.80615Z"
fill="#f0f0f0"
id="path31" />
</g>
<g
id="g43">
<path
d="m13.22363,45.42285c0-.2373.18262-.41992.41992-.41992h1.4502c1.11035,0,1.80176.62988,1.80176,1.58545v.01318c0,1.06396-.85352,1.61914-1.89697,1.61914h-.94189v1.14551c0,.22998-.18262.41309-.41309.41309-.2373,0-.41992-.18311-.41992-.41309v-3.94336Zm1.80176,2.0459c.63037,0,1.02344-.35205,1.02344-.84668v-.01367c0-.55566-.3999-.84668-1.02344-.84668h-.96875v1.70703h.96875Z"
fill="#1f1f1f"
id="path35" />
<path
d="m17.85986,47.7334v-2.35107c0-.23047.18311-.41357.42041-.41357.22998,0,.41309.18311.41309.41357v2.31689c0,.88086.4541,1.34863,1.19922,1.34863.73828,0,1.19238-.44043,1.19238-1.31445v-2.35107c0-.23047.18262-.41357.41992-.41357.23047,0,.41309.18311.41309.41357v2.31006c0,1.41602-.79932,2.12744-2.03906,2.12744-1.2334,0-2.01904-.71143-2.01904-2.08643Z"
fill="#1f1f1f"
id="path37" />
<path
d="m23.15625,49.2168c-.09473-.06738-.1626-.18262-.1626-.31836,0-.2168.17627-.38623.39307-.38623.11523,0,.18945.03369.24414.07471.39258.31152.8125.48779,1.32715.48779.51562,0,.84082-.24365.84082-.59619v-.01367c0-.33887-.19043-.52148-1.0708-.72461-1.00928-.24414-1.57861-.54199-1.57861-1.41602v-.01367c0-.81299.67773-1.37549,1.61914-1.37549.59668,0,1.07715.15576,1.50391.44043.09473.0542.18311.16943.18311.33203,0,.2168-.17627.38623-.39307.38623-.08105,0-.14893-.02051-.2168-.06104-.36572-.23682-.71777-.35889-1.09082-.35889-.4873,0-.77246.25049-.77246.56201v.01367c0,.36572.2168.52832,1.13184.74512,1.00293.24414,1.51758.60303,1.51758,1.38916v.01367c0,.88721-.69824,1.41553-1.69385,1.41553-.64355,0-1.25342-.20312-1.78174-.59619Z"
fill="#1f1f1f"
id="path39" />
<path
d="m27.84277,45.38232c0-.23047.18262-.41357.41992-.41357.23047,0,.41309.18311.41309.41357v1.59229h2.2627v-1.59229c0-.23047.18359-.41357.41357-.41357.23682,0,.42041.18311.42041.41357v3.98389c0,.22998-.18359.41309-.42041.41309-.22998,0-.41357-.18311-.41357-.41309v-1.61914h-2.2627v1.61914c0,.22998-.18262.41309-.41309.41309-.2373,0-.41992-.18311-.41992-.41309v-3.98389Z"
fill="#1f1f1f"
id="path41" />
</g>
<g
id="g53">
<path
d="m15.71094,93.83154h-1.15137c-.2168,0-.38623-.17627-.38623-.38623s.16943-.38623.38623-.38623h3.1499c.21045,0,.37939.17627.37939.38623s-.16895.38623-.37939.38623h-1.1582v3.59033c0,.23047-.18994.41357-.42041.41357-.22998,0-.41992-.18311-.41992-.41357v-3.59033Z"
fill="#1f1f1f"
id="path45" />
<path
d="m19.08984,93.479c0-.23682.18262-.41992.41992-.41992h1.69385c.59619,0,1.06348.17627,1.36865.47412.25049.25781.39258.60986.39258,1.02344v.01318c0,.75879-.44043,1.21924-1.07715,1.41602l.90771,1.14502c.08154.10156.13574.18945.13574.31836,0,.23047-.19678.38623-.3999.38623-.18945,0-.31152-.08838-.40625-.2168l-1.15186-1.47021h-1.05029v1.27344c0,.23047-.18262.41357-.41309.41357-.2373,0-.41992-.18311-.41992-.41357v-3.94287Zm2.05273,1.93115c.59619,0,.97559-.31152.97559-.79297v-.01367c0-.50781-.36572-.78564-.98242-.78564h-1.21289v1.59229h1.21973Z"
fill="#1f1f1f"
id="path47" />
<path
d="m24.24805,93.43848c0-.23047.18262-.41309.41992-.41309.23047,0,.41309.18262.41309.41309v3.9834c0,.23047-.18262.41357-.41309.41357-.2373,0-.41992-.18311-.41992-.41357v-3.9834Z"
fill="#1f1f1f"
id="path49" />
<path
d="m26.30908,95.44385v-.01367c0-1.32764,1.01611-2.45264,2.4458-2.45264.71094,0,1.18555.16992,1.61914.48145.08105.06055.16895.17578.16895.33887,0,.22314-.18262.41309-.41309.41309-.1084,0-.18945-.04785-.25732-.09473-.30518-.22363-.63672-.37305-1.15186-.37305-.87402,0-1.53809.76562-1.53809,1.67383v.01318c0,.97559.64404,1.69385,1.61279,1.69385.44678,0,.85352-.14258,1.14502-.35938v-.88721h-.93506c-.20312,0-.37256-.15576-.37256-.35889s.16943-.36621.37256-.36621h1.3208c.2373,0,.42041.18311.42041.41992v1.26709c0,.2373-.09521.40674-.2915.52881-.40625.27051-.97559.51465-1.68701.51465-1.4834,0-2.45898-1.05664-2.45898-2.43896Z"
fill="#1f1f1f"
id="path51" />
</g>
<g
id="g61">
<path
d="m9.02246,20.49219c0-.53809.42578-.96387.96387-.96387h3.04004c1.11328,0,1.97656.31299,2.55273.88867.4873.48779.75,1.17578.75,2.00195v.0249c0,1.37646-.6875,2.22705-1.75098,2.66504l1.33887,1.62646c.1875.23828.3125.43848.3125.73828,0,.53809-.4502.88867-.91309.88867-.43848,0-.72559-.21289-.95117-.50049l-1.87695-2.37744h-1.53906v1.91406c0,.53809-.42578.96387-.96289.96387-.53809,0-.96387-.42578-.96387-.96387v-6.90625Zm3.87891,3.29053c.93848,0,1.47656-.50049,1.47656-1.23877v-.0249c0-.82568-.57617-1.25146-1.51465-1.25146h-1.91406v2.51514h1.95215Z"
fill="#1f1f1f"
id="path55" />
<path
d="m18.23926,20.44189c0-.53809.42578-.96338.96387-.96338h.2002c.46289,0,.73828.2251,1.00098.56299l3.71582,4.87988v-4.51709c0-.52539.42578-.95068.95117-.95068s.95117.42529.95117.95068v6.96973c0,.5376-.42578.96289-.96387.96289h-.0625c-.46289,0-.73828-.2251-1.00098-.5625l-3.85352-5.05518v4.69189c0,.52539-.42578.95117-.95117.95117s-.95117-.42578-.95117-.95117v-6.96924Z"
fill="#1f1f1f"
id="path57" />
<path
d="m28.29004,20.49219c0-.53809.42578-.96387.96387-.96387h2.45215c2.75293,0,4.6543,1.88965,4.6543,4.35449v.0249c0,2.46533-1.90137,4.37939-4.6543,4.37939h-2.45215c-.53809,0-.96387-.42529-.96387-.96338v-6.83154Zm3.41602,6.05566c1.57617,0,2.63965-1.06348,2.63965-2.61523v-.0249c0-1.55127-1.06348-2.64014-2.63965-2.64014h-1.48926v5.28027h1.48926Z"
fill="#1f1f1f"
id="path59" />
</g>
</g>
<g
id="uuid-fed0c3bb-5966-4155-bb13-0568fa73eadc"
data-name="components"
inkscape:groupmode="layer"
style="display:none">
<circle
id="uuid-e41d2a27-b25f-4298-a438-f0e113090365"
data-name="Rnd7#PJ301MPort"
cx="22.50448"
cy="333.70117"
r="5"
fill="#0000ff" />
<circle
id="uuid-fb0f8486-4367-427b-bcd0-7b1e7d99566d"
data-name="Rnd6#PJ301MPort"
cx="22.50448"
cy="304.0961"
r="5"
fill="#0000ff" />
<circle
id="uuid-a229e816-ad90-43d7-b413-bc9c4251a1f4"
data-name="Rnd5#PJ301MPort"
cx="22.50448"
cy="274.1922"
r="5"
fill="#0000ff" />
<circle
id="uuid-7824c60e-c804-44c2-b4da-f7fe4de213b3"
data-name="Rnd4#PJ301MPort"
cx="22.50448"
cy="244.28828"
r="5"
fill="#0000ff" />
<circle
id="uuid-8a923fab-8a2c-4d00-b82f-9c4d7341e2f0"
data-name="Rnd3#PJ301MPort"
cx="22.50448"
cy="214.38438"
r="5"
fill="#0000ff" />
<circle
id="uuid-379353ea-601b-48cf-8969-562b940d52b2"
data-name="Rnd2#PJ301MPort"
cx="22.50448"
cy="184.48048"
r="5"
fill="#0000ff" />
<circle
id="uuid-6403e53f-b16e-4e13-a35a-4992167e1a58"
data-name="Rnd1#PJ301MPort"
cx="22.50448"
cy="154.57658"
r="5"
fill="#0000ff" />
<circle
id="uuid-beba54f8-ea69-4196-9839-2e3b0d3a3941"
data-name="Push#LEDLightBezel"
cx="22.5"
cy="64.865196"
r="5"
fill="#ff0000" />
<circle
id="uuid-6af3c13f-75b9-43e9-89b7-e4e41d764ed6"
data-name="Trig#PJ301MPort"
cx="22.5056"
cy="112.86853"
r="5"
fill="#00ff00" />
</g>
</svg>

+ 159
- 0
src/RandomValues.cpp View File

@@ -0,0 +1,159 @@
#include "plugin.hpp"


using simd::float_4;


struct RandomValues : Module {
enum ParamId {
PUSH_PARAM,
PARAMS_LEN
};
enum InputId {
TRIG_INPUT,
INPUTS_LEN
};
enum OutputId {
ENUMS(RND_OUTPUTS, 7),
OUTPUTS_LEN
};
enum LightId {
PUSH_LIGHT,
LIGHTS_LEN
};

dsp::BooleanTrigger pushTrigger;
dsp::TSchmittTrigger<float_4> trigTriggers[4];

struct Range {
float gain;
float offset;

bool operator==(const Range& other) const {
return gain == other.gain && offset == other.offset;
}
};
Range range = {10.f, 0.f};

RandomValues() {
config(PARAMS_LEN, INPUTS_LEN, OUTPUTS_LEN, LIGHTS_LEN);
configButton(PUSH_PARAM, "Push");
configInput(TRIG_INPUT, "Trigger");
for (int i = 0; i < 7; i++)
configOutput(RND_OUTPUTS + i, string::f("Random %d", i + 1));
}

void onReset(const ResetEvent& e) override {
Module::onReset(e);
range = {10.f, 0.f};
}

void process(const ProcessArgs& args) override {
int channels = std::max(1, inputs[TRIG_INPUT].getChannels());

bool pushed = pushTrigger.process(params[PUSH_PARAM].getValue());
bool light = false;

for (int c = 0; c < channels; c += 4) {
float_4 triggered = trigTriggers[c / 4].process(inputs[TRIG_INPUT].getVoltageSimd<float_4>(c), 0.1f, 1.f);
int triggeredMask = simd::movemask(triggered);

// This branch is infrequent so we don't need to use SIMD.
if (pushed || triggeredMask) {
light = true;

for (int c2 = 0; c2 < std::min(4, channels - c); c2++) {
if (pushed || (triggeredMask & (1 << c2))) {
for (int i = 0; i < 7; i++) {
float r = random::get<float>();
r = r * range.gain + range.offset;
outputs[RND_OUTPUTS + i].setVoltage(r, c + c2);
}
}
}
}
}

for (int i = 0; i < 7; i++) {
outputs[RND_OUTPUTS + i].setChannels(channels);
}
lights[PUSH_LIGHT].setBrightnessSmooth(light, args.sampleTime);
}

json_t* dataToJson() override {
json_t* rootJ = json_object();
json_object_set_new(rootJ, "gain", json_real(range.gain));
json_object_set_new(rootJ, "offset", json_real(range.offset));
return rootJ;
}

void dataFromJson(json_t* rootJ) override {
json_t* gainJ = json_object_get(rootJ, "gain");
if (gainJ)
range.gain = json_number_value(gainJ);

json_t* offsetJ = json_object_get(rootJ, "offset");
if (offsetJ)
range.offset = json_number_value(offsetJ);
}
};


struct RandomValuesWidget : ModuleWidget {
RandomValuesWidget(RandomValues* module) {
setModule(module);
setPanel(createPanel(asset::plugin(pluginInstance, "res/RandomValues.svg")));

addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));

addParam(createLightParamCentered<LEDLightBezel<>>(mm2px(Vec(7.62, 21.968)), module, RandomValues::PUSH_PARAM, RandomValues::PUSH_LIGHT));

addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.622, 38.225)), module, RandomValues::TRIG_INPUT));

addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(7.622, 52.35)), module, RandomValues::RND_OUTPUTS + 0));
addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(7.622, 62.477)), module, RandomValues::RND_OUTPUTS + 1));
addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(7.622, 72.605)), module, RandomValues::RND_OUTPUTS + 2));
addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(7.622, 82.732)), module, RandomValues::RND_OUTPUTS + 3));
addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(7.622, 92.86)), module, RandomValues::RND_OUTPUTS + 4));
addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(7.622, 102.987)), module, RandomValues::RND_OUTPUTS + 5));
addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(7.622, 113.013)), module, RandomValues::RND_OUTPUTS + 6));
}

void appendContextMenu(Menu* menu) override {
RandomValues* module = getModule<RandomValues>();

menu->addChild(new MenuSeparator);

static const std::vector<RandomValues::Range> ranges = {
{10.f, 0.f},
{5.f, 0.f},
{1.f, 0.f},
{20.f, -10.f},
{10.f, -5.f},
{2.f, -1.f},
};
static const std::vector<std::string> labels = {
"0V to 10V",
"0V to 5V",
"0V to 1V",
"-10V to 10V",
"-5V to 5V",
"-1V to 1V",
};
menu->addChild(createIndexSubmenuItem("Voltage range", labels,
[=]() {
auto it = std::find(ranges.begin(), ranges.end(), module->range);
return std::distance(ranges.begin(), it);
},
[=](int i) {
module->range = ranges[i];
}
));
}
};


Model* modelRandomValues = createModel<RandomValues, RandomValuesWidget>("RandomValues");

+ 1
- 0
src/plugin.cpp View File

@@ -42,4 +42,5 @@ void init(Plugin* p) {
p->addModel(modelProcess);
p->addModel(modelMult);
p->addModel(modelRescale);
p->addModel(modelRandomValues);
}

+ 1
- 0
src/plugin.hpp View File

@@ -42,6 +42,7 @@ extern Model* modelGates;
extern Model* modelProcess;
extern Model* modelMult;
extern Model* modelRescale;
extern Model* modelRandomValues;


struct DigitalDisplay : Widget {


Loading…
Cancel
Save