commit 25e7c4ccc6ef3034b69fb6ad00f7a39efaf9e3ff
parent d081861fe38d3ab0d5149e82abd43b89607bd1e7
Author: Adam M <[email protected]>
Date: Sun, 29 Mar 2020 09:23:37 -0500
gooder jsons for puttons and father and son
Diffstat:
2 files changed, 130 insertions(+), 112 deletions(-)
diff --git a/src/ComputerscareBolyPuttons.cpp b/src/ComputerscareBolyPuttons.cpp
@@ -8,7 +8,7 @@ struct ComputerscareBolyPuttons : Module {
int counter = 0;
int outputRangeEnum = 0;
bool momentary = false;
- bool radioMode=false;
+ bool radioMode = false;
float outputRanges[6][2];
float previousToggle[16] = {0.f};
rack::dsp::SchmittTrigger momentaryTriggers[16];
@@ -57,39 +57,59 @@ 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;
+ void switchOffAllButtonsButOne(int index) {
+ for (int i = 0; i < numToggles; i++) {
+ if (i != index) {
+ params[TOGGLE + i].setValue(0.f);
+ }
}
- previousToggle[i] = val;
}
- if(changeIndex > -1) {
- switchOffAllButtonsButOne(changeIndex);
+ 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 legacyJSON(json_t *rootJ) {
+ json_t *outputRangeEnumJ = json_object_get(rootJ, "outputRange");
+ if (outputRangeEnumJ) { outputRangeEnum = json_integer_value(outputRangeEnumJ); }
+ json_t *radioModeJ = json_object_get(rootJ, "radioMode");
+ if (radioModeJ) { radioMode = json_is_true(radioModeJ); }
+ json_t *momentaryModeJ = json_object_get(rootJ, "momentaryMode");
+ if (momentaryModeJ) { momentary = json_is_true(momentaryModeJ); }
+ }
+ void dataFromJson(json_t *rootJ) override {
+ legacyJSON(rootJ);
+ }
+ json_t *dataToJson() override
+ {
+ json_t *rootJ = json_object();
+ json_object_set_new(rootJ, "outputRange", json_integer(outputRangeEnum));
+ json_object_set_new(rootJ, "radioMode", json_boolean(radioMode));
+ json_object_set_new(rootJ, "momentaryMode", json_boolean(momentary));
+ return rootJ;
+ }
+
+ 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 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];
@@ -126,8 +146,8 @@ void onRandomize() override {
}
else {
- if(radioMode) {
- checkForParamChanges();
+ if (radioMode) {
+ checkForParamChanges();
}
for (int i = 0; i < numToggles; i++) {
if (inputs[A_INPUT].isConnected()) {
@@ -185,25 +205,12 @@ struct ComputerscareBolyPuttonsWidget : ModuleWidget {
addParam(createParam<SmallIsoButton>(Vec(x, y), module, ComputerscareBolyPuttons::TOGGLE + index));
}
- json_t *toJson() override
- {
- 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
{
ModuleWidget::fromJson(rootJ);
// button states
-
- 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); }
+ bolyPuttons->legacyJSON(rootJ);
}
void appendContextMenu(Menu *menu) override;
@@ -222,17 +229,17 @@ struct OutputRangeItem : MenuItem {
}
};
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();
- }
+ 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)
@@ -241,10 +248,10 @@ void ComputerscareBolyPuttonsWidget::appendContextMenu(Menu *menu)
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);
+ RadioModeMenuItem *radioMode = new RadioModeMenuItem();
+ radioMode->text = "Exclusive Mode (behaves like radio buttons)";
+ radioMode->bolyPuttons = bolyPuttons;
+ menu->addChild(radioMode);
menu->addChild(construct<MenuLabel>(&MenuLabel::text, ""));
diff --git a/src/ComputerscarePatchSequencer.cpp b/src/ComputerscarePatchSequencer.cpp
@@ -214,6 +214,61 @@ struct ComputerscarePatchSequencer : Module {
}
}; // end randomize()
+
+ void dataFromJson(json_t *rootJ) override {
+ // button states
+ DEBUG("dataFromJson called. It wants its JSON back");
+ json_t *button_statesJ = json_object_get(rootJ, "buttons");
+ if (button_statesJ)
+ {
+ DEBUG("there R buttonz");
+ 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)
+ switch_states[k][i][j] = !!json_integer_value(button_stateJ);
+ }
+ }
+ }
+ }
+ json_t *onlyRandomizeActiveJ = json_object_get(rootJ, "onlyRandomizeActive");
+ if (onlyRandomizeActiveJ) { onlyRandomizeActive = json_is_true(onlyRandomizeActiveJ); }
+
+ json_t *randomizationStepEnumJ = json_object_get(rootJ, "randomizationStepEnum");
+ if (randomizationStepEnumJ) { setRandomizationStepEnum(json_integer_value(randomizationStepEnumJ)); }
+
+ json_t *channelCountEnumJ = json_object_get(rootJ, "channelCountEnum");
+ if (channelCountEnumJ) { channelCountEnum = json_integer_value(channelCountEnumJ); }
+
+ json_t *randomizationOutputBoundsEnumJ = json_object_get(rootJ, "randomizationOutputBoundsEnum");
+ if (randomizationOutputBoundsEnumJ) { setRandomizationOutputBoundsEnum(json_integer_value(randomizationOutputBoundsEnumJ)); }
+
+ }
+ json_t *dataToJson() override
+ {
+
+ json_t *rootJ = json_object();
+ // 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++)
+ {
+ json_t *button_stateJ = json_integer((int) 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, "onlyRandomizeActive", json_boolean(onlyRandomizeActive));
+ json_object_set_new(rootJ, "channelCountEnum", json_integer(channelCountEnum));
+ json_object_set_new(rootJ, "randomizationStepEnum", json_integer(getRandomizationStepEnum()));
+ json_object_set_new(rootJ, "randomizationOutputBoundsEnum", json_integer(getRandomizationOutputBoundsEnum()));
+ return rootJ;
+ }
};
@@ -478,64 +533,20 @@ struct ComputerscarePatchSequencerWidget : ModuleWidget {
addChild(displayEdit);
fatherSon = module;
}
- json_t *toJson() override
- {
- 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++)
- {
- 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, "onlyRandomizeActive", json_boolean(fatherSon->onlyRandomizeActive));
- json_object_set_new(rootJ, "channelCountEnum", json_integer(fatherSon->channelCountEnum));
- 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)
- {
- 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 *button_statesJ = json_object_get(rootJ, "buttons");
+ if (button_statesJ) {
+ //there be legacy JSON
+ fatherSon->dataFromJson(rootJ);
}
- 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 *channelCountEnumJ = json_object_get(rootJ, "channelCountEnum");
- if (channelCountEnumJ) { fatherSon->channelCountEnum = json_integer_value(channelCountEnumJ); }
-
- json_t *randomizationOutputBoundsEnumJ = json_object_get(rootJ, "randomizationOutputBoundsEnum");
- if (randomizationOutputBoundsEnumJ) { fatherSon->setRandomizationOutputBoundsEnum(json_integer_value(randomizationOutputBoundsEnumJ)); }
-
}
void appendContextMenu(Menu *menu) override;
ComputerscarePatchSequencer *fatherSon;
- //Menu *createContextMenu() override;
};
struct OnlyRandomizeActiveMenuItem : MenuItem {
ComputerscarePatchSequencer *patchSequencer;