Browse Source

RandomValues: Store values in class variable, not output ports.

tags/v2.6.0
Andrew Belt 1 year ago
parent
commit
ecbab0e7a1
1 changed files with 7 additions and 10 deletions
  1. +7
    -10
      src/RandomValues.cpp

+ 7
- 10
src/RandomValues.cpp View File

@@ -24,6 +24,7 @@ struct RandomValues : Module {


dsp::BooleanTrigger pushTrigger; dsp::BooleanTrigger pushTrigger;
dsp::TSchmittTrigger<float_4> trigTriggers[4]; dsp::TSchmittTrigger<float_4> trigTriggers[4];
float values[7][16] = {};
float randomGain = 10.f; float randomGain = 10.f;
float randomOffset = 0.f; float randomOffset = 0.f;


@@ -69,16 +70,15 @@ struct RandomValues : Module {
} }


for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
// Don't call setChannels because we need to preserve all channel values
outputs[RND_OUTPUTS + i].channels = channels;
outputs[RND_OUTPUTS + i].setChannels(channels);
outputs[RND_OUTPUTS + i].writeVoltages(values[i]);
} }
lights[PUSH_LIGHT].setBrightnessSmooth(light, args.sampleTime); lights[PUSH_LIGHT].setBrightnessSmooth(light, args.sampleTime);
} }


void randomizeValues(int channel) { void randomizeValues(int channel) {
for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
float r = random::get<float>() * randomGain + randomOffset;
outputs[RND_OUTPUTS + i].setVoltage(r, channel);
values[i][channel] = random::get<float>() * randomGain + randomOffset;
} }
} }


@@ -89,8 +89,7 @@ struct RandomValues : Module {
for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
json_t* channelsJ = json_array(); json_t* channelsJ = json_array();
for (int c = 0; c < 16; c++) { for (int c = 0; c < 16; c++) {
float value = outputs[RND_OUTPUTS + i].getVoltage(c);
json_array_insert_new(channelsJ, c, json_real(value));
json_array_insert_new(channelsJ, c, json_real(values[i][c]));
} }
json_array_insert_new(valuesJ, i, channelsJ); json_array_insert_new(valuesJ, i, channelsJ);
} }
@@ -109,10 +108,8 @@ struct RandomValues : Module {
if (channelsJ) if (channelsJ)
for (int c = 0; c < 16; c++) { for (int c = 0; c < 16; c++) {
json_t* valueJ = json_array_get(channelsJ, c); json_t* valueJ = json_array_get(channelsJ, c);
if (valueJ) {
float value = json_number_value(valueJ);
outputs[RND_OUTPUTS + i].setVoltage(value, c);
}
if (valueJ)
values[i][c] = json_number_value(valueJ);
} }
} }




Loading…
Cancel
Save