Browse Source

Add Octave

v0.6
Andrew Belt 6 years ago
parent
commit
aabcb39e66
4 changed files with 335 additions and 2 deletions
  1. +168
    -0
      res/Octave.svg
  2. +1
    -0
      src/Fundamental.cpp
  3. +1
    -2
      src/Fundamental.hpp
  4. +165
    -0
      src/Octave.cpp

+ 168
- 0
res/Octave.svg View File

@@ -0,0 +1,168 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<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"
width="15.23972mm"
height="128.49931mm"
viewBox="0 0 15.23972 128.49931"
version="1.1"
id="svg55191"
inkscape:version="0.92.2 2405546, 2018-03-11"
sodipodi:docname="Octave.svg">
<defs
id="defs55185" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.98994949"
inkscape:cx="-65.862266"
inkscape:cy="195.84867"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:window-width="1600"
inkscape:window-height="882"
inkscape:window-x="0"
inkscape:window-y="18"
inkscape:window-maximized="0"
inkscape:snap-bbox="true"
inkscape:snap-bbox-midpoints="true"
inkscape:snap-nodes="false"
inkscape:snap-others="false"
inkscape:bbox-nodes="true" />
<metadata
id="metadata55188">
<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></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-90.65395,-49.809869)">
<path
inkscape:connector-curvature="0"
style="fill:#e6e6e6;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.35277778"
d="M 90.747648,49.903575 H 105.79994 V 178.21685 H 90.747648 Z m 0,0"
id="path34071" />
<path
inkscape:connector-curvature="0"
style="fill:#ababab;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.35277778"
d="M 105.89367,49.809869 H 90.65395 V 178.30918 h 15.23972 z M 105.70761,178.12315 H 90.83997 V 49.997282 h 14.86764 z m 0,0"
id="path34073" />
<path
inkscape:connector-curvature="0"
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.35277778"
d="m 95.309488,59.424614 c 0.915,0 1.576459,-0.689019 1.576459,-1.532378 v -0.0055 c 0,-0.84336 -0.655955,-1.526867 -1.570955,-1.526867 -0.915035,0 -1.576494,0.689019 -1.576494,1.532379 v 0.01103 c 0,0.843359 0.655955,1.521354 1.57099,1.521354 z m 0.0056,-0.600824 c -0.523663,0 -0.898489,-0.424436 -0.898489,-0.931554 v -0.0055 c 0,-0.507119 0.363819,-0.926042 0.892986,-0.926042 0.523628,0 0.892951,0.424436 0.892951,0.931554 v 0.01103 c 0,0.507118 -0.363784,0.92053 -0.887448,0.92053 z m 0,0"
id="path55078" />
<path
inkscape:connector-curvature="0"
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.35277778"
d="m 98.865418,59.424614 c 0.474028,0 0.788247,-0.137804 1.058333,-0.369314 0.0551,-0.05512 0.110239,-0.132292 0.110239,-0.237023 0,-0.165364 -0.143329,-0.297656 -0.308676,-0.297656 -0.07719,0 -0.143334,0.02756 -0.192934,0.07166 -0.187396,0.148828 -0.369323,0.23151 -0.644913,0.23151 -0.507119,0 -0.859896,-0.424435 -0.859896,-0.931554 v -0.0055 c 0,-0.507118 0.363784,-0.926041 0.859896,-0.926041 0.231493,0 0.424427,0.07717 0.606319,0.214974 0.04964,0.02756 0.10474,0.06063 0.192934,0.06063 0.181892,0 0.32523,-0.137804 0.32523,-0.314193 0,-0.115755 -0.06065,-0.209462 -0.126793,-0.259071 -0.248037,-0.181905 -0.545711,-0.303173 -0.992187,-0.303173 -0.909497,0 -1.543403,0.689019 -1.543403,1.532379 v 0.01102 c 0,0.848872 0.644913,1.521354 1.515851,1.521355 z m 0,0"
id="path55082" />
<path
inkscape:connector-curvature="0"
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.35277778"
d="m 101.33525,59.071837 c 0,0.181901 0.14333,0.330729 0.32523,0.330729 0.18189,0 0.32522,-0.148828 0.32522,-0.330729 v -2.061546 h 0.62837 c 0.16538,0 0.29767,-0.132291 0.29767,-0.297656 0,-0.165365 -0.13229,-0.303169 -0.29767,-0.303169 h -1.90719 c -0.16538,0 -0.29767,0.137804 -0.29767,0.303169 0,0.165365 0.13229,0.297656 0.29767,0.297656 h 0.62837 z m 0,0"
id="path55074" />
<path
inkscape:connector-curvature="0"
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.35277778"
d="m 98.908386,170.28487 c 0,0.22048 -0.17914,0.401 -0.401002,0.401 -0.221862,0 -0.401038,-0.18052 -0.401038,-0.401 0,-0.22187 0.179176,-0.40101 0.401038,-0.40101 0.221862,0 0.401002,0.17914 0.401002,0.40101"
id="path34139" />
<path
inkscape:connector-curvature="0"
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.35277778"
d="m 95.584549,171.61054 c -0.117122,0 -0.223237,-0.0661 -0.27559,-0.17088 l -1.001854,-2.00367 c -0.07715,-0.15296 -0.01517,-0.33762 0.137795,-0.41478 0.151589,-0.0758 0.337644,-0.0138 0.413421,0.1378 l 0.726228,1.45383 0.726229,-1.45383 c 0.07719,-0.15159 0.261831,-0.2136 0.414796,-0.1378 0.151588,0.0772 0.213607,0.26182 0.137795,0.41478 l -1.003195,2.00367 c -0.05239,0.10473 -0.158502,0.17088 -0.275625,0.17088"
id="path34141" />
<path
inkscape:connector-curvature="0"
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.35277778"
d="m 101.08982,171.61054 c -0.11574,0 -0.22323,-0.0661 -0.27562,-0.17088 l -1.00182,-2.00367 c -0.07581,-0.15296 -0.01517,-0.33762 0.137795,-0.41478 0.151585,-0.0758 0.337605,-0.0138 0.413415,0.1378 l 0.72623,1.45383 0.72761,-1.45383 c 0.0758,-0.15159 0.26045,-0.2136 0.41342,-0.1378 0.15155,0.0772 0.21357,0.26182 0.13779,0.41478 l -1.00185,2.00367 c -0.0523,0.10473 -0.15984,0.17088 -0.27697,0.17088"
id="path34143" />
<path
inkscape:connector-curvature="0"
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.35277778"
d="m 98.486711,171.61054 c -0.722101,0 -1.310534,-0.58843 -1.310534,-1.31052 0,-0.72347 0.588433,-1.31051 1.310534,-1.31051 0.286632,0 0.55947,0.0909 0.786836,0.26183 0.136454,0.10197 0.164006,0.29627 0.06202,0.43132 -0.101953,0.13643 -0.296263,0.16399 -0.432682,0.062 -0.11991,-0.0909 -0.264584,-0.13918 -0.416172,-0.13918 -0.381741,0 -0.693173,0.31144 -0.693173,0.69453 0,0.3831 0.311432,0.69316 0.693173,0.69316 0.151588,0 0.296262,-0.0469 0.416172,-0.13781 0.136419,-0.10197 0.330729,-0.0758 0.432682,0.0606 0.101988,0.13642 0.07444,0.33073 -0.06202,0.4327 -0.227366,0.17088 -0.500204,0.26183 -0.786836,0.26183"
id="path34145" />
<path
inkscape:connector-curvature="0"
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.35277778"
d="m 103.11554,154.72819 c 0,-0.54983 -0.45063,-0.99908 -1.00047,-0.99908 h -7.682552 c -0.549839,0 -0.999067,0.44925 -0.999067,0.99908 v 11.67336 c 0,0.54984 0.449228,1.00046 0.999067,1.00046 h 7.682552 c 0.54984,0 1.00047,-0.45062 1.00047,-1.00046 z m 0,0"
id="path34173" />
<path
inkscape:connector-curvature="0"
style="fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.35277778"
d="m 96.605347,156.56751 c 0.496111,0 0.859896,-0.37482 0.859896,-0.83233 0,-0.45751 -0.358281,-0.82682 -0.854393,-0.82682 -0.496076,0 -0.854357,0.37482 -0.854357,0.82682 v 0.005 c 0,0.45752 0.358281,0.82683 0.848854,0.82683 z m 0.0056,-0.32521 c -0.281093,0 -0.48507,-0.23151 -0.48507,-0.50712 0,-0.27561 0.198438,-0.50161 0.479567,-0.50161 0.286631,0 0.490572,0.226 0.490572,0.50161 v 0.005 c 0,0.27561 -0.198437,0.50161 -0.485069,0.50161 z m 0,0"
id="path55066" />
<path
inkscape:connector-curvature="0"
style="fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.35277778"
d="m 98.593426,156.56751 c 0.259045,0 0.429931,-0.0772 0.573264,-0.20394 0.03316,-0.0276 0.06061,-0.0717 0.06061,-0.12127 0,-0.0937 -0.07715,-0.16537 -0.165347,-0.16537 -0.0441,0 -0.07719,0.0165 -0.104739,0.0386 -0.10474,0.0827 -0.198438,0.12678 -0.352778,0.12678 -0.270087,0 -0.463021,-0.23151 -0.463021,-0.50712 0,-0.27561 0.192934,-0.50161 0.463021,-0.50161 0.126788,0 0.231528,0.0386 0.330729,0.11576 0.02752,0.0165 0.05514,0.0331 0.10474,0.0331 0.0992,0 0.176389,-0.0772 0.176389,-0.17088 0,-0.0662 -0.03316,-0.11576 -0.07165,-0.14332 -0.132292,-0.0992 -0.292171,-0.15985 -0.534706,-0.15985 -0.496076,0 -0.837847,0.37483 -0.837847,0.82682 v 0.006 c 0,0.46302 0.352778,0.82682 0.821337,0.82682 z m 0,0"
id="path55070" />
<path
inkscape:connector-curvature="0"
style="fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.35277778"
d="m 99.990321,156.37459 c 0,0.0992 0.07715,0.17639 0.176389,0.17639 0.0992,0 0.17639,-0.0772 0.17639,-0.17639 v -1.11345 h 0.33623 c 0.0937,0 0.16535,-0.0717 0.16535,-0.16537 0,-0.0882 -0.0716,-0.15985 -0.16535,-0.15985 h -1.03078 c -0.08819,0 -0.159844,0.0717 -0.159844,0.15985 0,0.0937 0.07165,0.16537 0.159844,0.16537 h 0.341771 z m 0,0"
id="path55062" />
<path
inkscape:connector-curvature="0"
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.35277778"
d="m 97.187995,141.01531 c 0,0.0772 0.06615,0.1378 0.143298,0.1378 0.07719,0 0.143334,-0.0606 0.143334,-0.1378 v -1.35048 c 0,-0.0772 -0.06615,-0.1378 -0.143334,-0.1378 -0.07715,0 -0.143298,0.0606 -0.143298,0.1378 z m 0,0"
id="path55054" />
<path
inkscape:connector-curvature="0"
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.35277778"
d="m 97.971656,141.01531 c 0,0.0772 0.06615,0.1378 0.143333,0.1378 0.07715,0 0.137795,-0.0606 0.137795,-0.1378 v -1.01975 l 0.826806,1.06936 c 0.03859,0.0496 0.07719,0.0882 0.143333,0.0882 h 0.01094 c 0.07719,0 0.137831,-0.0661 0.137831,-0.14332 v -1.34496 c 0,-0.0772 -0.06064,-0.13781 -0.137831,-0.13781 -0.07715,0 -0.137795,0.0606 -0.137795,0.13781 v 0.98667 l -0.804756,-1.04179 c -0.03859,-0.0496 -0.07719,-0.0827 -0.143334,-0.0827 h -0.03316 c -0.07719,0 -0.143334,0.0661 -0.143334,0.14332 z m 0,0"
id="path55058" />
</g>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="widgets"
style="display:none">
<rect
style="opacity:1;vector-effect:none;fill:#00ff00;fill-opacity:0.50196078;fill-rule:evenodd;stroke:none;stroke-width:0.69999999;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal"
id="rect56028"
width="6"
height="6"
x="4.6198416"
y="94.252983" />
<rect
y="109.25293"
x="4.6198425"
height="6"
width="6"
id="rect56030"
style="opacity:1;vector-effect:none;fill:#0000ff;fill-opacity:0.50196078;fill-rule:evenodd;stroke:none;stroke-width:0.69999999;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal" />
<rect
y="14.583808"
x="0"
height="72.001122"
width="15.23972"
id="rect56032"
style="opacity:1;vector-effect:none;fill:#ffff00;fill-opacity:0.50196078;fill-rule:evenodd;stroke:none;stroke-width:3.86460304;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal" />
</g>
</svg>

+ 1
- 0
src/Fundamental.cpp View File

@@ -25,4 +25,5 @@ void init(rack::Plugin *p) {
p->addModel(modelSEQ3); p->addModel(modelSEQ3);
p->addModel(modelSequentialSwitch1); p->addModel(modelSequentialSwitch1);
p->addModel(modelSequentialSwitch2); p->addModel(modelSequentialSwitch2);
p->addModel(modelOctave);
} }

+ 1
- 2
src/Fundamental.hpp View File

@@ -23,5 +23,4 @@ extern Model *modelScope;
extern Model *modelSEQ3; extern Model *modelSEQ3;
extern Model *modelSequentialSwitch1; extern Model *modelSequentialSwitch1;
extern Model *modelSequentialSwitch2; extern Model *modelSequentialSwitch2;


extern Model *modelOctave;

+ 165
- 0
src/Octave.cpp View File

@@ -0,0 +1,165 @@
#include "Fundamental.hpp"

struct Octave : Module {
enum ParamIds {
NUM_PARAMS
};
enum InputIds {
CV_INPUT,
NUM_INPUTS
};
enum OutputIds {
CV_OUTPUT,
NUM_OUTPUTS
};
enum LightIds {
NUM_LIGHTS
};

int octave = 0;

Octave() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}

void onReset() override {
octave = 0;
}

void onRandomize() override {
octave = (randomu32() % 9) - 4;
}

json_t *toJson() override {
json_t *rootJ = json_object();
json_object_set_new(rootJ, "octave", json_integer(octave));
return rootJ;
}

void fromJson(json_t *rootJ) override {
json_t *octaveJ = json_object_get(rootJ, "octave");
if (octaveJ)
octave = json_integer_value(octaveJ);
}

void step() override {
float cv = inputs[CV_INPUT].value;
cv += octave;
outputs[CV_OUTPUT].value = cv;
}
};


struct OctaveButton : OpaqueWidget {
Octave *module;
int octave;

void draw(NVGcontext *vg) override {
Vec c = box.size.div(2);

if (module->octave == octave) {
// Enabled
nvgBeginPath(vg);
nvgCircle(vg, c.x, c.y, mm2px(4.0/2));
if (octave < 0)
nvgFillColor(vg, COLOR_RED);
else if (octave > 0)
nvgFillColor(vg, COLOR_GREEN);
else
nvgFillColor(vg, colorAlpha(COLOR_WHITE, 0.33));
nvgFill(vg);
}
else {
// Disabled
nvgBeginPath(vg);
nvgCircle(vg, c.x, c.y, mm2px(4.0/2));
nvgFillColor(vg, colorAlpha(COLOR_WHITE, 0.33));
nvgFill(vg);

nvgBeginPath(vg);
nvgCircle(vg, c.x, c.y, mm2px(3.0/2));
nvgFillColor(vg, COLOR_BLACK);
nvgFill(vg);

if (octave == 0) {
nvgBeginPath(vg);
nvgCircle(vg, c.x, c.y, mm2px(1.0/2));
nvgFillColor(vg, colorAlpha(COLOR_WHITE, 0.33));
nvgFill(vg);
}
}
}

void onMouseDown(EventMouseDown &e) override {
if (e.button == 1) {
module->octave = 0;
e.target = this;
e.consumed = true;
return;
}
OpaqueWidget::onMouseDown(e);
}

void onDragEnter(EventDragEnter &e) override {
OctaveButton *w = dynamic_cast<OctaveButton*>(e.origin);
if (w) {
module->octave = octave;
}
}
};


struct OctaveDisplay : OpaqueWidget {
OctaveDisplay() {
box.size = mm2px(Vec(15.240, 72.000));
}

void setModule(Octave *module) {
clearChildren();

const int octaves = 9;
const float margin = mm2px(2.0);
float height = box.size.y - 2*margin;
for (int i = 0; i < octaves; i++) {
OctaveButton *octaveButton = new OctaveButton();
octaveButton->box.pos = Vec(0, height / octaves * i + margin);
octaveButton->box.size = Vec(box.size.x, height / octaves);
octaveButton->module = module;
octaveButton->octave = 4 - i;
addChild(octaveButton);
}
}

void draw(NVGcontext *vg) override {
// Background
nvgBeginPath(vg);
nvgRect(vg, 0, 0, box.size.x, box.size.y);
nvgFillColor(vg, nvgRGB(0, 0, 0));
nvgFill(vg);

Widget::draw(vg);
}
};


struct OctaveWidget : ModuleWidget {
OctaveWidget(Octave *module) : ModuleWidget(module) {
setPanel(SVG::load(assetPlugin(plugin, "res/Octave.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)));

addInput(createInputCentered<PJ301MPort>(mm2px(Vec(7.62, 97.253)), module, Octave::CV_INPUT));

addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(7.62, 112.253)), module, Octave::CV_OUTPUT));

OctaveDisplay *octaveDisplay = new OctaveDisplay();
octaveDisplay->box.pos = mm2px(Vec(0.0, 14.584));
octaveDisplay->setModule(module);
addChild(octaveDisplay);
}
};


Model *modelOctave = createModel<Octave, OctaveWidget>("Fundamental", "Octave", "Octave", UTILITY_TAG);


Loading…
Cancel
Save