commit 52cb9d091dcc300b79b3f0a04e24ccc67056cfee
parent ec695a6a1879f4eff20e51d39249a40d96390b0d
Author: Adam M <aemalone@gmail.com>
Date: Sun, 29 Mar 2020 10:33:42 -0500
Merge branch 'master' into goly-penerator
Diffstat:
5 files changed, 190 insertions(+), 140 deletions(-)
diff --git a/src/Computerscare.hpp b/src/Computerscare.hpp
@@ -145,6 +145,9 @@ struct ThreeVerticalXSwitch : app::SvgSwitch {
addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/vertical-x-3.svg")));
shadow->opacity = 0.f;
}
+ void randomize() override {
+ return;
+ }
};
struct ComputerscareDebugFour : app::SvgSwitch {
ComputerscareDebugFour() {
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,11 @@ 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 +228,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 +247,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/ComputerscareDebug.cpp b/src/ComputerscareDebug.cpp
@@ -88,6 +88,10 @@ struct ComputerscareDebug : Module {
outputRanges[4][1] = 1.f;
outputRanges[5][0] = -10.f;
outputRanges[5][1] = 10.f;
+ outputRanges[6][0] = -2.f;
+ outputRanges[6][1] = 2.f;
+ outputRanges[7][0] = 0.f;
+ outputRanges[7][1] = 2.f;
stepCounter = 0;
@@ -97,11 +101,23 @@ struct ComputerscareDebug : Module {
}
void process(const ProcessArgs &args) override;
+ void onRandomize() override {
+ randomizeStorage();
+ }
+
+ void randomizeStorage() {
+ float min = outputRanges[outputRangeEnum][0];
+ float max = outputRanges[outputRangeEnum][1];
+ float spread = max - min;
+ for (int i = 0; i < 16; i++) {
+ logLines[i] = min + spread * random::uniform();
+ }
+ }
json_t *dataToJson() override {
json_t *rootJ = json_object();
- json_object_set_new(rootJ, "outputRange", json_integer(outputRangeEnum));
+ json_object_set_new(rootJ, "outputRange", json_integer(outputRangeEnum));
json_t *sequencesJ = json_array();
@@ -111,10 +127,10 @@ struct ComputerscareDebug : Module {
}
json_object_set_new(rootJ, "lines", sequencesJ);
return rootJ;
- }
+ }
- void dataFromJson(json_t *rootJ) override {
- float val;
+ void dataFromJson(json_t *rootJ) override {
+ float val;
json_t *outputRangeEnumJ = json_object_get(rootJ, "outputRange");
if (outputRangeEnumJ) { outputRangeEnum = json_integer_value(outputRangeEnumJ); }
@@ -125,12 +141,12 @@ struct ComputerscareDebug : Module {
for (int i = 0; i < 16; i++) {
json_t *sequenceJ = json_array_get(sequencesJ, i);
if (sequenceJ)
- val = json_real_value(sequenceJ);
+ val = json_real_value(sequenceJ);
logLines[i] = val;
}
}
- }
+ }
// 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
@@ -248,7 +264,6 @@ struct HidableSmallSnapKnob : SmallSnapKnob {
ComputerscareDebug *module;
HidableSmallSnapKnob() {
-
SmallSnapKnob();
}
void draw(const DrawArgs &args) {
@@ -256,6 +271,7 @@ struct HidableSmallSnapKnob : SmallSnapKnob {
Widget::draw(args);
}
};
+ void randomize() override { return; }
};
////////////////////////////////////
struct StringDisplayWidget3 : Widget {
@@ -404,7 +420,7 @@ struct ComputerscareDebugWidget : ModuleWidget {
for (int i = 0; i < 16; i++) {
json_t *sequenceJ = json_array_get(sequencesJ, i);
if (sequenceJ)
- val = json_real_value(sequenceJ);
+ val = json_real_value(sequenceJ);
debug->logLines[i] = val;
}
}
@@ -441,6 +457,8 @@ void ComputerscareDebugWidget::appendContextMenu(Menu *menu)
menu->addChild(construct<DebugOutputRangeItem>(&MenuItem::text, " 0v ... +1v", &DebugOutputRangeItem::debug, debug, &DebugOutputRangeItem::outputRangeEnum, 3));
menu->addChild(construct<DebugOutputRangeItem>(&MenuItem::text, " -1v ... +1v", &DebugOutputRangeItem::debug, debug, &DebugOutputRangeItem::outputRangeEnum, 4));
menu->addChild(construct<DebugOutputRangeItem>(&MenuItem::text, "-10v ... +10v", &DebugOutputRangeItem::debug, debug, &DebugOutputRangeItem::outputRangeEnum, 5));
+ menu->addChild(construct<DebugOutputRangeItem>(&MenuItem::text, " -2v ... +2v", &DebugOutputRangeItem::debug, debug, &DebugOutputRangeItem::outputRangeEnum, 6));
+ menu->addChild(construct<DebugOutputRangeItem>(&MenuItem::text, " 0v ... +2v", &DebugOutputRangeItem::debug, debug, &DebugOutputRangeItem::outputRangeEnum, 7));
}
Model *modelComputerscareDebug = createModel<ComputerscareDebug, ComputerscareDebugWidget>("computerscare-debug");
diff --git a/src/ComputerscareILoveCookies.cpp b/src/ComputerscareILoveCookies.cpp
@@ -324,7 +324,9 @@ void ComputerscareILoveCookies::process(const ProcessArgs &args) {
bool currentResetActive;
bool currentResetTriggered;
bool currentManualResetClicked;
+ bool outputConnected;
float knobRawValue = 0.f;
+ float inV[16] = {10.f};
if (checkCounter > checkCounterLimit) {
if (!jsonLoaded) {
@@ -350,6 +352,8 @@ void ComputerscareILoveCookies::process(const ProcessArgs &args) {
for (int i = 0; i < numFields; i++) {
activeStep = false;
currentResetActive = inputs[RESET_INPUT + i].isConnected();
+ outputConnected=outputs[TRG_OUTPUT+i].isConnected();
+
currentResetTriggered = resetTriggers[i].process(inputs[RESET_INPUT + i].getVoltage() / 2.f);
currentManualResetClicked = manualResetTriggers[i].process(params[INDIVIDUAL_RESET_PARAM + i].getValue());
@@ -389,25 +393,33 @@ void ComputerscareILoveCookies::process(const ProcessArgs &args) {
}
}
}
- if (activeKnobIndex[i] < 0) {
- outputs[TRG_OUTPUT + i].setVoltage(0.f);
- }
- else if (activeKnobIndex[i] < 26) {
- knobRawValue = params[activeKnobIndex[i]].getValue();
- outputs[TRG_OUTPUT + i].setVoltage(mapKnobValue(knobRawValue, i));
- }
- else if (activeKnobIndex[i] < 52) {
- knobRawValue = inputs[SIGNAL_INPUT + activeKnobIndex[i] - 26].getVoltage();
- outputs[TRG_OUTPUT + i].setVoltage(knobRawValue);
- }
- else if (activeKnobIndex[i] < 78) {
- outputs[TRG_OUTPUT + i].setVoltage(newABS[i].exactFloats[activeKnobIndex[i] - 52]);
- }
- else if (activeKnobIndex[i] < 104) {
- outputs[TRG_OUTPUT + i].setVoltage(2.22);
- }
- else {
- outputs[TRG_OUTPUT + i].setVoltage(0.f);
+ if(outputConnected) {
+ if (activeKnobIndex[i] < 0) {
+ outputs[TRG_OUTPUT+i].setChannels(1);
+ outputs[TRG_OUTPUT + i].setVoltage(0.f);
+ }
+ else if (activeKnobIndex[i] < 26) {
+ outputs[TRG_OUTPUT+i].setChannels(1);
+ knobRawValue = params[activeKnobIndex[i]].getValue();
+ outputs[TRG_OUTPUT + i].setVoltage(mapKnobValue(knobRawValue, i));
+ }
+ else if (activeKnobIndex[i] < 52) {
+ outputs[TRG_OUTPUT+i].setChannels(inputs[SIGNAL_INPUT + activeKnobIndex[i] - 26].getChannels());
+ inputs[SIGNAL_INPUT + activeKnobIndex[i] - 26].readVoltages(inV);
+ outputs[TRG_OUTPUT + i].writeVoltages(inV);
+ }
+ else if (activeKnobIndex[i] < 78) {
+ outputs[TRG_OUTPUT+i].setChannels(1);
+ outputs[TRG_OUTPUT + i].setVoltage(newABS[i].exactFloats[activeKnobIndex[i] - 52]);
+ }
+ else if (activeKnobIndex[i] < 104) {
+ outputs[TRG_OUTPUT+i].setChannels(1);
+ outputs[TRG_OUTPUT + i].setVoltage(2.22);
+ }
+ else {
+ outputs[TRG_OUTPUT+i].setChannels(1);
+ outputs[TRG_OUTPUT + i].setVoltage(0.f);
+ }
}
if (inputs[CLOCK_INPUT + i].isConnected()) {
outputs[FIRST_STEP_OUTPUT + i].setVoltage((currentTriggerIsHigh && atFirstStep) ? 10.f : 0.0f);
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;