computerscare-vcv-modules

computerscare modules for VCV Rack
Log | Files | Refs

commit 260966400a8cf6a555b89ebc53ce68a68f6ec237
parent 12ca3ac3d871017edf5ed88ddb96c865d4c7f08a
Author: Adam M <[email protected]>
Date:   Wed,  7 Aug 2019 20:16:11 -0500

Merge branch 'master' into laundrypoly

Diffstat:
Msrc/ComputerscareBolyPuttons.cpp | 88++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------
Msrc/ComputerscareILoveCookies.cpp | 1-
Msrc/ComputerscareOhPeas.cpp | 12+++---------
3 files changed, 75 insertions(+), 26 deletions(-)

diff --git a/src/ComputerscareBolyPuttons.cpp b/src/ComputerscareBolyPuttons.cpp @@ -8,7 +8,9 @@ struct ComputerscareBolyPuttons : Module { int counter = 0; int outputRangeEnum = 0; bool momentary = false; + bool radioMode=false; float outputRanges[6][2]; + float previousToggle[16] = {0.f}; rack::dsp::SchmittTrigger momentaryTriggers[16]; rack::dsp::PulseGenerator pulseGen[16]; @@ -39,7 +41,7 @@ struct ComputerscareBolyPuttons : Module { for (int i = 0; i < numToggles; i++) { //configParam(KNOB + i, 0.0f, 10.0f, 0.0f); - configParam(TOGGLE + i, 0.f, 1.f, 0.f, "Channel " + std::to_string(i + 1) + " Voltage", " Volts"); + configParam(TOGGLE + i, 0.f, 1.f, 0.f, "Channel " + std::to_string(i + 1)); } outputRanges[0][0] = 0.f; @@ -55,6 +57,39 @@ struct ComputerscareBolyPuttons : Module { outputRanges[5][0] = -10.f; outputRanges[5][1] = 10.f; } +void switchOffAllButtonsButOne(int index) { + for (int i = 0; i < numToggles; i++) { + if (i != index) { + params[TOGGLE + i].setValue(0.f); + } + } + } +void checkForParamChanges() { + int changeIndex = -1; + float val; + for(int i = 0; i < numToggles; i++) { + val=params[TOGGLE + i].getValue(); + if(val == 1.f && previousToggle[i] != val) { + changeIndex = i; + } + previousToggle[i] = val; + } + if(changeIndex > -1) { + switchOffAllButtonsButOne(changeIndex); + } +} +void onRandomize() override { + if(radioMode) { + int rIndex = floor(random::uniform() * 16); + switchOffAllButtonsButOne(rIndex); + params[TOGGLE+rIndex].setValue(1.f); + } + else { + for(int i = 0; i < numToggles; i++) { + params[TOGGLE+i].setValue(random::uniform() < 0.5 ? 0.f : 1.f); + } + } + } void process(const ProcessArgs &args) override { float min = outputRanges[outputRangeEnum][0]; float max = outputRanges[outputRangeEnum][1]; @@ -91,8 +126,9 @@ struct ComputerscareBolyPuttons : Module { } else { - - + if(radioMode) { + checkForParamChanges(); + } for (int i = 0; i < numToggles; i++) { if (inputs[A_INPUT].isConnected()) { min = inputs[A_INPUT].getVoltage(i % numAChannels); @@ -120,26 +156,17 @@ struct ComputerscareBolyPuttonsWidget : ModuleWidget { ComputerscareSVGPanel *panel = new ComputerscareSVGPanel(); panel->box.size = box.size; panel->setBackground(APP->window->loadSvg(asset::plugin(pluginInstance, "res/ComputerscareBolyPuttonsPanel.svg"))); - - //module->panelRef = panel; - addChild(panel); } float xx; float yy; - // for (int i = 0; i < numToggles; i++) { - // xx = 7.4f + 27.3 * (i % 2); - // yy = 94 + 16.5 * (i - i % 2) + 11.3 * (i % 2); - // addLabeledButton(std::to_string(i + 1), xx, yy, module, i, (i % 2) * (3 + 10 * (i < 9)) - 2, 0); - // } for (int i = 0; i < numToggles; i++) { xx = 5.2f + 27.3 * (i - i % 8) / 8; yy = 92 + 33.5 * (i % 8) + 14.3 * (i - i % 8) / 8; addLabeledButton(std::to_string(i + 1), xx, yy, module, i, (i - i % 8) * 1.2 - 2, 2); } - addInput(createInput<InPort>(Vec(9, 58), module, ComputerscareBolyPuttons::A_INPUT)); addInput(createInput<PointingUpPentagonPort>(Vec(33, 55), module, ComputerscareBolyPuttons::B_INPUT)); @@ -162,6 +189,8 @@ struct ComputerscareBolyPuttonsWidget : ModuleWidget { { json_t *rootJ = ModuleWidget::toJson(); json_object_set_new(rootJ, "outputRange", json_integer(bolyPuttons->outputRangeEnum)); + json_object_set_new(rootJ, "radioMode", json_boolean(bolyPuttons->radioMode)); + json_object_set_new(rootJ, "momentaryMode", json_boolean(bolyPuttons->momentary)); return rootJ; } void fromJson(json_t *rootJ) override @@ -171,6 +200,10 @@ struct ComputerscareBolyPuttonsWidget : ModuleWidget { json_t *outputRangeEnumJ = json_object_get(rootJ, "outputRange"); if (outputRangeEnumJ) { bolyPuttons->outputRangeEnum = json_integer_value(outputRangeEnumJ); } + json_t *radioModeJ = json_object_get(rootJ, "radioMode"); + if (radioModeJ) { bolyPuttons->radioMode = json_is_true(radioModeJ); } + json_t *momentaryModeJ = json_object_get(rootJ, "momentaryMode"); + if (momentaryModeJ) { bolyPuttons->momentary = json_is_true(momentaryModeJ); } } void appendContextMenu(Menu *menu) override; @@ -188,15 +221,35 @@ struct OutputRangeItem : MenuItem { MenuItem::step(); } }; +struct RadioModeMenuItem: MenuItem { + ComputerscareBolyPuttons *bolyPuttons; + RadioModeMenuItem() { + + } + void onAction(const event::Action &e) override { + bolyPuttons->radioMode = !bolyPuttons->radioMode; + } + void step() override { + rightText = bolyPuttons->radioMode? "✔" : ""; + MenuItem::step(); + } +}; + void ComputerscareBolyPuttonsWidget::appendContextMenu(Menu *menu) { ComputerscareBolyPuttons *bolyPuttons = dynamic_cast<ComputerscareBolyPuttons *>(this->module); - MenuLabel *spacerLabel = new MenuLabel(); - menu->addChild(spacerLabel); + menu->addChild(construct<MenuLabel>(&MenuLabel::text, "")); + menu->addChild(construct<MenuLabel>(&MenuLabel::text, "How The Buttons Work")); + RadioModeMenuItem *radioMode = new RadioModeMenuItem(); + radioMode->text = "Exclusive Mode (behaves like radio buttons)"; + radioMode->bolyPuttons= bolyPuttons; + menu->addChild(radioMode); + - menu->addChild(construct<MenuLabel>()); - menu->addChild(construct<MenuLabel>(&MenuLabel::text, "Output Range")); + menu->addChild(construct<MenuLabel>(&MenuLabel::text, "")); + + menu->addChild(construct<MenuLabel>(&MenuLabel::text, "Off / On Values (A ... B)")); menu->addChild(construct<OutputRangeItem>(&MenuItem::text, " 0v ... +10v", &OutputRangeItem::bolyPuttons, bolyPuttons, &OutputRangeItem::outputRangeEnum, 0)); menu->addChild(construct<OutputRangeItem>(&MenuItem::text, " -5v ... +5v", &OutputRangeItem::bolyPuttons, bolyPuttons, &OutputRangeItem::outputRangeEnum, 1)); menu->addChild(construct<OutputRangeItem>(&MenuItem::text, " 0v ... +5v", &OutputRangeItem::bolyPuttons, bolyPuttons, &OutputRangeItem::outputRangeEnum, 2)); @@ -204,5 +257,8 @@ void ComputerscareBolyPuttonsWidget::appendContextMenu(Menu *menu) menu->addChild(construct<OutputRangeItem>(&MenuItem::text, " -1v ... +1v", &OutputRangeItem::bolyPuttons, bolyPuttons, &OutputRangeItem::outputRangeEnum, 4)); menu->addChild(construct<OutputRangeItem>(&MenuItem::text, "-10v ... +10v", &OutputRangeItem::bolyPuttons, bolyPuttons, &OutputRangeItem::outputRangeEnum, 5)); + + + } Model *modelComputerscareBolyPuttons = createModel<ComputerscareBolyPuttons, ComputerscareBolyPuttonsWidget>("computerscare-bolyputtons"); diff --git a/src/ComputerscareILoveCookies.cpp b/src/ComputerscareILoveCookies.cpp @@ -109,7 +109,6 @@ struct ComputerscareILoveCookies : Module { params[KNOB_PARAM + i].setValue(rv); } } - } void randomizeTextFields() { std::string mainlookup = knoblookup; diff --git a/src/ComputerscareOhPeas.cpp b/src/ComputerscareOhPeas.cpp @@ -190,12 +190,8 @@ void ComputerscareOhPeas::process(const ProcessArgs &args) int numScaleCVChannels; int numOffsetCVChannels; - //int globalTransposeKnobValue = (int) clamp(roundf(params[GLOBAL_TRANSPOSE].getValue()), -fNumDiv, fNumDiv); - if (numDivisionsKnobValue != numDivisions) { - //printf("%i, %i, %i, %i\n",numDivisionsKnobValue,numDivisions,iTranspose,globalTranspose); - //what a hack!!! if (numDivisionsKnobValue != 0) { @@ -206,8 +202,6 @@ void ComputerscareOhPeas::process(const ProcessArgs &args) } if (iTranspose != globalTranspose) { - //printf("%i, %i, %i, %i\n",numDivisionsKnobValue,numDivisions,iTranspose,globalTranspose); - globalTranspose = iTranspose; setQuant(); } @@ -219,17 +213,17 @@ void ComputerscareOhPeas::process(const ProcessArgs &args) numOffsetCVChannels = inputs[OFFSET_CV + i].getChannels(); outputs[SCALED_OUTPUT + i].setChannels(numInputChannels); outputs[QUANTIZED_OUTPUT + i].setChannels(numInputChannels); - for (int ch = 0; ch < numInputChannels; ch++) { + for (int ch = 0; ch < std::max(numInputChannels,1); ch++) { a = params[SCALE_VAL + i].getValue(); b = params[SCALE_TRIM + i].getValue(); - B = inputs[SCALE_CV + i].getVoltage(ch % numInputChannels); + B = inputs[SCALE_CV + i].getVoltage(ch); A = inputs[CHANNEL_INPUT + i].getVoltage(ch); c = params[OFFSET_TRIM + i].getValue(); - C = inputs[OFFSET_CV + i].getVoltage(ch % numInputChannels); + C = inputs[OFFSET_CV + i].getVoltage(ch); d = params[OFFSET_VAL + i].getValue(); D = (b * B + a) * A + (c * C + d);