computerscare-vcv-modules

computerscare modules for VCV Rack
Log | Files | Refs

commit a79254d915d8eead9378f6a36e93a9699019da34
parent 7b25d044d8dc7d047e0e3afcb92121abc9df74dc
Author: Adam M <[email protected]>
Date:   Tue, 18 Jun 2019 17:54:08 -0500

Incremental progress Father & Son, format all cpp with astyle

Diffstat:
Msrc/Computerscare.cpp | 2+-
Msrc/Computerscare.hpp | 226++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/ComputerscareDebug.cpp | 222++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/ComputerscareKnolyPobs.cpp | 118++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/ComputerscareOhPeas.cpp | 101++++++++++++-------------------------------------------------------------------
Msrc/ComputerscarePatchSequencer.cpp | 655++++++++++++++++++++++++++++++++++++++++---------------------------------------
6 files changed, 629 insertions(+), 695 deletions(-)

diff --git a/src/Computerscare.cpp b/src/Computerscare.cpp @@ -7,7 +7,7 @@ void init(Plugin *p) { pluginInstance = p; p->addModel(modelComputerscareDebug); - + p->addModel(modelComputerscarePatchSequencer); //p->addModel(modelComputerscareLaundrySoup); //p->addModel(modelComputerscareILoveCookies); diff --git a/src/Computerscare.hpp b/src/Computerscare.hpp @@ -39,7 +39,7 @@ static const NVGcolor COLOR_COMPUTERSCARE_RED = nvgRGB(0xC4, 0x34, 0x21); static const NVGcolor COLOR_COMPUTERSCARE_YELLOW = nvgRGB(0xE4, 0xC4, 0x21); static const NVGcolor COLOR_COMPUTERSCARE_BLUE = nvgRGB(0x24, 0x44, 0xC1); static const NVGcolor COLOR_COMPUTERSCARE_PINK = nvgRGB(0xAA, 0x18, 0x31); -static const NVGcolor COLOR_COMPUTERSCARE_TRANSPARENT = nvgRGBA(0x00, 0x00,0x00,0x00); +static const NVGcolor COLOR_COMPUTERSCARE_TRANSPARENT = nvgRGBA(0x00, 0x00, 0x00, 0x00); namespace rack { @@ -73,53 +73,53 @@ struct ComputerscareSvgPort : PortWidget { struct IsoButton : SvgSwitch { IsoButton() { - addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/computerscare-iso-button-down.svg"))); - addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/computerscare-iso-button-up.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-iso-button-down.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-iso-button-up.svg"))); } }; struct ComputerscareIsoThree : app::SvgSwitch { ComputerscareIsoThree() { - addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/iso-3way-1.svg"))); - addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/iso-3way-2.svg"))); - addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/iso-3way-3.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/iso-3way-1.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/iso-3way-2.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/iso-3way-3.svg"))); } }; struct ThreeVerticalXSwitch : app::SvgSwitch { ThreeVerticalXSwitch() { - addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/vertical-x-1.svg"))); - addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/vertical-x-2.svg"))); - addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/vertical-x-3.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/vertical-x-1.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/vertical-x-2.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/vertical-x-3.svg"))); } }; struct ComputerscareDebugFour : app::SvgSwitch { ComputerscareDebugFour() { - addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/debug-clock-selector-4way-template.svg"))); - addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/debug-clock-selector-4way-template.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/debug-clock-selector-4way-template.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/debug-clock-selector-4way-template.svg"))); - addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/debug-clock-selector-4way-template.svg"))); - addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/debug-clock-selector-4way-template.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/debug-clock-selector-4way-template.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/debug-clock-selector-4way-template.svg"))); } }; struct ComputerscareResetButton : SvgSwitch { ComputerscareResetButton() { - momentary=true; - addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/computerscare-rst-text.svg"))); - addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/computerscare-rst-text-red.svg"))); + momentary = true; + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-rst-text.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-rst-text-red.svg"))); //APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-pentagon-jack-1-outline-flipped.svg")); } }; struct ComputerscareClockButton : SvgSwitch { ComputerscareClockButton() { - momentary=true; - addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/computerscare-clk-text.svg"))); - addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/computerscare-clk-text-red.svg"))); + momentary = true; + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-clk-text.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-clk-text-red.svg"))); } }; struct ComputerscareInvisibleButton : SvgSwitch { ComputerscareInvisibleButton() { - addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/computerscare-invisible-button.svg"))); - addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/computerscare-invisible-button-frame2.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-invisible-button.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-invisible-button-frame2.svg"))); } }; @@ -134,21 +134,21 @@ struct ComputerscareRedLight : ModuleLightWidget { bgColor = nvgRGBA(0x5a, 0x5a, 0x5a, 0x00); borderColor = nvgRGBA(0, 0, 0, 0x00); addBaseColor(COLOR_COMPUTERSCARE_RED); - } + } }; struct ComputerscareYellowLight : ModuleLightWidget { ComputerscareYellowLight() { bgColor = nvgRGBA(0x5a, 0x5a, 0x5a, 0x00); borderColor = nvgRGBA(0, 0, 0, 0x00); addBaseColor(COLOR_COMPUTERSCARE_YELLOW); - } + } }; struct ComputerscareBlueLight : ModuleLightWidget { ComputerscareBlueLight() { bgColor = nvgRGBA(0x5a, 0x5a, 0x5a, 0x00); borderColor = nvgRGBA(0, 0, 0, 0x00); addBaseColor(COLOR_COMPUTERSCARE_BLUE); - } + } }; @@ -164,13 +164,13 @@ struct ComputerscareHugeLight : ParamWidget { struct ComputerscareMediumLight : ParamWidget { ComputerscareMediumLight() { - this->box.size = mm2px(Vec(6,6)); + this->box.size = mm2px(Vec(6, 6)); } }; struct ComputerscareSmallLight : ParamWidget { ComputerscareSmallLight() { - this->box.size = mm2px(Vec(3,3)); + this->box.size = mm2px(Vec(3, 3)); } }; @@ -199,21 +199,21 @@ struct InPort : ComputerscareSvgPort { - // Knobs +// Knobs struct LrgKnob : RoundBlackSnapKnob { LrgKnob() { - setSvg(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-big-knob-effed.svg"))); + setSvg(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-big-knob-effed.svg"))); } - //void randomize() override { return; } + //void randomize() override { return; } }; struct MediumSnapKnob : RoundBlackSnapKnob { MediumSnapKnob() { - setSvg(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-medium-knob-effed.svg"))); - } + setSvg(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-medium-knob-effed.svg"))); + } }; struct SmoothKnob : RoundKnob { @@ -231,10 +231,10 @@ struct SmallSnapKnob : RoundBlackSnapKnob { //CircularShadow *shadow; SmallSnapKnob() { - + setSvg(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-small-knob-effed.svg"))); - shadow->box.size = math::Vec(0,0); - shadow->opacity=0.f; + shadow->box.size = math::Vec(0, 0); + shadow->opacity = 0.f; } }; @@ -245,7 +245,7 @@ struct BigSmoothKnob : RoundKnob { }; struct ComputerscareDotKnob : SmallKnob { ComputerscareDotKnob() { - + } }; @@ -255,94 +255,94 @@ struct ComputerscareTextField : ui::TextField { NVGcolor color = COLOR_COMPUTERSCARE_LIGHT_GREEN; ComputerscareTextField() { - font = APP->window->loadFont(asset::system("res/fonts/ShareTechMono-Regular.ttf")); - color = nvgRGB(0xff, 0xd7, 0x14); - textOffset = math::Vec(5, 5); -} + font = APP->window->loadFont(asset::system("res/fonts/ShareTechMono-Regular.ttf")); + color = nvgRGB(0xff, 0xd7, 0x14); + textOffset = math::Vec(5, 5); + } + + void draw(const DrawArgs &args) { + nvgScissor(args.vg, RECT_ARGS(args.clipBox)); -void draw(const DrawArgs &args) { - nvgScissor(args.vg, RECT_ARGS(args.clipBox)); + // Background + nvgBeginPath(args.vg); + nvgRoundedRect(args.vg, 0, 0, box.size.x, box.size.y, 5.0); + nvgFillColor(args.vg, nvgRGB(0x00, 0x00, 0x00)); + nvgFill(args.vg); - // Background - nvgBeginPath(args.vg); - nvgRoundedRect(args.vg, 0, 0, box.size.x, box.size.y, 5.0); - nvgFillColor(args.vg, nvgRGB(0x00, 0x00, 0x00)); - nvgFill(args.vg); + // Text + if (font->handle >= 0) { + bndSetFont(font->handle); - // Text - if (font->handle >= 0) { - bndSetFont(font->handle); + NVGcolor highlightColor = color; + highlightColor.a = 0.5; + int begin = std::min(cursor, selection); + int end = (this == APP->event->selectedWidget) ? std::max(cursor, selection) : -1; + bndIconLabelCaret(args.vg, textOffset.x, textOffset.y, + box.size.x - 2 * textOffset.x, box.size.y - 2 * textOffset.y, + -1, color, 18, text.c_str(), highlightColor, begin, end); - NVGcolor highlightColor = color; - highlightColor.a = 0.5; - int begin = std::min(cursor, selection); - int end = (this == APP->event->selectedWidget) ? std::max(cursor, selection) : -1; - bndIconLabelCaret(args.vg, textOffset.x, textOffset.y, - box.size.x - 2*textOffset.x, box.size.y - 2*textOffset.y, - -1, color, 18, text.c_str(), highlightColor, begin, end); + bndSetFont(APP->window->uiFont->handle); + } - bndSetFont(APP->window->uiFont->handle); + nvgResetScissor(args.vg); } - - nvgResetScissor(args.vg); -} //int getTextPosition(math::Vec mousePos) override; }; //////////////////////////////////// struct SmallLetterDisplay : Widget { - std::string value; - std::shared_ptr<Font> font; - int fontSize = 19; - std::string defaultFontPath = "res/Oswald-Regular.ttf"; - NVGcolor baseColor = COLOR_COMPUTERSCARE_TRANSPARENT; - - float letterSpacing = 2.5; - int textAlign = 1; - bool active = false; - bool blink = false; - bool doubleblink = false; - - SmallLetterDisplay() { - font = APP->window->loadFont(asset::plugin(pluginInstance,defaultFontPath)); - }; - SmallLetterDisplay(std::string fontPath) { - font = APP->window->loadFont(asset::plugin(pluginInstance,fontPath)); - }; - - void draw(const DrawArgs &ctx) override - { - // Background - NVGcolor backgroundColor = COLOR_COMPUTERSCARE_RED; - NVGcolor doubleblinkColor = COLOR_COMPUTERSCARE_YELLOW; - - nvgBeginPath(ctx.vg); - nvgRoundedRect(ctx.vg, 1.0, -1.0, box.size.x-3, box.size.y-3, 4.0); - if(doubleblink) { - nvgFillColor(ctx.vg, doubleblinkColor); - } - else { - if(blink) { - nvgFillColor(ctx.vg, backgroundColor); - } - else { - nvgFillColor(ctx.vg, baseColor); - } - } - nvgFill(ctx.vg); - - // text - nvgFontSize(ctx.vg, fontSize); - nvgFontFaceId(ctx.vg, font->handle); - nvgTextLetterSpacing(ctx.vg, letterSpacing); - nvgTextLineHeight(ctx.vg, 0.7); - nvgTextAlign(ctx.vg,textAlign); - - Vec textPos = Vec(6.0f, 12.0f); - NVGcolor textColor = (!blink || doubleblink) ? nvgRGB(0x10, 0x10, 0x00) : COLOR_COMPUTERSCARE_YELLOW; - nvgFillColor(ctx.vg, textColor); - nvgTextBox(ctx.vg, textPos.x, textPos.y,80,value.c_str(), NULL); - - } + std::string value; + std::shared_ptr<Font> font; + int fontSize = 19; + std::string defaultFontPath = "res/Oswald-Regular.ttf"; + NVGcolor baseColor = COLOR_COMPUTERSCARE_TRANSPARENT; + + float letterSpacing = 2.5; + int textAlign = 1; + bool active = false; + bool blink = false; + bool doubleblink = false; + + SmallLetterDisplay() { + font = APP->window->loadFont(asset::plugin(pluginInstance, defaultFontPath)); + }; + SmallLetterDisplay(std::string fontPath) { + font = APP->window->loadFont(asset::plugin(pluginInstance, fontPath)); + }; + + void draw(const DrawArgs &ctx) override + { + // Background + NVGcolor backgroundColor = COLOR_COMPUTERSCARE_RED; + NVGcolor doubleblinkColor = COLOR_COMPUTERSCARE_YELLOW; + + nvgBeginPath(ctx.vg); + nvgRoundedRect(ctx.vg, 1.0, -1.0, box.size.x - 3, box.size.y - 3, 4.0); + if (doubleblink) { + nvgFillColor(ctx.vg, doubleblinkColor); + } + else { + if (blink) { + nvgFillColor(ctx.vg, backgroundColor); + } + else { + nvgFillColor(ctx.vg, baseColor); + } + } + nvgFill(ctx.vg); + + // text + nvgFontSize(ctx.vg, fontSize); + nvgFontFaceId(ctx.vg, font->handle); + nvgTextLetterSpacing(ctx.vg, letterSpacing); + nvgTextLineHeight(ctx.vg, 0.7); + nvgTextAlign(ctx.vg, textAlign); + + Vec textPos = Vec(6.0f, 12.0f); + NVGcolor textColor = (!blink || doubleblink) ? nvgRGB(0x10, 0x10, 0x00) : COLOR_COMPUTERSCARE_YELLOW; + nvgFillColor(ctx.vg, textColor); + nvgTextBox(ctx.vg, textPos.x, textPos.y, 80, value.c_str(), NULL); + + } }; diff --git a/src/ComputerscareDebug.cpp b/src/ComputerscareDebug.cpp @@ -52,14 +52,14 @@ struct ComputerscareDebug : Module { dsp::SchmittTrigger clockTriggers[NUM_LINES]; dsp::SchmittTrigger clearTrigger; dsp::SchmittTrigger manualClockTrigger; - dsp::SchmittTrigger manualClearTrigger; + dsp::SchmittTrigger manualClearTrigger; - enum clockAndInputModes { - SINGLE_MODE, - INTERNAL_MODE, - POLY_MODE - }; - //StringDisplayWidget3* textDisplay; + enum clockAndInputModes { + SINGLE_MODE, + INTERNAL_MODE, + POLY_MODE + }; + //StringDisplayWidget3* textDisplay; ComputerscareDebug() { config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); @@ -67,8 +67,8 @@ struct ComputerscareDebug : Module { configParam(MANUAL_CLEAR_TRIGGER, 0.0f, 1.0f, 0.0f, "Clear"); configParam(SWITCH_VIEW, 0.0f, 2.0f, 0.0f, "Input Mode"); configParam(WHICH_CLOCK, 0.0f, 2.0f, 0.0f, "Clock Mode"); - configParam(CLOCK_CHANNEL_FOCUS, 0.f,15.f,0.f,"Clock Channel Selector"); - configParam(INPUT_CHANNEL_FOCUS, 0.f,15.f,0.f,"Input Channel Selector"); + configParam(CLOCK_CHANNEL_FOCUS, 0.f, 15.f, 0.f, "Clock Channel Selector"); + configParam(INPUT_CHANNEL_FOCUS, 0.f, 15.f, 0.f, "Input Channel Selector"); //params[MANUAL_TRIGGER].randomizable=false; //params[MANUAL_CLEAR_TRIGGER].randomizable=false; @@ -87,99 +87,99 @@ struct ComputerscareDebug : Module { void ComputerscareDebug::process(const ProcessArgs &args) { std::string thisVal; - + clockMode = floor(params[WHICH_CLOCK].getValue()); inputMode = floor(params[SWITCH_VIEW].getValue()); inputChannel = floor(params[INPUT_CHANNEL_FOCUS].getValue()); clockChannel = floor(params[CLOCK_CHANNEL_FOCUS].getValue()); - if(clockMode == SINGLE_MODE) { + if (clockMode == SINGLE_MODE) { if (clockTriggers[clockChannel].process(inputs[TRG_INPUT].getVoltage(clockChannel) / 2.f) || manualClockTrigger.process(params[MANUAL_TRIGGER].getValue()) ) { - if(inputMode == POLY_MODE) { - for(int i = 0; i < 16; i++) { + if (inputMode == POLY_MODE) { + for (int i = 0; i < 16; i++) { logLines[i] = inputs[VAL_INPUT].getVoltage(i); } } - else if(inputMode == SINGLE_MODE) { - for( unsigned int a = NUM_LINES-1; a > 0; a = a - 1 ) - { - logLines[a] = logLines[a-1]; - } + else if (inputMode == SINGLE_MODE) { + for ( unsigned int a = NUM_LINES - 1; a > 0; a = a - 1 ) + { + logLines[a] = logLines[a - 1]; + } + - logLines[0] = inputs[VAL_INPUT].getVoltage(inputChannel); } - else if(inputMode == INTERNAL_MODE) { - for(int i = 0; i < 16; i++) { + else if (inputMode == INTERNAL_MODE) { + for (int i = 0; i < 16; i++) { logLines[i] = random::uniform(); } } //thisVal = std::to_string(logLines[0]).substr(0,10); //outputs[POLY_OUTPUT].setVoltage(logLines[0],0); - - + + } } - else if(clockMode == INTERNAL_MODE) { - if(inputMode == POLY_MODE) { - for(int i = 0; i < 16; i++) { - logLines[i] = inputs[VAL_INPUT].getVoltage(i); - } + else if (clockMode == INTERNAL_MODE) { + if (inputMode == POLY_MODE) { + for (int i = 0; i < 16; i++) { + logLines[i] = inputs[VAL_INPUT].getVoltage(i); + } } - else if(inputMode == SINGLE_MODE) { + else if (inputMode == SINGLE_MODE) { logLines[inputChannel] = inputs[VAL_INPUT].getVoltage(inputChannel); } - else if(inputMode == INTERNAL_MODE) { - for(int i = 0; i < 16; i++) { - logLines[i] = random::uniform(); - } + else if (inputMode == INTERNAL_MODE) { + for (int i = 0; i < 16; i++) { + logLines[i] = random::uniform(); + } } } - else if(clockMode == POLY_MODE) { - if(inputMode == POLY_MODE) { - for(int i = 0; i < 16; i++) { + else if (clockMode == POLY_MODE) { + if (inputMode == POLY_MODE) { + for (int i = 0; i < 16; i++) { if (clockTriggers[i].process(inputs[TRG_INPUT].getVoltage(i) / 2.f) || manualClockTrigger.process(params[MANUAL_TRIGGER].getValue()) ) { logLines[i] = inputs[VAL_INPUT].getVoltage(i); } } } - else if(inputMode == SINGLE_MODE) { - for(int i = 0; i < 16; i++) { + else if (inputMode == SINGLE_MODE) { + for (int i = 0; i < 16; i++) { if (clockTriggers[i].process(inputs[TRG_INPUT].getVoltage(i) / 2.f) || manualClockTrigger.process(params[MANUAL_TRIGGER].getValue()) ) { logLines[i] = inputs[VAL_INPUT].getVoltage(inputChannel); } } } - else if(inputMode == INTERNAL_MODE) { - for(int i = 0; i < 16; i++) { + else if (inputMode == INTERNAL_MODE) { + for (int i = 0; i < 16; i++) { if (clockTriggers[i].process(inputs[TRG_INPUT].getVoltage(i) / 2.f) || manualClockTrigger.process(params[MANUAL_TRIGGER].getValue()) ) { logLines[i] = random::uniform(); } } } } - - if(clearTrigger.process(inputs[CLR_INPUT].getVoltage() / 2.f) || manualClearTrigger.process(params[MANUAL_CLEAR_TRIGGER].getValue())) { - for( unsigned int a = 0; a < NUM_LINES; a++ ) - { - logLines[a] = 0; - } + + if (clearTrigger.process(inputs[CLR_INPUT].getVoltage() / 2.f) || manualClearTrigger.process(params[MANUAL_CLEAR_TRIGGER].getValue())) { + for ( unsigned int a = 0; a < NUM_LINES; a++ ) + { + logLines[a] = 0; + } strValue = defaultStrValue; } stepCounter++; - if(stepCounter > 1025) { + if (stepCounter > 1025) { stepCounter = 0; - thisVal = ""; - for( unsigned int a = 0; a < NUM_LINES; a = a + 1 ) - { - thisVal += a > 0 ? "\n" : ""; - thisVal+=logLines[a] >=0 ? "+" : ""; - thisVal+= std::to_string(logLines[a]).substr(0,10); - outputs[POLY_OUTPUT].setVoltage(logLines[a],a); - } - strValue = thisVal; + thisVal = ""; + for ( unsigned int a = 0; a < NUM_LINES; a = a + 1 ) + { + thisVal += a > 0 ? "\n" : ""; + thisVal += logLines[a] >= 0 ? "+" : ""; + thisVal += std::to_string(logLines[a]).substr(0, 10); + outputs[POLY_OUTPUT].setVoltage(logLines[a], a); + } + strValue = thisVal; } outputs[POLY_OUTPUT].setChannels(16); @@ -190,12 +190,12 @@ struct HidableSmallSnapKnob : SmallSnapKnob { ComputerscareDebug *module; HidableSmallSnapKnob() { - + SmallSnapKnob(); } void draw(const DrawArgs &args) { - if(module ? (hackIndex == 0 ? module->clockMode == 0 : module->inputMode == 0) : true) { + if (module ? (hackIndex == 0 ? module->clockMode == 0 : module->inputMode == 0) : true) { Widget::draw(args); } }; @@ -203,51 +203,51 @@ struct HidableSmallSnapKnob : SmallSnapKnob { //////////////////////////////////// struct StringDisplayWidget3 : Widget { - std::string value; - std::shared_ptr<Font> font; - ComputerscareDebug *module; - - StringDisplayWidget3() { - font = APP->window->loadFont(asset::plugin(pluginInstance, "res/Oswald-Regular.ttf")); - }; - - void draw(const DrawArgs &ctx) override - { - // Background - NVGcolor backgroundColor = nvgRGB(0x10, 0x00, 0x10); - NVGcolor StrokeColor = nvgRGB(0xC0, 0xC7, 0xDE); - nvgBeginPath(ctx.vg); - nvgRoundedRect(ctx.vg, -1.0, -1.0, box.size.x+2, box.size.y+2, 4.0); - nvgFillColor(ctx.vg, StrokeColor); - nvgFill(ctx.vg); - nvgBeginPath(ctx.vg); - nvgRoundedRect(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, 4.0); - nvgFillColor(ctx.vg, backgroundColor); - nvgFill(ctx.vg); - - - nvgFontSize(ctx.vg, 15); - nvgFontFaceId(ctx.vg, font->handle); - nvgTextLetterSpacing(ctx.vg, 2.5); - - std::string textToDraw = module ? module->strValue : ""; - Vec textPos = Vec(6.0f, 12.0f); - NVGcolor textColor = nvgRGB(0xC0, 0xE7, 0xDE); - nvgFillColor(ctx.vg, textColor); - - nvgTextBox(ctx.vg, textPos.x, textPos.y,80,textToDraw.c_str(), NULL); - - } + std::string value; + std::shared_ptr<Font> font; + ComputerscareDebug *module; + + StringDisplayWidget3() { + font = APP->window->loadFont(asset::plugin(pluginInstance, "res/Oswald-Regular.ttf")); + }; + + void draw(const DrawArgs &ctx) override + { + // Background + NVGcolor backgroundColor = nvgRGB(0x10, 0x00, 0x10); + NVGcolor StrokeColor = nvgRGB(0xC0, 0xC7, 0xDE); + nvgBeginPath(ctx.vg); + nvgRoundedRect(ctx.vg, -1.0, -1.0, box.size.x + 2, box.size.y + 2, 4.0); + nvgFillColor(ctx.vg, StrokeColor); + nvgFill(ctx.vg); + nvgBeginPath(ctx.vg); + nvgRoundedRect(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, 4.0); + nvgFillColor(ctx.vg, backgroundColor); + nvgFill(ctx.vg); + + + nvgFontSize(ctx.vg, 15); + nvgFontFaceId(ctx.vg, font->handle); + nvgTextLetterSpacing(ctx.vg, 2.5); + + std::string textToDraw = module ? module->strValue : ""; + Vec textPos = Vec(6.0f, 12.0f); + NVGcolor textColor = nvgRGB(0xC0, 0xE7, 0xDE); + nvgFillColor(ctx.vg, textColor); + + nvgTextBox(ctx.vg, textPos.x, textPos.y, 80, textToDraw.c_str(), NULL); + + } }; struct ConnectedSmallLetter : SmallLetterDisplay { ComputerscareDebug *module; int index; ConnectedSmallLetter(int dex) { index = dex; - value = std::to_string(dex+1); + value = std::to_string(dex + 1); } void draw(const DrawArgs &ctx) override { - if(module) { + if (module) { int cm = module->clockMode; int im = module->inputMode; int cc = module->clockChannel; @@ -257,14 +257,14 @@ struct ConnectedSmallLetter : SmallLetterDisplay { // clock: green // input:yellow baseColor = COLOR_COMPUTERSCARE_TRANSPARENT; - if(cm == 0 && im == 0 && cc == index && ic == index) { + if (cm == 0 && im == 0 && cc == index && ic == index) { baseColor = COLOR_COMPUTERSCARE_PINK; - } + } else { - if(cm == 0 && cc == index) { + if (cm == 0 && cc == index) { baseColor = COLOR_COMPUTERSCARE_LIGHT_GREEN; } - if(im == 0 && ic == index) { + if (im == 0 && ic == index) { baseColor = COLOR_COMPUTERSCARE_YELLOW; } } @@ -280,43 +280,43 @@ struct ComputerscareDebugWidget : ModuleWidget { addInput(createInput<InPort>(Vec(2, 335), module, ComputerscareDebug::TRG_INPUT)); addInput(createInput<InPort>(Vec(61, 335), module, ComputerscareDebug::VAL_INPUT)); - addInput(createInput<InPort>(Vec(31, 335), module, ComputerscareDebug::CLR_INPUT)); + addInput(createInput<InPort>(Vec(31, 335), module, ComputerscareDebug::CLR_INPUT)); addParam(createParam<ComputerscareClockButton>(Vec(2, 321), module, ComputerscareDebug::MANUAL_TRIGGER)); addParam(createParam<ComputerscareResetButton>(Vec(32, 320), module, ComputerscareDebug::MANUAL_CLEAR_TRIGGER)); - - addParam(createParam<ThreeVerticalXSwitch>(Vec(2,279),module,ComputerscareDebug::WHICH_CLOCK)); - addParam(createParam<ThreeVerticalXSwitch>(Vec(66,279),module,ComputerscareDebug::SWITCH_VIEW)); - HidableSmallSnapKnob *clockKnob = createParam<HidableSmallSnapKnob>(Vec(6,305),module,ComputerscareDebug::CLOCK_CHANNEL_FOCUS); + addParam(createParam<ThreeVerticalXSwitch>(Vec(2, 279), module, ComputerscareDebug::WHICH_CLOCK)); + addParam(createParam<ThreeVerticalXSwitch>(Vec(66, 279), module, ComputerscareDebug::SWITCH_VIEW)); + + HidableSmallSnapKnob *clockKnob = createParam<HidableSmallSnapKnob>(Vec(6, 305), module, ComputerscareDebug::CLOCK_CHANNEL_FOCUS); clockKnob->module = module; clockKnob->hackIndex = 0; addParam(clockKnob); - - HidableSmallSnapKnob *inputKnob =createParam<HidableSmallSnapKnob>(Vec(66,305),module,ComputerscareDebug::INPUT_CHANNEL_FOCUS); + + HidableSmallSnapKnob *inputKnob = createParam<HidableSmallSnapKnob>(Vec(66, 305), module, ComputerscareDebug::INPUT_CHANNEL_FOCUS); inputKnob->module = module; inputKnob->hackIndex = 1; addParam(inputKnob); addOutput(createOutput<OutPort>(Vec(56, 1), module, ComputerscareDebug::POLY_OUTPUT)); - for(int i = 0; i < 16; i++) { + for (int i = 0; i < 16; i++) { ConnectedSmallLetter *sld = new ConnectedSmallLetter(i); sld->fontSize = 15; - sld->textAlign=1; - sld->box.pos = Vec(-4,33.8+15.08*i); + sld->textAlign = 1; + sld->box.pos = Vec(-4, 33.8 + 15.08 * i); sld->box.size = Vec(28, 20); sld->module = module; addChild(sld); } - StringDisplayWidget3 *stringDisplay = createWidget<StringDisplayWidget3>(Vec(15,34)); + StringDisplayWidget3 *stringDisplay = createWidget<StringDisplayWidget3>(Vec(15, 34)); stringDisplay->box.size = Vec(73, 245); stringDisplay->module = module; addChild(stringDisplay); - + } }; diff --git a/src/ComputerscareKnolyPobs.cpp b/src/ComputerscareKnolyPobs.cpp @@ -13,8 +13,8 @@ struct ComputerscareKnolyPobs : Module { enum ParamIds { KNOB, TOGGLES = KNOB + numKnobs, - NUM_PARAMS = TOGGLES+numToggles - + NUM_PARAMS = TOGGLES + numToggles + }; enum InputIds { CHANNEL_INPUT, @@ -22,7 +22,7 @@ struct ComputerscareKnolyPobs : Module { }; enum OutputIds { POLY_OUTPUT, - NUM_OUTPUTS=POLY_OUTPUT + numOutputs + NUM_OUTPUTS = POLY_OUTPUT + numOutputs }; enum LightIds { NUM_LIGHTS @@ -32,17 +32,17 @@ struct ComputerscareKnolyPobs : Module { ComputerscareKnolyPobs() { config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); - - for (int i = 0; i < numKnobs; i++) { - configParam(KNOB + i, 0.0f, 10.0f, 0.0f); - configParam(KNOB+i, 0.f, 10.f, 0.f, "Channel "+std::to_string(i+1) + " Voltage", " Volts"); + + for (int i = 0; i < numKnobs; i++) { + configParam(KNOB + i, 0.0f, 10.0f, 0.0f); + configParam(KNOB + i, 0.f, 10.f, 0.f, "Channel " + std::to_string(i + 1) + " Voltage", " Volts"); } configParam(TOGGLES, 0.0f, 1.0f, 0.0f); - + } void process(const ProcessArgs &args) override { counter++; - if(counter > 5012) { + if (counter > 5012) { //printf("%f \n",random::uniform()); counter = 0; //rect4032 @@ -50,7 +50,7 @@ struct ComputerscareKnolyPobs : Module { } outputs[POLY_OUTPUT].setChannels(16); for (int i = 0; i < numKnobs; i++) { - outputs[POLY_OUTPUT].setVoltage(params[KNOB+i].getValue(),i); + outputs[POLY_OUTPUT].setVoltage(params[KNOB + i].getValue(), i); } } @@ -58,69 +58,69 @@ struct ComputerscareKnolyPobs : Module { struct ComputerscareKnolyPobsWidget : ModuleWidget { ComputerscareKnolyPobsWidget(ComputerscareKnolyPobs *module) { - + setModule(module); //setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/ComputerscareKnolyPobsPanel.svg"))); - box.size = Vec(4*15, 380); + box.size = Vec(4 * 15, 380); { ComputerscareSVGPanel *panel = new ComputerscareSVGPanel(); panel->box.size = box.size; - panel->setBackground(APP->window->loadSvg(asset::plugin(pluginInstance,"res/ComputerscareKnolyPobsPanel.svg"))); - - //module->panelRef = panel; + panel->setBackground(APP->window->loadSvg(asset::plugin(pluginInstance, "res/ComputerscareKnolyPobsPanel.svg"))); - addChild(panel); + //module->panelRef = panel; + + addChild(panel); } float xx; float yy; - for(int i = 0; i < numKnobs; i++) { - xx=1.4f+24.3*(i%2); - yy=64 + 18.5*(i-i%2) + 11.3*(i%2); - addLabeledKnob(std::to_string(i+1),xx,yy,module,i,0,(i%2)*(11+5*(i<9))-4,0); + for (int i = 0; i < numKnobs; i++) { + xx = 1.4f + 24.3 * (i % 2); + yy = 64 + 18.5 * (i - i % 2) + 11.3 * (i % 2); + addLabeledKnob(std::to_string(i + 1), xx, yy, module, i, 0, (i % 2) * (11 + 5 * (i < 9)) - 4, 0); } - - + + addOutput(createOutput<PointingUpPentagonPort>(Vec(28, 24), module, ComputerscareKnolyPobs::POLY_OUTPUT)); -} -void addLabeledKnob(std::string label,int x, int y, ComputerscareKnolyPobs *module,int index,int type,float labelDx,float labelDy) { - - smallLetterDisplay = new SmallLetterDisplay(); - smallLetterDisplay->box.size = Vec(5, 10); - smallLetterDisplay->fontSize=16; - smallLetterDisplay->value = label; - smallLetterDisplay->textAlign = 1; - if(type == 0) { - addParam(createParam<SmoothKnob>(Vec(x,y),module,ComputerscareKnolyPobs::KNOB+index)); - smallLetterDisplay->box.pos = Vec(x+labelDx,y-12+labelDy); - } - else if(type ==1) { - addParam(createParam<SmallKnob>(Vec(x,y),module,ComputerscareKnolyPobs::KNOB+index)); - smallLetterDisplay->box.pos = Vec(x+12+labelDx,y-10+labelDy); - } - else if(type==2) { - addParam(createParam<BigSmoothKnob>(Vec(x,y),module,ComputerscareKnolyPobs::KNOB+index)); - smallLetterDisplay->box.pos = Vec(x+22+labelDx,y-12+labelDy); - } - else if (type==3) { - addParam(createParam<LrgKnob>(Vec(x,y),module,ComputerscareKnolyPobs::KNOB+index)); - smallLetterDisplay->box.pos = Vec(x+22+labelDx,y-12+labelDy); - } - else if (type==4) { - addParam(createParam<BigSmoothKnob>(Vec(x,y),module,ComputerscareKnolyPobs::KNOB+index)); - smallLetterDisplay->box.pos = Vec(x+22+labelDx,y-12+labelDy); - } - - else { - addParam(createParam<MediumSnapKnob>(Vec(x,y),module,ComputerscareKnolyPobs::KNOB+index)); - smallLetterDisplay->box.pos = Vec(x+12,y-10); - } - addChild(smallLetterDisplay); - -} -SmallLetterDisplay* smallLetterDisplay; + } + void addLabeledKnob(std::string label, int x, int y, ComputerscareKnolyPobs *module, int index, int type, float labelDx, float labelDy) { + + smallLetterDisplay = new SmallLetterDisplay(); + smallLetterDisplay->box.size = Vec(5, 10); + smallLetterDisplay->fontSize = 16; + smallLetterDisplay->value = label; + smallLetterDisplay->textAlign = 1; + if (type == 0) { + addParam(createParam<SmoothKnob>(Vec(x, y), module, ComputerscareKnolyPobs::KNOB + index)); + smallLetterDisplay->box.pos = Vec(x + labelDx, y - 12 + labelDy); + } + else if (type == 1) { + addParam(createParam<SmallKnob>(Vec(x, y), module, ComputerscareKnolyPobs::KNOB + index)); + smallLetterDisplay->box.pos = Vec(x + 12 + labelDx, y - 10 + labelDy); + } + else if (type == 2) { + addParam(createParam<BigSmoothKnob>(Vec(x, y), module, ComputerscareKnolyPobs::KNOB + index)); + smallLetterDisplay->box.pos = Vec(x + 22 + labelDx, y - 12 + labelDy); + } + else if (type == 3) { + addParam(createParam<LrgKnob>(Vec(x, y), module, ComputerscareKnolyPobs::KNOB + index)); + smallLetterDisplay->box.pos = Vec(x + 22 + labelDx, y - 12 + labelDy); + } + else if (type == 4) { + addParam(createParam<BigSmoothKnob>(Vec(x, y), module, ComputerscareKnolyPobs::KNOB + index)); + smallLetterDisplay->box.pos = Vec(x + 22 + labelDx, y - 12 + labelDy); + } + + else { + addParam(createParam<MediumSnapKnob>(Vec(x, y), module, ComputerscareKnolyPobs::KNOB + index)); + smallLetterDisplay->box.pos = Vec(x + 12, y - 10); + } + addChild(smallLetterDisplay); + + } + SmallLetterDisplay* smallLetterDisplay; }; Model *modelComputerscareKnolyPobs = createModel<ComputerscareKnolyPobs, ComputerscareKnolyPobsWidget>("computerscare-knolypobs"); diff --git a/src/ComputerscareOhPeas.cpp b/src/ComputerscareOhPeas.cpp @@ -54,7 +54,7 @@ struct PeasTextField : LedDisplayTextField } void draw(const DrawArgs &args) override { - if(module) + if (module) { nvgScissor(args.vg, 0, 0, box.size.x, box.size.y); @@ -63,7 +63,7 @@ struct PeasTextField : LedDisplayTextField nvgBeginPath(args.vg); nvgRoundedRect(args.vg, 0, 0, box.size.x, box.size.y, 10.0); - if(inError) + if (inError) { nvgFillColor(args.vg, COLOR_COMPUTERSCARE_PINK); } @@ -150,7 +150,7 @@ struct ComputerscareOhPeas : Module config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); configParam(GLOBAL_TRANSPOSE, -1.f, 1.f, 0.0f, "Global Transpose"); configParam(NUM_DIVISIONS, 1.f, 24.f, 12.0f, "Number of Divisions"); - for(int i = 0; i < numChannels; i++) + for (int i = 0; i < numChannels; i++) { std::string chi = "Ch. " + std::to_string(i + 1); configParam( SCALE_TRIM + i, -1.f, 1.f, 0.0f, chi + " Scale CV Amount"); @@ -178,33 +178,6 @@ struct ComputerscareOhPeas : Module } void process(const ProcessArgs &args) override; - /* json_t *toJson() override - { - json_t *rootJ = json_object(); - - json_t *sequencesJ = json_array(); - for (int i = 0; i < 1; i++) { - json_t *sequenceJ = json_string(textField->text.c_str()); - json_array_append_new(sequencesJ, sequenceJ); - } - json_object_set_new(rootJ, "sequences", sequencesJ); - - return rootJ; - } - - void fromJson(json_t *rootJ) override - { - json_t *sequencesJ = json_object_get(rootJ, "sequences"); - if (sequencesJ) { - for (int i = 0; i < 1; i++) { - json_t *sequenceJ = json_array_get(sequencesJ, i); - if (sequenceJ) - textField->text = json_string_value(sequenceJ); - } - } - setQuant(); - }*/ - void setQuant() @@ -230,26 +203,26 @@ void ComputerscareOhPeas::process(const ProcessArgs &args) //int globalTransposeKnobValue = (int) clamp(roundf(params[GLOBAL_TRANSPOSE].getValue()), -fNumDiv, fNumDiv); - if(numDivisionsKnobValue != numDivisions) + if (numDivisionsKnobValue != numDivisions) { //printf("%i, %i, %i, %i\n",numDivisionsKnobValue,numDivisions,iTranspose,globalTranspose); //what a hack!!! - if(numDivisionsKnobValue != 0) + if (numDivisionsKnobValue != 0) { numDivisions = numDivisionsKnobValue; setQuant(); } } - if(iTranspose != globalTranspose) + if (iTranspose != globalTranspose) { //printf("%i, %i, %i, %i\n",numDivisionsKnobValue,numDivisions,iTranspose,globalTranspose); globalTranspose = iTranspose; setQuant(); } - for(int i = 0; i < numChannels; i++) + for (int i = 0; i < numChannels; i++) { a = params[SCALE_VAL + i].getValue(); @@ -271,50 +244,6 @@ void ComputerscareOhPeas::process(const ProcessArgs &args) } } -//////////////////////////////////// -struct StringDisplayWidget3 : TransparentWidget -{ - - std::string *value; - std::shared_ptr<Font> font; - - StringDisplayWidget3() - { - font = APP->window->loadFont(asset::plugin(pluginInstance, "res/Oswald-Regular.ttf")); - }; - - void draw(const DrawArgs &args) override - { - // Background - NVGcolor backgroundColor = nvgRGB(0x10, 0x00, 0x10); - NVGcolor StrokeColor = nvgRGB(0xC0, 0xC7, 0xDE); - nvgBeginPath(args.vg); - nvgRoundedRect(args.vg, -1.0, -1.0, box.size.x + 2, box.size.y + 2, 4.0); - nvgFillColor(args.vg, StrokeColor); - nvgFill(args.vg); - nvgBeginPath(args.vg); - nvgRoundedRect(args.vg, 0.0, 0.0, box.size.x, box.size.y, 4.0); - nvgFillColor(args.vg, backgroundColor); - nvgFill(args.vg); - - // text - nvgFontSize(args.vg, 15); - nvgFontFaceId(args.vg, font->handle); - nvgTextLetterSpacing(args.vg, 2.5); - - std::stringstream to_display; - to_display << std::setw(8) << *value; - - Vec textPos = Vec(6.0f, 12.0f); - NVGcolor textColor = nvgRGB(0xC0, 0xE7, 0xDE); - nvgFillColor(args.vg, textColor); - nvgTextBox(args.vg, textPos.x, textPos.y, 80, to_display.str().c_str(), NULL); - - } -}; - - - struct SetQuantizationModeMenuItem : MenuItem { ComputerscareOhPeas *peas; @@ -347,9 +276,9 @@ struct PeasTF2 : ComputerscareTextField }; void draw(const DrawArgs &args) override { - if(module) + if (module) { - if(text.c_str() != module->currentFormula) + if (text.c_str() != module->currentFormula) { module->currentFormula = text.c_str(); module->setQuant(); @@ -373,9 +302,9 @@ struct PeasSmallDisplay : SmallLetterDisplay void draw(const DrawArgs &args) { //this->setNumDivisionsString(); - if(module) + if (module) { - if(type == 0) + if (type == 0) { std::string transposeString = (module->globalTranspose > 0 ? "+" : "" ) + std::to_string(module->globalTranspose); @@ -460,7 +389,7 @@ struct ComputerscareOhPeasWidget : ModuleWidget transposeDisplay->baseColor = COLOR_COMPUTERSCARE_LIGHT_GREEN; addChild(transposeDisplay); - for(int i = 0; i < numChannels; i++) + for (int i = 0; i < numChannels; i++) { xx = x + dx * i + randAmt * (2 * random::uniform() - .5); @@ -560,9 +489,9 @@ void ComputerscareOhPeasWidget::appendContextMenu(Menu *menu) scaleItemAdd(peas, menu, "32113", "Blues"); scaleItemAdd(peas, menu, "11111111111", "Chromatic"); scaleItemAdd(peas, menu, "212213", "Harmonic Minor"); - scaleItemAdd(peas,menu,"22222","Whole-Tone"); - scaleItemAdd(peas,menu,"2121212","Whole-Half Diminished"); - + scaleItemAdd(peas, menu, "22222", "Whole-Tone"); + scaleItemAdd(peas, menu, "2121212", "Whole-Half Diminished"); + scaleItemAdd(peas, menu, "43", "Major Triad"); scaleItemAdd(peas, menu, "34", "Minor Triad"); scaleItemAdd(peas, menu, "33", "Diminished Triad"); diff --git a/src/ComputerscarePatchSequencer.cpp b/src/ComputerscarePatchSequencer.cpp @@ -13,30 +13,30 @@ const int numOutputs = 10; struct ComputerscareDebug; struct ComputerscarePatchSequencer : Module { - enum ParamIds { + enum ParamIds { STEPS_PARAM, MANUAL_CLOCK_PARAM, EDIT_PARAM, EDIT_PREV_PARAM, - ENUMS(SWITCHES,100), + ENUMS(SWITCHES, 100), RESET_PARAM, - NUM_PARAMS - }; - enum InputIds { - TRG_INPUT, - ENUMS(INPUT_JACKS, 10), - RANDOMIZE_INPUT, - RESET_INPUT, - NUM_INPUTS - }; - enum OutputIds { - OUTPUTS, - NUM_OUTPUTS = OUTPUTS + 10 - }; + NUM_PARAMS + }; + enum InputIds { + TRG_INPUT, + ENUMS(INPUT_JACKS, 10), + RANDOMIZE_INPUT, + RESET_INPUT, + NUM_INPUTS + }; + enum OutputIds { + OUTPUTS, + NUM_OUTPUTS = OUTPUTS + 10 + }; enum LightIds { - SWITCH_LIGHTS, - NUM_LIGHTS = SWITCH_LIGHTS + 200 - }; + SWITCH_LIGHTS, + NUM_LIGHTS = SWITCH_LIGHTS + 200 + }; rack::dsp::SchmittTrigger switch_triggers[10][10]; @@ -52,51 +52,51 @@ struct ComputerscarePatchSequencer : Module { int editAddress = 0; int addressPlusOne = 1; int editAddressPlusOne = 1; - + int numAddresses = 2; bool switch_states[maxSteps][10][10] = {}; - + bool onlyRandomizeActive = true; - - float input_values[numInputs] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}; - float sums[numOutputs] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}; - + + float input_values[numInputs] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; + float sums[numOutputs] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; + int randomizationStepEnum = 0; //0: edit step, 1: active step, 2: all steps int randomizationOutputBoundsEnum = 1; //0: randomize exactly one per output, 1: randomize exactly one per output, 2: randomize 1 or more, 3: randomize 0 or more -ComputerscarePatchSequencer() { - config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); + ComputerscarePatchSequencer() { + config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); - // configParam(GLOBAL_TRANSPOSE, -1.f, 1.f, 0.0f, "Global Transpose"); + // configParam(GLOBAL_TRANSPOSE, -1.f, 1.f, 0.0f, "Global Transpose"); + + } + void process(const ProcessArgs &args) override; - } - void process(const ProcessArgs &args) override; - int getRandomizationStepEnum() { - return randomizationStepEnum; - } - - int getRandomizationOutputBoundsEnum() { + return randomizationStepEnum; + } + + int getRandomizationOutputBoundsEnum() { return randomizationOutputBoundsEnum; } - void setRandomizationStepEnum(int randomizationStep) { - randomizationStepEnum = randomizationStep; - } + void setRandomizationStepEnum(int randomizationStep) { + randomizationStepEnum = randomizationStep; + } void setRandomizationOutputBoundsEnum(int randomizationOutputBounds) { randomizationOutputBoundsEnum = randomizationOutputBounds; } - void onRandomize() override { - randomizePatchMatrix(); - } + void onRandomize() override { + randomizePatchMatrix(); + } void randomizePatchMatrix() { - if(onlyRandomizeActive) { + if (onlyRandomizeActive) { randomizeMatrixOnlyActive(); } else { @@ -105,90 +105,90 @@ ComputerscarePatchSequencer() { }; - // For more advanced Module features, read Rack's engine.hpp header file - // - toJson, fromJson: serialization of internal data - // - onSampleRateChange: event triggered by a change of sample rate - // - onReset, onRandomize, onCreate, onDelete: implements special behavior when user clicks these from the context menu - - void randomizeMatrixOnlyActive() { - int randomIndex; - - bool connectedInputs[10]; - bool connectedOutputs[10]; - int numConnectedInputs=0; - - std::vector<int> connectedInputIndices; - - for (int i = 0; i < 10; i++) - { - if(inputs[INPUT_JACKS + i].isConnected()) { - numConnectedInputs++; - connectedInputIndices.push_back(i); - } - connectedInputs[i] = inputs[INPUT_JACKS + i].isConnected(); - connectedOutputs[i] = outputs[OUTPUTS + i].isConnected(); - } - for(int k = 0; k < maxSteps; k++) { - if((randomizationStepEnum == 0 && k == editAddress) || (randomizationStepEnum == 1 && k == address) || randomizationStepEnum == 2) { - for(int i = 0; i < 10; i++) { - randomIndex = numConnectedInputs > 0 ? connectedInputIndices[floor(random::uniform()*numConnectedInputs)] : 0; - if(connectedOutputs[i]) { - for (int j = 0; j < 10; j++) { - if(j==randomIndex) - switch_states[k][j][i] = 1; - else - switch_states[k][j][i]=0; - } - } - } - } - } - - } - - void randomizeMatrixIncludingDisconnected() { - int randomIndex; - for(int k = 0; k < maxSteps; k++) { - if((randomizationStepEnum == 0 && k == editAddress) || (randomizationStepEnum == 1 && k == address) || randomizationStepEnum == 2) { - for (int i = 0; i < 10; i++) - { - randomIndex = floor(random::uniform()*10); - - for (int j = 0; j < 10; j++) - { - if(randomizationOutputBoundsEnum == 3) { - switch_states[k][j][i] = (j==randomIndex || random::uniform() < 0.2) ? 1 : 0; + // For more advanced Module features, read Rack's engine.hpp header file + // - toJson, fromJson: serialization of internal data + // - onSampleRateChange: event triggered by a change of sample rate + // - onReset, onRandomize, onCreate, onDelete: implements special behavior when user clicks these from the context menu + + void randomizeMatrixOnlyActive() { + int randomIndex; + + bool connectedInputs[10]; + bool connectedOutputs[10]; + int numConnectedInputs = 0; + + std::vector<int> connectedInputIndices; + + for (int i = 0; i < 10; i++) + { + if (inputs[INPUT_JACKS + i].isConnected()) { + numConnectedInputs++; + connectedInputIndices.push_back(i); + } + connectedInputs[i] = inputs[INPUT_JACKS + i].isConnected(); + connectedOutputs[i] = outputs[OUTPUTS + i].isConnected(); + } + for (int k = 0; k < maxSteps; k++) { + if ((randomizationStepEnum == 0 && k == editAddress) || (randomizationStepEnum == 1 && k == address) || randomizationStepEnum == 2) { + for (int i = 0; i < 10; i++) { + randomIndex = numConnectedInputs > 0 ? connectedInputIndices[floor(random::uniform() * numConnectedInputs)] : 0; + if (connectedOutputs[i]) { + for (int j = 0; j < 10; j++) { + if (j == randomIndex) + switch_states[k][j][i] = 1; + else + switch_states[k][j][i] = 0; } - else if(randomizationOutputBoundsEnum == 2) { - switch_states[k][j][i] = random::uniform() < 0.2 ? 1 : 0; + } + } + } + } + + } + + void randomizeMatrixIncludingDisconnected() { + int randomIndex; + for (int k = 0; k < maxSteps; k++) { + if ((randomizationStepEnum == 0 && k == editAddress) || (randomizationStepEnum == 1 && k == address) || randomizationStepEnum == 2) { + for (int i = 0; i < 10; i++) + { + randomIndex = floor(random::uniform() * 10); + + for (int j = 0; j < 10; j++) + { + if (randomizationOutputBoundsEnum == 3) { + switch_states[k][j][i] = (j == randomIndex || random::uniform() < 0.2) ? 1 : 0; + } + else if (randomizationOutputBoundsEnum == 2) { + switch_states[k][j][i] = random::uniform() < 0.2 ? 1 : 0; + } + else if (randomizationOutputBoundsEnum == 0) { + switch_states[k][j][i] = (j == randomIndex && random::uniform() < 0.7) ? 1 : 0; } - else if(randomizationOutputBoundsEnum == 0) { - switch_states[k][j][i] = (j==randomIndex && random::uniform() < 0.7) ? 1 : 0; + else { + switch_states[k][j][i] = j == randomIndex ? 1 : 0; } - else { - switch_states[k][j][i] = j==randomIndex ? 1 : 0; - } - } - } - } - } + } + } + } + } } - void onReset() override - { - for(int k =0; k < maxSteps; k++) { - - - for (int i = 0; i < 10; i++) - { - for (int j = 0; j < 10; j++) - { - switch_states[k][i][j] = 0; - } - } - } - }; // end randomize() + void onReset() override + { + for (int k = 0; k < maxSteps; k++) { + + + for (int i = 0; i < 10; i++) + { + for (int j = 0; j < 10; j++) + { + switch_states[k][i][j] = 0; + } + } + } + }; // end randomize() }; @@ -200,49 +200,49 @@ void ComputerscarePatchSequencer::process(const ProcessArgs &args) { for ( int i = 0 ; i < 10 ; i++) { - sums[i] = 0.0; + sums[i] = 0.0; } for (int i = 0 ; i < 10 ; i++) { - for (int j = 0 ; j < 10 ; j++) - { - if (switch_triggers[i][j].process(params[SWITCHES+j*10 + i].getValue())) - { - // handle button clicks in the patch matrix - switch_states[editAddress][i][j] = !switch_states[editAddress][i][j]; - } - // update the green lights (step you are editing) and the red lights (current active step) - lights[SWITCH_LIGHTS + i + j * 10].value = (switch_states[editAddress][i][j]) ? 1.0 : 0.0; - lights[SWITCH_LIGHTS + i + j * 10+100].value = (switch_states[address][i][j]) ? 1.0 : 0.0; - } + for (int j = 0 ; j < 10 ; j++) + { + if (switch_triggers[i][j].process(params[SWITCHES + j * 10 + i].getValue())) + { + // handle button clicks in the patch matrix + switch_states[editAddress][i][j] = !switch_states[editAddress][i][j]; + } + // update the green lights (step you are editing) and the red lights (current active step) + lights[SWITCH_LIGHTS + i + j * 10].value = (switch_states[editAddress][i][j]) ? 1.0 : 0.0; + lights[SWITCH_LIGHTS + i + j * 10 + 100].value = (switch_states[address][i][j]) ? 1.0 : 0.0; + } } - if(numStepsKnobPosition != numAddresses) { - numAddresses = numStepsKnobPosition; + if (numStepsKnobPosition != numAddresses) { + numAddresses = numStepsKnobPosition; } - if(randomizeTrigger.process(inputs[RANDOMIZE_INPUT].getVoltage() / 2.f)) { - randomizePatchMatrix(); + if (randomizeTrigger.process(inputs[RANDOMIZE_INPUT].getVoltage() / 2.f)) { + randomizePatchMatrix(); } - if(nextAddressEdit.process(params[EDIT_PARAM].getValue()) ) { + if (nextAddressEdit.process(params[EDIT_PARAM].getValue()) ) { editAddress = editAddress + 1; editAddress = editAddress % maxSteps; } - if(prevAddressEdit.process(params[EDIT_PREV_PARAM].getValue()) ) { + if (prevAddressEdit.process(params[EDIT_PREV_PARAM].getValue()) ) { editAddress = editAddress - 1; editAddress = editAddress + maxSteps; editAddress = editAddress % maxSteps; } - if(nextAddressRead.process(params[MANUAL_CLOCK_PARAM].getValue()) || clockTrigger.process(inputs[TRG_INPUT].getVoltage() / 2.f)) { + if (nextAddressRead.process(params[MANUAL_CLOCK_PARAM].getValue()) || clockTrigger.process(inputs[TRG_INPUT].getVoltage() / 2.f)) { numAddresses = (int) clamp(roundf(params[STEPS_PARAM].getValue() /*+ inputs[STEPS_INPUT].getVoltage()*/), 1.0f, 16.0f); address = address + 1; address = address % numAddresses; } - if(resetTriggerButton.process(params[RESET_PARAM].getValue()) || resetTriggerInput.process(inputs[RESET_INPUT].getVoltage() / 2.f)) { + if (resetTriggerButton.process(params[RESET_PARAM].getValue()) || resetTriggerInput.process(inputs[RESET_INPUT].getVoltage() / 2.f)) { numAddresses = (int) clamp(roundf(params[STEPS_PARAM].getValue()), 1.0f, 16.0f); address = 0; @@ -255,22 +255,22 @@ void ComputerscarePatchSequencer::process(const ProcessArgs &args) { { input_values[i] = inputs[INPUT_JACKS + i].getVoltage(); } - + for (int i = 0 ; i < 10 ; i++) { - for (int j = 0 ; j < 10 ; j++) - { - // todo: toggle for each output of how to combine multiple active signals in a column - // sum, average, and, or etc - if (switch_states[address][j][i]) { + for (int j = 0 ; j < 10 ; j++) + { + // todo: toggle for each output of how to combine multiple active signals in a column + // sum, average, and, or etc + if (switch_states[address][j][i]) { sums[i] += input_values[j]; } - } + } } - /// outputs + /// outputs for (int i = 0 ; i < 10 ; i++) { - outputs[OUTPUTS + i].setVoltage(sums[i]); + outputs[OUTPUTS + i].setVoltage(sums[i]); } } @@ -278,6 +278,7 @@ void ComputerscarePatchSequencer::process(const ProcessArgs &args) { struct NumberDisplayWidget3 : TransparentWidget { int *value; + ComputerscarePatchSequencer *module; std::shared_ptr<Font> font; NumberDisplayWidget3() { @@ -287,25 +288,27 @@ struct NumberDisplayWidget3 : TransparentWidget { void draw(const DrawArgs &args) override { // Background - NVGcolor backgroundColor = nvgRGB(0x00, 0x00, 0x00); - - nvgBeginPath(args.vg); - nvgRoundedRect(args.vg, 0.0, 0.0, box.size.x, box.size.y, 4.0); - nvgFillColor(args.vg, backgroundColor); - nvgFill(args.vg); - - // text - nvgFontSize(args.vg, 13); - nvgFontFaceId(args.vg, font->handle); - nvgTextLetterSpacing(args.vg, 2.5); - - std::stringstream to_display; - to_display << std::setw(3) << *value; - - Vec textPos = Vec(6.0f, 17.0f); - NVGcolor textColor = nvgRGB(0xC0, 0xE7, 0xDE); - nvgFillColor(args.vg, textColor); - nvgText(args.vg, textPos.x, textPos.y, to_display.str().c_str(), NULL); + if (module) { + NVGcolor backgroundColor = nvgRGB(0x00, 0x00, 0x00); + + nvgBeginPath(args.vg); + nvgRoundedRect(args.vg, 0.0, 0.0, box.size.x, box.size.y, 4.0); + nvgFillColor(args.vg, backgroundColor); + nvgFill(args.vg); + + // text + nvgFontSize(args.vg, 13); + nvgFontFaceId(args.vg, font->handle); + nvgTextLetterSpacing(args.vg, 2.5); + + std::stringstream to_display; + to_display << std::setw(3) << *value; + + Vec textPos = Vec(6.0f, 17.0f); + NVGcolor textColor = nvgRGB(0xC0, 0xE7, 0xDE); + nvgFillColor(args.vg, textColor); + nvgText(args.vg, textPos.x, textPos.y, to_display.str().c_str(), NULL); + } } }; @@ -314,189 +317,191 @@ struct NumberDisplayWidget3 : TransparentWidget { struct ComputerscarePatchSequencerWidget : ModuleWidget { ComputerscarePatchSequencerWidget(ComputerscarePatchSequencer *module) { - setModule(module); - setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/ComputerscarePatchSequencerPanel.svg"))); + setModule(module); + setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/ComputerscarePatchSequencerPanel.svg"))); - int top_row = 70; - int row_spacing = 26; - int column_spacing = 26; + int top_row = 70; + int row_spacing = 26; + int column_spacing = 26; - int rdx = rand() % 8; - int rdy = rand() % 8; + int rdx = rand() % 8; + int rdy = rand() % 8; + + for (int i = 0 ; i < 10 ; i++) + { - for (int i = 0 ; i < 10 ; i++) - { + for (int j = 0 ; j < 10 ; j++ ) + { + // the part you click + //addParam(ParamWidget::create<LEDButton>(Vec(35 + column_spacing * j+2, top_row + row_spacing * i+4), module, ComputerscarePatchSequencer::SWITCHES + i + j * 10, 0.0, 1.0, 0.0)); + //addParam(createParam<LEDButton>(Vec(35 + column_spacing * j+2, top_row + row_spacing * i+4), module, ComputerscarePatchSequencer::SWITCHES + i + j * 10)); - for(int j = 0 ; j < 10 ; j++ ) - { - // the part you click - //addParam(ParamWidget::create<LEDButton>(Vec(35 + column_spacing * j+2, top_row + row_spacing * i+4), module, ComputerscarePatchSequencer::SWITCHES + i + j * 10, 0.0, 1.0, 0.0)); - addParam(createParam<LEDButton>(Vec(35 + column_spacing * j+2, top_row + row_spacing * i+4), module, ComputerscarePatchSequencer::SWITCHES + i + j * 10)); + // green light indicates the state of the matrix that is being edited + //ModuleLightWidget *bigOne = ModuleLightWidget::create<ComputerscareHugeLight<ComputerscareGreenLight>>(Vec(35 + column_spacing * j +0.4, top_row + row_spacing * i +2.4 ), module, ComputerscarePatchSequencer::SWITCH_LIGHTS + i + j * 10); + //addParam(createParam<ComputerscareHugeLight>(Vec(35 + column_spacing * j +0.4, top_row + row_spacing * i +2.4 ), module, ComputerscarePatchSequencer::SWITCH_LIGHTS + i + j * 10)); - // green light indicates the state of the matrix that is being edited - //ModuleLightWidget *bigOne = ModuleLightWidget::create<ComputerscareHugeLight<ComputerscareGreenLight>>(Vec(35 + column_spacing * j +0.4, top_row + row_spacing * i +2.4 ), module, ComputerscarePatchSequencer::SWITCH_LIGHTS + i + j * 10); - addParam(createParam<ComputerscareHugeLight>(Vec(35 + column_spacing * j +0.4, top_row + row_spacing * i +2.4 ), module, ComputerscarePatchSequencer::SWITCH_LIGHTS + i + j * 10)); - //addParam(createParam<LEDButton>(Vec(35 + column_spacing * j+2, top_row + row_spacing * i+4), module, ComputerscarePatchSequencer::SWITCHES + i + j * 10)); - //addChild(bigOne); - - double xpos = 35 + column_spacing * j + 6.3 + rand() % 8 - 4; - double ypos = top_row + row_spacing * i + 8.3 + rand() % 8 - 4; - // red light indicates the state of the matrix that is the active step - //computerscarered - addParam(createParam<ComputerscareSmallLight>(Vec(xpos, ypos), module, ComputerscarePatchSequencer::SWITCH_LIGHTS + i + j * 10 + 100)); - addParam(createParam<ComputerscareSmallLight>(Vec(xpos + rdx, ypos + rdy), module, ComputerscarePatchSequencer::SWITCH_LIGHTS + i + j * 10 + 100)); + //addChild(bigOne); + + double xpos = 35 + column_spacing * j + 6.3 + rand() % 8 - 4; + double ypos = top_row + row_spacing * i + 8.3 + rand() % 8 - 4; + // red light indicates the state of the matrix that is the active step + //computerscarered + //addParam(createParam<ComputerscareSmallLight>(Vec(xpos, ypos), module, ComputerscarePatchSequencer::SWITCH_LIGHTS + i + j * 10 + 100)); + //addParam(createParam<ComputerscareSmallLight>(Vec(xpos + rdx, ypos + rdy), module, ComputerscarePatchSequencer::SWITCH_LIGHTS + i + j * 10 + 100)); - } + } // addInput(createInput<InPort>(mm2px(Vec(xx, y - 0.8)), module, ComputerscareOhPeas::CHANNEL_INPUT + i)); - addInput(createInput<InPort>(Vec(3, i * row_spacing + top_row), module, ComputerscarePatchSequencer::INPUT_JACKS + i)); - - if(i % 2) { - addOutput(createOutput<PointingUpPentagonPort>(Vec(33 + i * column_spacing , top_row + 10 * row_spacing), module, ComputerscarePatchSequencer::OUTPUTS + i)); - } - else { - addOutput(createOutput<InPort>(Vec(33 + i * column_spacing , top_row + 10 * row_spacing), module, ComputerscarePatchSequencer::OUTPUTS + i)); - } - } - - //clock input - addInput(createInput<InPort>(Vec(24, 37), module, ComputerscarePatchSequencer::TRG_INPUT)); - - //reset input - addInput(createInput<InPort>(Vec(24, 3), module, ComputerscarePatchSequencer::RESET_INPUT)); - - //manual clock button - addParam(createParam<LEDButton>(Vec(7 , 37), module, ComputerscarePatchSequencer::MANUAL_CLOCK_PARAM)); - - //reset button - addParam(createParam<LEDButton>(Vec(7 , 3), module, ComputerscarePatchSequencer::RESET_PARAM)); - - //randomize input - addInput(createInput<InPort>(Vec(270, 0), module, ComputerscarePatchSequencer::RANDOMIZE_INPUT)); - - //active step display - NumberDisplayWidget3 *display = new NumberDisplayWidget3(); - display->box.pos = Vec(56,40); - display->box.size = Vec(50, 20); - display->value = &module->addressPlusOne; - addChild(display); - - // number of steps display - NumberDisplayWidget3 *stepsDisplay = new NumberDisplayWidget3(); - stepsDisplay->box.pos = Vec(150,40); - stepsDisplay->box.size = Vec(50, 20); - stepsDisplay->value = &module->numAddresses; - addChild(stepsDisplay); - - //number-of-steps dial. Discrete, 16 positions - ParamWidget* stepsKnob = createParam<LrgKnob>(Vec(108,30), module, ComputerscarePatchSequencer::STEPS_PARAM); - addParam(stepsKnob); - - //editAddressNext button - addParam(createParam<LEDButton>(Vec(227 , 41), module, ComputerscarePatchSequencer::EDIT_PARAM)); - - //editAddressPrevious button - addParam(createParam<LEDButton>(Vec(208 , 41), module, ComputerscarePatchSequencer::EDIT_PREV_PARAM)); - - // currently editing step #: - NumberDisplayWidget3 *displayEdit = new NumberDisplayWidget3(); - displayEdit->box.pos = Vec(246,40); - displayEdit->box.size = Vec(50, 20); - displayEdit->value = &module->editAddressPlusOne; - addChild(displayEdit); - printf("ujje\n"); - fatherSon = module; - } + addInput(createInput<InPort>(Vec(3, i * row_spacing + top_row), module, ComputerscarePatchSequencer::INPUT_JACKS + i)); + + if (i % 2) { + addOutput(createOutput<PointingUpPentagonPort>(Vec(33 + i * column_spacing , top_row + 10 * row_spacing), module, ComputerscarePatchSequencer::OUTPUTS + i)); + } + else { + addOutput(createOutput<InPort>(Vec(33 + i * column_spacing , top_row + 10 * row_spacing), module, ComputerscarePatchSequencer::OUTPUTS + i)); + } + } + //clock input + addInput(createInput<InPort>(Vec(24, 37), module, ComputerscarePatchSequencer::TRG_INPUT)); + + //reset input + addInput(createInput<InPort>(Vec(24, 3), module, ComputerscarePatchSequencer::RESET_INPUT)); + + //manual clock button + addParam(createParam<LEDButton>(Vec(7 , 37), module, ComputerscarePatchSequencer::MANUAL_CLOCK_PARAM)); + + //reset button + //addParam(createParam<LEDButton>(Vec(7 , 3), module, ComputerscarePatchSequencer::RESET_PARAM)); + + //randomize input + addInput(createInput<InPort>(Vec(270, 0), module, ComputerscarePatchSequencer::RANDOMIZE_INPUT)); + + //active step display + /*NumberDisplayWidget3 *display = new NumberDisplayWidget3(); + display->box.pos = Vec(56,40); + display->box.size = Vec(50, 20); + display->value = &module->addressPlusOne; + display->module = module; + addChild(display); + + // number of steps display + NumberDisplayWidget3 *stepsDisplay = new NumberDisplayWidget3(); + stepsDisplay->box.pos = Vec(150,40); + stepsDisplay->box.size = Vec(50, 20); + stepsDisplay->module = module; + stepsDisplay->value = &module->numAddresses; + addChild(stepsDisplay); + + //number-of-steps dial. Discrete, 16 positions + ParamWidget* stepsKnob = createParam<LrgKnob>(Vec(108,30), module, ComputerscarePatchSequencer::STEPS_PARAM); + addParam(stepsKnob); + + //editAddressNext button + addParam(createParam<LEDButton>(Vec(227 , 41), module, ComputerscarePatchSequencer::EDIT_PARAM)); + + //editAddressPrevious button + addParam(createParam<LEDButton>(Vec(208 , 41), module, ComputerscarePatchSequencer::EDIT_PREV_PARAM)); + + // currently editing step #: + NumberDisplayWidget3 *displayEdit = new NumberDisplayWidget3(); + displayEdit->box.pos = Vec(246,40); + displayEdit->box.size = Vec(50, 20); + displayEdit->module = module; + displayEdit->value = &module->editAddressPlusOne; + addChild(displayEdit);*/ + printf("ujje\n"); + fatherSon = module; + } json_t *toJson() override { - json_t *rootJ = json_object(); - + json_t *rootJ = ModuleWidget::toJson(); // button states json_t *button_statesJ = json_array(); - for(int k = 0; k < maxSteps; k++) { - for (int i = 0; i < 10; i++) - { - for (int j = 0; j < 10; j++) + for (int k = 0; k < maxSteps; k++) { + for (int i = 0; i < 10; i++) { - json_t *button_stateJ = json_integer((int) fatherSon->switch_states[k][i][j]); - json_array_append_new(button_statesJ, button_stateJ); + for (int j = 0; j < 10; j++) + { + json_t *button_stateJ = json_integer((int) fatherSon->switch_states[k][i][j]); + json_array_append_new(button_statesJ, button_stateJ); } } } - json_object_set_new(rootJ, "buttons", button_statesJ); + json_object_set_new(rootJ, "buttons", button_statesJ); json_object_set_new(rootJ, "onlyRandomizeActive", json_boolean(fatherSon->onlyRandomizeActive)); json_object_set_new(rootJ, "randomizationStepEnum", json_integer(fatherSon->getRandomizationStepEnum())); json_object_set_new(rootJ, "randomizationOutputBoundsEnum", json_integer(fatherSon->getRandomizationOutputBoundsEnum())); return rootJ; - } - + } + void fromJson(json_t *rootJ) override { + ModuleWidget::fromJson(rootJ); // button states - json_t *button_statesJ = json_object_get(rootJ, "buttons"); - if (button_statesJ) + json_t *button_statesJ = json_object_get(rootJ, "buttons"); + if (button_statesJ) { - for(int k = 0; k < maxSteps; k++) { - - for (int i = 0; i < 10; i++) { - for (int j = 0; j < 10; j++) { - json_t *button_stateJ = json_array_get(button_statesJ, k*100+i*10 + j); - if (button_stateJ) - fatherSon->switch_states[k][i][j] = !!json_integer_value(button_stateJ); + for (int k = 0; k < maxSteps; k++) { + + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + json_t *button_stateJ = json_array_get(button_statesJ, k * 100 + i * 10 + j); + if (button_stateJ) + fatherSon->switch_states[k][i][j] = !!json_integer_value(button_stateJ); + } } } } - } - json_t *onlyRandomizeActiveJ = json_object_get(rootJ, "onlyRandomizeActive"); - if (onlyRandomizeActiveJ){ fatherSon->onlyRandomizeActive = json_is_true(onlyRandomizeActiveJ); } + json_t *onlyRandomizeActiveJ = json_object_get(rootJ, "onlyRandomizeActive"); + if (onlyRandomizeActiveJ) { fatherSon->onlyRandomizeActive = json_is_true(onlyRandomizeActiveJ); } + + json_t *randomizationStepEnumJ = json_object_get(rootJ, "randomizationStepEnum"); + if (randomizationStepEnumJ) { fatherSon->setRandomizationStepEnum(json_integer_value(randomizationStepEnumJ)); } - json_t *randomizationStepEnumJ = json_object_get(rootJ, "randomizationStepEnum"); - if (randomizationStepEnumJ){ fatherSon->setRandomizationStepEnum(json_integer_value(randomizationStepEnumJ)); } - -json_t *randomizationOutputBoundsEnumJ = json_object_get(rootJ, "randomizationOutputBoundsEnum"); - if (randomizationOutputBoundsEnumJ){ fatherSon->setRandomizationOutputBoundsEnum(json_integer_value(randomizationOutputBoundsEnumJ)); } - - } + json_t *randomizationOutputBoundsEnumJ = json_object_get(rootJ, "randomizationOutputBoundsEnum"); + if (randomizationOutputBoundsEnumJ) { fatherSon->setRandomizationOutputBoundsEnum(json_integer_value(randomizationOutputBoundsEnumJ)); } + + } ComputerscarePatchSequencer *fatherSon; //Menu *createContextMenu() override; }; -struct OnlyRandomizeActiveMenuItem : MenuItem { - ComputerscarePatchSequencer *patchSequencer; - void onAction(EventAction &e) override { - patchSequencer->onlyRandomizeActive = !patchSequencer->onlyRandomizeActive; - } - void process(const ProcessArgs &args) override { - rightText = patchSequencer->onlyRandomizeActive ? "✔" : ""; - } +/*struct OnlyRandomizeActiveMenuItem : MenuItem { + ComputerscarePatchSequencer *patchSequencer; + void onAction(const event::Action &e) override { + patchSequencer->onlyRandomizeActive = !patchSequencer->onlyRandomizeActive; + } + void process(const ProcessArgs &args) override { + rightText = patchSequencer->onlyRandomizeActive ? "✔" : ""; + } }; struct WhichStepToRandomizeItem : MenuItem { - ComputerscarePatchSequencer *patchSequencer; - int stepEnum; - void onAction(EventAction &e) override { - patchSequencer->setRandomizationStepEnum(stepEnum); - } - void process(const ProcessArgs &args) override { - rightText = CHECKMARK(patchSequencer->getRandomizationStepEnum() == stepEnum); - MenuItem::step(); - } + ComputerscarePatchSequencer *patchSequencer; + int stepEnum; + void onAction(const event::Action &e) override { + patchSequencer->setRandomizationStepEnum(stepEnum); + } + void process(const ProcessArgs &args) override { + rightText = CHECKMARK(patchSequencer->getRandomizationStepEnum() == stepEnum); + MenuItem::step(); + } }; struct WhichRandomizationOutputBoundsItem : MenuItem { ComputerscarePatchSequencer *patchSequencer; int boundsEnum; - void onAction(EventAction &e) override { + void onAction(const event::Action &e) override { patchSequencer->setRandomizationOutputBoundsEnum(boundsEnum); } void process(const ProcessArgs &args) override { @@ -506,29 +511,29 @@ struct WhichRandomizationOutputBoundsItem : MenuItem { }; Menu *ComputerscarePatchSequencerWidget::createContextMenu() { - Menu *menu = ModuleWidget::createContextMenu(); - ComputerscarePatchSequencer *patchSequencer = dynamic_cast<ComputerscarePatchSequencer*>(module); - assert(patchSequencer); - - MenuLabel *spacerLabel = new MenuLabel(); - menu->addChild(spacerLabel); - - MenuLabel *modeLabel = new MenuLabel(); - modeLabel->text = "Randomization Options"; - menu->addChild(modeLabel); - - OnlyRandomizeActiveMenuItem *onlyRandomizeActiveMenuItem = new OnlyRandomizeActiveMenuItem(); - onlyRandomizeActiveMenuItem->text = "Only Randomize Active Connections"; - onlyRandomizeActiveMenuItem->patchSequencer = patchSequencer; - menu->addChild(onlyRandomizeActiveMenuItem); - - - menu->addChild(construct<MenuLabel>()); - menu->addChild(construct<MenuLabel>(&MenuLabel::text, "Which Step to Randomize")); - menu->addChild(construct<WhichStepToRandomizeItem>(&MenuItem::text, "Edit step", &WhichStepToRandomizeItem::patchSequencer, patchSequencer, &WhichStepToRandomizeItem::stepEnum, 0)); - menu->addChild(construct<WhichStepToRandomizeItem>(&MenuItem::text, "Active step", &WhichStepToRandomizeItem::patchSequencer, patchSequencer, &WhichStepToRandomizeItem::stepEnum, 1)); - menu->addChild(construct<WhichStepToRandomizeItem>(&MenuItem::text, "All steps", &WhichStepToRandomizeItem::patchSequencer, patchSequencer, &WhichStepToRandomizeItem::stepEnum, 2)); - + Menu *menu = ModuleWidget::createContextMenu(); + ComputerscarePatchSequencer *patchSequencer = dynamic_cast<ComputerscarePatchSequencer*>(module); + assert(patchSequencer); + + MenuLabel *spacerLabel = new MenuLabel(); + menu->addChild(spacerLabel); + + MenuLabel *modeLabel = new MenuLabel(); + modeLabel->text = "Randomization Options"; + menu->addChild(modeLabel); + + OnlyRandomizeActiveMenuItem *onlyRandomizeActiveMenuItem = new OnlyRandomizeActiveMenuItem(); + onlyRandomizeActiveMenuItem->text = "Only Randomize Active Connections"; + onlyRandomizeActiveMenuItem->patchSequencer = patchSequencer; + menu->addChild(onlyRandomizeActiveMenuItem); + + + menu->addChild(construct<MenuLabel>()); + menu->addChild(construct<MenuLabel>(&MenuLabel::text, "Which Step to Randomize")); + menu->addChild(construct<WhichStepToRandomizeItem>(&MenuItem::text, "Edit step", &WhichStepToRandomizeItem::patchSequencer, patchSequencer, &WhichStepToRandomizeItem::stepEnum, 0)); + menu->addChild(construct<WhichStepToRandomizeItem>(&MenuItem::text, "Active step", &WhichStepToRandomizeItem::patchSequencer, patchSequencer, &WhichStepToRandomizeItem::stepEnum, 1)); + menu->addChild(construct<WhichStepToRandomizeItem>(&MenuItem::text, "All steps", &WhichStepToRandomizeItem::patchSequencer, patchSequencer, &WhichStepToRandomizeItem::stepEnum, 2)); + // randomization output bounds menu->addChild(construct<MenuLabel>()); menu->addChild(construct<MenuLabel>(&MenuLabel::text, "Output Row Randomization Method")); @@ -538,8 +543,8 @@ Menu *ComputerscarePatchSequencerWidget::createContextMenu() { menu->addChild(construct<WhichRandomizationOutputBoundsItem>(&MenuItem::text, "One or more", &WhichRandomizationOutputBoundsItem::patchSequencer, patchSequencer, &WhichRandomizationOutputBoundsItem::boundsEnum, 3)); - return menu; -} + return menu; +}*/ // Specify the Module and ModuleWidget subclass, human-readable // author name for categorization per plugin, module slug (should never // change), human-readable module name, and any number of tags