diff --git a/src/erwin.cpp b/src/erwin.cpp index 867271a..92c8e06 100644 --- a/src/erwin.cpp +++ b/src/erwin.cpp @@ -2,30 +2,31 @@ #include "osdialog.h" #include -#define NUM_CHANNELS 4 -#define NUM_SCALES 16 +static constexpr const int NUM_CHANNELS = 4; +static constexpr const int NUM_SCALES = 16; +static constexpr const int NUM_NOTES = 12; struct Erwin : Module { enum ParamIds { CHANNEL_TRANSPOSE_PARAM, NOTE_PARAM = CHANNEL_TRANSPOSE_PARAM + NUM_CHANNELS, - SELECT_PARAM = NOTE_PARAM + 12, + SELECT_PARAM = NOTE_PARAM + NUM_NOTES, NUM_PARAMS }; enum InputIds { TRANSPOSE_INPUT, SEMI_INPUT, IN_INPUT, - SELECT_INPUT = IN_INPUT + 4, + SELECT_INPUT = IN_INPUT + NUM_CHANNELS, NUM_INPUTS }; enum OutputIds { OUT_OUTPUT, - NUM_OUTPUTS = OUT_OUTPUT + 4 + NUM_OUTPUTS = OUT_OUTPUT + NUM_CHANNELS }; enum LightIds { NOTE_LIGHT, - NUM_LIGHTS = NOTE_LIGHT + 12 + NUM_LIGHTS = NOTE_LIGHT + NUM_NOTES }; enum QModes { @@ -41,17 +42,16 @@ struct Erwin : Module { configParam(Erwin::CHANNEL_TRANSPOSE_PARAM + 2, -4, 4, 0, "octave"); configParam(Erwin::CHANNEL_TRANSPOSE_PARAM + 3, -4, 4, 0, "octave"); configParam(Erwin::SELECT_PARAM, 0, 15, 0, "scene", "", 0, 1, 1); - for (int i = 0; i < 12; i++) { + for (int i = 0; i < NUM_NOTES; i++) { configParam(Erwin::NOTE_PARAM + i, 0.0, 1.0, 0.0, "enable/disable note"); } - for (int i = 0; i < 4; i++) { + for (int i = 0; i < NUM_CHANNELS; i++) { configInput(IN_INPUT + i, string::f("channel %i", i + 1)); configOutput(OUT_OUTPUT + i, string::f("channel %i", i + 1)); } configInput(SELECT_INPUT, "scene selection"); configInput(TRANSPOSE_INPUT, "transposition"); configInput(SEMI_INPUT, "semi"); - onReset(); } void process(const ProcessArgs &args) override; @@ -60,13 +60,12 @@ struct Erwin : Module { void onReset() override; int mode = 0; - bool noteState[12 * NUM_SCALES] = {}; + bool noteState[NUM_NOTES * NUM_SCALES] = {}; int octave = 0; int transposeOctave = 0; int transposeSemi = 0; float freq = 0.0f; - - dsp::SchmittTrigger noteTriggers[12]; + dsp::SchmittTrigger noteTriggers[NUM_NOTES]; }; json_t* Erwin::dataToJson() { @@ -74,7 +73,7 @@ json_t* Erwin::dataToJson() { // Note values json_t *gatesJ = json_array(); - for (int i = 0; i < 12 * NUM_SCALES; i++) { + for (int i = 0; i < NUM_NOTES * NUM_SCALES; i++) { json_t *gateJ = json_boolean(noteState[i]); json_array_append_new(gatesJ, gateJ); } @@ -104,83 +103,85 @@ void Erwin::dataFromJson(json_t *rootJ) { } } -void Erwin::onReset() { - for (int i = 0; i < 12 * NUM_SCALES; i++) noteState[i] = 0; +void Erwin::onReset() { + for (int i = 0; i < NUM_NOTES * NUM_SCALES; i++) noteState[i] = false; } void Erwin::process(const ProcessArgs &args) { // Scale selection int scaleOffset = clamp((int)(params[SELECT_PARAM].getValue() - + inputs[SELECT_INPUT].getVoltage() * NUM_SCALES /10),0,15) * 12; + + inputs[SELECT_INPUT].getVoltage() * NUM_SCALES / 10), 0, 15) * 12; bool* currentScale = noteState + scaleOffset; // limit to 1 octave transposeSemi = (int)round(inputs[SEMI_INPUT].getVoltage() * 1.2); - for(unsigned int y=0; y= 1.0) ? 0.7 : 0; } - } struct ErwinWidget : ModuleWidget { - ErwinWidget(Erwin *module) { + explicit ErwinWidget(Erwin *module) { setModule(module); box.size = Vec(8 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); setPanel(createPanel(asset::plugin(pluginInstance, "res/reface/rewin_bg.svg"))); @@ -193,9 +194,9 @@ struct ErwinWidget : ModuleWidget { addInput(createInput(Vec(85.75, 108.75), module, Erwin::TRANSPOSE_INPUT)); addInput(createInput(Vec(48.25, 108.75), module, Erwin::SEMI_INPUT)); - for(int i=0;i(Vec(92.75, 198.75 + i*42), module, Erwin::OUT_OUTPUT + i)); - addInput(createInput(Vec(62.75, 198.75 + i*42), module, Erwin::IN_INPUT + i)); + for(int i = 0; i < NUM_CHANNELS; i++) { + addOutput(createOutput(Vec(92.75, 198.75 + i * 42), module, Erwin::OUT_OUTPUT + i)); + addInput(createInput(Vec(62.75, 198.75 + i * 42), module, Erwin::IN_INPUT + i)); } addParam(createParam(Vec(80, 181), module, Erwin::CHANNEL_TRANSPOSE_PARAM)); @@ -204,19 +205,18 @@ struct ErwinWidget : ModuleWidget { addParam(createParam(Vec(80, 308), module, Erwin::CHANNEL_TRANSPOSE_PARAM + 3)); /* note buttons */ - int white=0; - int black = 0; - for(int i=0; i<12; i++) { + int white = 0, black = 0; + for(int i = 0; i < NUM_NOTES; i++) { if (i == 1 || i == 3 || i == 6 || i == 8 || i == 10 ) { - addParam(createParam(Vec(8, 312 - black*28), module, Erwin::NOTE_PARAM + i)); - addChild(createLight>(Vec(10, 314 - black*28), module, Erwin::NOTE_LIGHT + i)); + addParam(createParam(Vec(8, 312 - black * 28), module, Erwin::NOTE_PARAM + i)); + addChild(createLight>(Vec(10, 314 - black * 28), module, Erwin::NOTE_LIGHT + i)); black++; } else { if(i == 4) black++; - addParam(createParam(Vec(33, 326 - white*28), module, Erwin::NOTE_PARAM + i)); - addChild(createLight>(Vec(35, 328 - white*28), module, Erwin::NOTE_LIGHT + i)); + addParam(createParam(Vec(33, 326 - white * 28), module, Erwin::NOTE_PARAM + i)); + addChild(createLight>(Vec(35, 328 - white * 28), module, Erwin::NOTE_LIGHT + i)); white++; } } @@ -259,7 +259,7 @@ struct ErwinWidget : ModuleWidget { async_dialog_filebrowser(true, nullptr, "Save scales", [rootJ](char* path) { pathSelected(rootJ, path); }); -#else +#else char* path = osdialog_file(OSDIALOG_SAVE, NULL, "rewin.json", NULL); pathSelected(rootJ, path); #endif @@ -285,7 +285,7 @@ struct ErwinWidget : ModuleWidget { async_dialog_filebrowser(false, nullptr, "Load scales", [module](char* path) { pathSelected(module, path); }); -#else +#else char* path = osdialog_file(OSDIALOG_OPEN, NULL, NULL, NULL); pathSelected(module, path); #endif @@ -301,9 +301,9 @@ struct ErwinWidget : ModuleWidget { if(!gatesJ || json_array_size(gatesJ) != 12 * NUM_SCALES) { #ifdef USING_CARDINAL_NOT_RACK async_dialog_message("rewin: invalid input file"); -#else +#else osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, "rewin: invalid input file"); -#endif +#endif return; } module->dataFromJson(rootJ); @@ -311,9 +311,9 @@ struct ErwinWidget : ModuleWidget { else { #ifdef USING_CARDINAL_NOT_RACK async_dialog_message("rewin: can't load file - see logfile for details"); -#else +#else osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, "rewin: can't load file - see logfile for details"); -#endif +#endif DEBUG("Error: Can't import file %s", path); DEBUG("Text: %s", error.text); DEBUG("Source: %s", error.source); diff --git a/src/mixer.cpp b/src/mixer.cpp index b4e3280..9b9b248 100644 --- a/src/mixer.cpp +++ b/src/mixer.cpp @@ -139,7 +139,7 @@ void Mixer::process(const ProcessArgs &args) { float aux2LIn = inputs[AUX2_L_INPUT].getNormalVoltage(0.0f); float aux2RIn = inputs[AUX2_R_INPUT].getNormalVoltage(0.0f); - for(int i=0;i res) { - for(int i=0; i minDelta) { - gatePulse[i].trigger(0.01); - } - - lastValue[i] = value; - } - frame = 0; + if(++frame > res) { + for(int i=0; i minDelta) { + gatePulse[i][c].trigger(0.01); + } + lastValue[i][c] = value; + } + } + frame = 0; } for(int i=0; i