computerscare-vcv-modules

computerscare modules for VCV Rack
Log | Files | Refs

commit 3feed98604100e2c206da438558a0fb833d2d18d
parent 7b60e9634ce882ce7ad11f0b1c8da10956b35f54
Author: Adam M <[email protected]>
Date:   Wed, 19 Sep 2018 21:56:15 -0500

almost done with multi-text field functionality for laundry soup

Diffstat:
Msrc/ComputerscareLaundrySoup.cpp | 103++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
Msrc/ComputerscarePatchSequencer.cpp | 230+++++++++++++++----------------------------------------------------------------
2 files changed, 110 insertions(+), 223 deletions(-)

diff --git a/src/ComputerscareLaundrySoup.cpp b/src/ComputerscareLaundrySoup.cpp @@ -8,6 +8,8 @@ struct ComputerscareLaundrySoup; +const int numFields = 2; + class MyTextField : public LedDisplayTextField { public: MyTextField() : LedDisplayTextField() {} @@ -31,7 +33,7 @@ struct ComputerscareLaundrySoup : Module { }; enum OutputIds { TRG_OUTPUT, - NUM_OUTPUTS + NUM_OUTPUTS = TRG_OUTPUT + numFields }; enum LightIds { SWITCH_LIGHTS, @@ -41,17 +43,17 @@ struct ComputerscareLaundrySoup : Module { SchmittTrigger clockTrigger; SchmittTrigger resetTriggerInput; - MyTextField* textField; + MyTextField* textFields[numFields]; - std::vector<int> sequence; - std::vector<int> sequenceSums; + std::vector<int> sequences[numFields]; + std::vector<int> sequenceSums[numFields]; int stepCity = 0; int stepState = 0; int stepCounty = 0; int currentChar = 0; int numSteps = 0; - int numStepBlocks = 0; + int numStepBlocks[numFields]; bool compiled = false; @@ -70,40 +72,66 @@ ComputerscareLaundrySoup() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIG void fromJson(json_t *rootJ) override { - } + } - void onRandomize() override { - - } + void onRandomize() override { + + } // 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 parseFormula(std::string expr) { - int current; - sequence.resize(0); - sequenceSums.resize(0); - sequenceSums.push_back(0); - numSteps = 0; - for(char& c : expr) { - //do_things_with(c); - currentChar = c - '0'; - numSteps += currentChar; - sequenceSums.push_back(numSteps); - sequence.push_back(currentChar); +void parseFormulas(MyTextField* textFields) { + std::string expr; + for(int i = 0; i < numFields; i++) { + sequences[i].resize(0); + sequenceSums[i].resize(0); + sequenceSums[i].push_back(0); + numSteps = 0; + //expr = textFields[i]->text; + for(char& c : expr) { + + //do_things_with(c); + currentChar = c - '0'; + numSteps += currentChar; + sequenceSums[i].push_back(numSteps); + sequences[i].push_back(currentChar); + } + numStepBlocks[i] = sequences[i].size(); } - numStepBlocks = sequence.size(); + } + void parseFormula(std::string expr, int index) { + sequences[index].resize(0); + sequenceSums[index].resize(0); + sequenceSums[index].push_back(0); + numSteps = 0; + //expr = textFields[i]->text; + for(char& c : expr) { + + //do_things_with(c); + currentChar = c - '0'; + numSteps += currentChar; + sequenceSums[index].push_back(numSteps); + sequences[index].push_back(currentChar); + } + numStepBlocks[index] = sequences[index].size(); } void onCreate () override { + for(int i = 0; i < numFields; i++) { + if(textFields[i]->text.size() > 0) { + parseFormula(textFields[i]->text,i); + } + } compiled = false; - if (textField->text.size() > 0) { - parseFormula(textField->text); + /* + if (textFields[0]->text.size() > 0) { + parseFormulas(textFields); compiled = true; - } + }*/ } void onReset () override @@ -113,11 +141,11 @@ void onCreate () override void incrementInternalStep() { this->stepCity += 1; this->stepState += 1; - if(this->stepCity >= sequence[this->stepCounty]) { + if(this->stepCity >= sequences[0][this->stepCounty]) { this->stepCity = 0; this->stepCounty += 1; } - if(this->stepCounty >= this->numStepBlocks) { + if(this->stepCounty >= this->numStepBlocks[0]) { this->stepCounty = 0; this->stepCity = 0; this->stepState = 0; @@ -133,7 +161,7 @@ void ComputerscareLaundrySoup::step() { bool gateIn = false; bool activeStep = false; -if(this->numStepBlocks > 0) { +if(this->numStepBlocks[0] > 0) { if (inputs[CLOCK_INPUT].active) { // External clock if (clockTrigger.process(inputs[CLOCK_INPUT].value)) { @@ -141,7 +169,7 @@ if(this->numStepBlocks > 0) { } gateIn = clockTrigger.isHigh(); } - activeStep = (sequenceSums[this->stepCounty] == this->stepState); + activeStep = (sequenceSums[0][this->stepCounty] == this->stepState); } // 112 @@ -199,16 +227,17 @@ struct ComputerscareLaundrySoupWidget : ModuleWidget { //reset input addInput(Port::create<InPort>(Vec(54, 13), Port::INPUT, module, ComputerscareLaundrySoup::RESET_INPUT)); - addOutput(Port::create<InPort>(Vec(33 , 200), Port::OUTPUT, module, ComputerscareLaundrySoup::TRG_OUTPUT)); - + for(int i = 0; i < numFields; i++) { + addOutput(Port::create<InPort>(Vec(33 , 130 + 100*i), Port::OUTPUT, module, ComputerscareLaundrySoup::TRG_OUTPUT + i)); - textField = Widget::create<MyTextField>(mm2px(Vec(1, 25))); - textField->setModule(module); - textField->box.size = mm2px(Vec(63, 20)); - textField->multiline = true; - addChild(textField); - module->textField = textField; + textField = Widget::create<MyTextField>(mm2px(Vec(1, 25 + 30*i))); + textField->setModule(module); + textField->box.size = mm2px(Vec(63, 20)); + textField->multiline = true; + addChild(textField); + module->textFields[i] = textField; + } //active step display NumberDisplayWidget3 *display = new NumberDisplayWidget3(); display->box.pos = Vec(56,40); diff --git a/src/ComputerscarePatchSequencer.cpp b/src/ComputerscarePatchSequencer.cpp @@ -6,6 +6,10 @@ #include <sstream> #include <iomanip> +const int maxSteps = 16; +const int numInputs = 10; +const int numOutputs = 10; + struct ComputerscarePatchSequencer : Module { enum ParamIds { STEPS_PARAM, @@ -48,159 +52,13 @@ struct ComputerscarePatchSequencer : Module { int editAddressPlusOne = 1; int numAddresses = 2; - bool switch_states[16][10][10] = - {{{0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, -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0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}},{{0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0}} -}; + bool switch_states[maxSteps][10][10] = {}; bool onlyRandomizeActive = false; bool neg5ToPos5 = false; - float input_values[10] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}; - float sums[10] = {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 @@ -216,7 +74,7 @@ ComputerscarePatchSequencer() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_ // button states json_t *button_statesJ = json_array(); - for(int k = 0; k < 16; k++) { + for(int k = 0; k < maxSteps; k++) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) @@ -238,7 +96,7 @@ ComputerscarePatchSequencer() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_ json_t *button_statesJ = json_object_get(rootJ, "buttons"); if (button_statesJ) { - for(int k = 0; k < 16; k++) { + for(int k = 0; k < maxSteps; k++) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { @@ -281,35 +139,35 @@ ComputerscarePatchSequencer() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_ std::vector<int> connectedInputIndices; for (int i = 0; i < 10; i++) - { - if(inputs[INPUT_JACKS + i].active) { - numConnectedInputs++; - connectedInputIndices.push_back(i); - } - connectedInputs[i] = inputs[INPUT_JACKS + i].active; - connectedOutputs[i] = outputs[OUTPUTS + i].active; - } - for(int k = 0; k < 16; k++) { - if((randomizationStepEnum == 0 && k == editAddress) || (randomizationStepEnum == 1 && k == address) || randomizationStepEnum == 2) { - for(int i = 0; i < 10; i++) { - randomIndex = connectedInputIndices[floor(randomUniform()*numConnectedInputs)]; - 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; - } - } - } - } - } + { + if(inputs[INPUT_JACKS + i].active) { + numConnectedInputs++; + connectedInputIndices.push_back(i); + } + connectedInputs[i] = inputs[INPUT_JACKS + i].active; + connectedOutputs[i] = outputs[OUTPUTS + i].active; + } + 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 = connectedInputIndices[floor(randomUniform()*numConnectedInputs)]; + 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 randomizeMatrixOnePerOutput() { int randomIndex; - for(int k = 0; k < 16; k++) { + 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++) { @@ -320,7 +178,7 @@ ComputerscarePatchSequencer() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_ if(j==randomIndex) switch_states[k][j][i] = 1; else - switch_states[k][j][i]=0; + switch_states[k][j][i] = 0; } } } @@ -339,7 +197,7 @@ ComputerscarePatchSequencer() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_ }; // end randomize() void onReset() override { - for(int k =0; k < 16; k++) { + for(int k =0; k < maxSteps; k++) { for (int i = 0; i < 10; i++) @@ -372,13 +230,11 @@ void ComputerscarePatchSequencer::step() { if (switch_triggers[i][j].process(params[SWITCHES+j*10 + i].value)) { // 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) + 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; - } } @@ -391,12 +247,12 @@ void ComputerscarePatchSequencer::step() { } if(nextAddressEdit.process(params[EDIT_PARAM].value) ) { editAddress = editAddress + 1; - editAddress = editAddress % 16; + editAddress = editAddress % maxSteps; } if(prevAddressEdit.process(params[EDIT_PREV_PARAM].value) ) { editAddress = editAddress - 1; - editAddress = editAddress + 16; - editAddress = editAddress % 16; + editAddress = editAddress + maxSteps; + editAddress = editAddress % maxSteps; } if(nextAddressRead.process(params[MANUAL_CLOCK_PARAM].value) || clockTrigger.process(inputs[TRG_INPUT].value / 2.f)) { @@ -426,7 +282,9 @@ void ComputerscarePatchSequencer::step() { { // 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]; + if (switch_states[address][j][i]) { + sums[i] += input_values[j]; + } } } /// outputs