diff --git a/src/gateseq.cpp b/src/gateseq.cpp index 8038af5..8c336f7 100644 --- a/src/gateseq.cpp +++ b/src/gateseq.cpp @@ -19,7 +19,7 @@ struct Gateseq : Via { struct ModulationQuantity; struct ModulationCVQuantity; struct ButtonQuantity; - + Gateseq() : Via(), virtualModule(asset::plugin(pluginInstance, "res/original.gateseq")) { virtualIO = &virtualModule; @@ -32,14 +32,14 @@ struct Gateseq : Via { configParam(CV2AMT_PARAM, 0, 1.0, 1.0, "Pattern I modulation CV amount"); configParam(A_PARAM, -5.0, 5.0, 5.0, "Pattern I gate level"); configParam(CV3AMT_PARAM, 0, 1.0, 1.0, "Pattern II density CV amount"); - + configParam(BUTTON1_PARAM, 0.0, 1.0, 0.0, "A channel/ PTN I S+H control"); configParam(BUTTON2_PARAM, 0.0, 1.0, 0.0, "A channel/ PTN I gate control"); configParam(BUTTON3_PARAM, 0.0, 1.0, 0.0, "Pattern I mode"); configParam(BUTTON4_PARAM, 0.0, 1.0, 0.0, "B channel/ PTN II S+H control"); configParam(BUTTON5_PARAM, 0.0, 1.0, 0.0, "B channel/ PTN II gate control"); configParam(BUTTON6_PARAM, 0.0, 1.0, 0.0, "Pattern II patterns"); - + configParam(TRIGBUTTON_PARAM, 0.0, 5.0, 0.0, "Pattern reset"); configInput(A_INPUT, "A"); @@ -64,7 +64,7 @@ struct Gateseq : Via { presetData[4] = virtualModule.gateseqUI.stockPreset5; presetData[5] = virtualModule.gateseqUI.stockPreset6; } - + void process(const ProcessArgs &args) override; ViaGateseq virtualModule; @@ -96,20 +96,20 @@ struct Gateseq : Via { } else if (sampleRate == 768000.0) { virtualModule.sequencer.virtualTimer4Overflow = 768; } - + } json_t *dataToJson() override { json_t *rootJ = json_object(); - + json_object_set_new(rootJ, "gateseq_modes", json_integer(virtualModule.gateseqUI.modeStateBuffer)); json_object_set_new(rootJ, "logic_mode", json_integer((int) virtualModule.gateseqUI.aux2Mode)); - + json_object_set_new(rootJ, "patterns_file", json_string(patternsPath.c_str())); return rootJ; } - + void dataFromJson(json_t *rootJ) override { json_t *modesJ = json_object_get(rootJ, "gateseq_modes"); @@ -127,7 +127,7 @@ struct Gateseq : Via { virtualModule.handleButton6ModeChange(virtualModule.gateseqUI.button6Mode); } } - + std::string patternsPath = asset::plugin(pluginInstance, "res/original.gateseq"); }; @@ -180,7 +180,7 @@ void Gateseq::process(const ProcessArgs &args) { // A and B inputs with normalled reference voltages float aIn = inputs[A_INPUT].getVoltage() + (!inputs[A_INPUT].isConnected()) * params[A_PARAM].getValue(); float bIn = (inputs[B_INPUT].isConnected()) * ((inputs[B_INPUT].getVoltage()) * (params[B_PARAM].getValue())) + (!inputs[B_INPUT].isConnected()) * (5* (params[B_PARAM].getValue())); - + // sample and holds // get a new sample on the rising edge at the sh control output if (virtualIO->shAState > shALast) { @@ -199,13 +199,13 @@ void Gateseq::process(const ProcessArgs &args) { // VCA/mixing stage // normalize 12 bits to 0-1 - outputs[MAIN_OUTPUT].setVoltage(bIn*(dac2Sample/4095.0) + aIn*(dac1Sample/4095.0)); + outputs[MAIN_OUTPUT].setVoltage(bIn*(dac2Sample/4095.0) + aIn*(dac1Sample/4095.0)); outputs[AUX_DAC_OUTPUT].setVoltage((dac3Sample/4095.0 - .5) * -10.666666666); outputs[LOGICA_OUTPUT].setVoltage(virtualIO->logicAState * 5.0); outputs[AUX_LOGIC_OUTPUT].setVoltage(virtualIO->auxLogicState * 5.0); clockDivider = 0; - + } struct GateseqWidget : ModuleWidget { @@ -230,14 +230,14 @@ struct GateseqWidget : ModuleWidget { addParam(createParam(Vec(128.04 + .753, 30.90), module, Gateseq::CV2AMT_PARAM)); addParam(createParam(Vec(128.04 + .753, 100.4), module, Gateseq::A_PARAM)); addParam(createParam(Vec(128.04 + .753, 169.89), module, Gateseq::CV3AMT_PARAM)); - + addParam(createParam(Vec(8 + .753, 85), module, Gateseq::BUTTON1_PARAM)); addParam(createParam(Vec(48 + .753, 85), module, Gateseq::BUTTON2_PARAM)); addParam(createParam(Vec(86 + .753, 85), module, Gateseq::BUTTON3_PARAM)); addParam(createParam(Vec(8 + .753, 139), module, Gateseq::BUTTON4_PARAM)); addParam(createParam(Vec(48 + .753, 139), module, Gateseq::BUTTON5_PARAM)); addParam(createParam(Vec(86 + .753, 139), module, Gateseq::BUTTON6_PARAM)); - + addParam(createParam(Vec(132.7 + .753, 320), module, Gateseq::TRIGBUTTON_PARAM)); addInput(createInput(Vec(8.07 + 1.053, 241.12), module, Gateseq::A_INPUT)); @@ -329,18 +329,28 @@ struct GateseqWidget : ModuleWidget { menu->addChild(stockPresets); struct ScaleSetHandler : MenuItem { - Gateseq *module; + Gateseq *module; void onAction(const event::Action &e) override { - - char* pathC = osdialog_file(OSDIALOG_OPEN, NULL, NULL, NULL); - if (!pathC) { - // Fail silently - return; - } - DEFER({ - std::free(pathC); - }); - +#ifdef USING_CARDINAL_NOT_RACK + Gateseq* module = this->module; + async_dialog_filebrowser(false, NULL, NULL, "Load Bank", [module](char* pathC) { + pathSelected(module, pathC); + }); +#else + char* pathC = osdialog_file(OSDIALOG_OPEN, NULL, NULL, NULL); + pathSelected(module, pathC); +#endif + } + + static void pathSelected(Gateseq* module, char* pathC) { + if (!pathC) { + // Fail silently + return; + } + DEFER({ + std::free(pathC); + }); + module->virtualModule.readPatternsFromFile(pathC); module->virtualModule.handleButton3ModeChange(module->virtualModule.gateseqUI.button3Mode); module->virtualModule.handleButton6ModeChange(module->virtualModule.gateseqUI.button6Mode); @@ -376,8 +386,8 @@ struct Gateseq::PatternIQuantity : ViaKnobQuantity { } } - return 1 + (gateseqModule->virtualModule.controls.knob1Value >> 8); - + return 1 + (gateseqModule->virtualModule.controls.knob1Value >> 8); + } float translateInput(float userInput) override { @@ -407,8 +417,8 @@ struct Gateseq::PatternIModQuantity : ViaKnobQuantity { return ((swing/65535.0) + 0.25) * 100.0; } else { return gateseqModule->virtualModule.controls.knob2Value >> 9; - } - + } + } float translateInput(float userInput) override { @@ -476,8 +486,8 @@ struct Gateseq::PatternIIQuantity : ViaKnobQuantity { } } - return 1 + (gateseqModule->virtualModule.controls.knob3Value >> 8); - + return 1 + (gateseqModule->virtualModule.controls.knob3Value >> 8); + } float translateInput(float userInput) override { @@ -496,7 +506,7 @@ struct Gateseq::SHIButtonQuantity : ViaButtonQuantity<3> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Gateseq * gateseqModule = dynamic_cast(this->module); @@ -526,7 +536,7 @@ struct Gateseq::GateIButtonQuantity : ViaButtonQuantity<3> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Gateseq * gateseqModule = dynamic_cast(this->module); @@ -556,7 +566,7 @@ struct Gateseq::SeqIButtonQuantity : ViaButtonQuantity<4> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Gateseq * gateseqModule = dynamic_cast(this->module); @@ -580,13 +590,13 @@ struct Gateseq::SeqIButtonQuantity : ViaButtonQuantity<4> { struct Gateseq::SHIIButtonQuantity : ViaButtonQuantity<3> { std::string buttonModes[3] = {"Off", "Sample and hold during gate", "Resample on rising edge"}; - + SHIIButtonQuantity() { for (int i = 0; i < 3; i++) { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Gateseq * gateseqModule = dynamic_cast(this->module); @@ -616,7 +626,7 @@ struct Gateseq::GateIIButtonQuantity : ViaButtonQuantity<3> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Gateseq * gateseqModule = dynamic_cast(this->module); @@ -646,7 +656,7 @@ struct Gateseq::SeqIIButtonQuantity : ViaButtonQuantity<4> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Gateseq * gateseqModule = dynamic_cast(this->module); @@ -675,7 +685,7 @@ struct Gateseq::ModulationQuantity : ParamQuantity { Gateseq * gateseqModule = (Gateseq *) module; - return modes[gateseqModule->virtualModule.gateseqUI.button3Mode]; + return modes[gateseqModule->virtualModule.gateseqUI.button3Mode]; } diff --git a/src/meta.cpp b/src/meta.cpp index d6c1644..97f60fd 100644 --- a/src/meta.cpp +++ b/src/meta.cpp @@ -21,7 +21,7 @@ struct Meta : Via { ExpoConverter expo; Meta() : Via(), virtualModule(asset::plugin(pluginInstance, "res/original.meta")) { - + virtualIO = &virtualModule; config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); @@ -34,14 +34,14 @@ struct Meta : Via { configParam(A_PARAM, -5.0, 5.0, -5.0, "A level"); paramQuantities[A_PARAM]->description = "Main output is bounded between A and B levels"; configParam(CV3AMT_PARAM, 0, 1.0, 1.0, "Wave shape CV scale"); - + configParam(BUTTON1_PARAM, 0.0, 1.0, 0.0, "S+H"); configParam(BUTTON2_PARAM, 0.0, 1.0, 0.0, "Wavetable"); configParam(BUTTON3_PARAM, 0.0, 1.0, 0.0, "Frequency range"); configParam(BUTTON4_PARAM, 0.0, 1.0, 0.0, "TRIG response"); configParam(BUTTON5_PARAM, 0.0, 1.0, 0.0, "Wavetable"); configParam(BUTTON6_PARAM, 0.0, 1.0, 0.0, "Loop"); - + configParam(TRIGBUTTON_PARAM, 0.0, 5.0, 0.0, "Manual Trigger"); configInput(A_INPUT, "A"); @@ -64,7 +64,7 @@ struct Meta : Via { presetData[3] = virtualModule.metaUI.stockPreset4; presetData[4] = virtualModule.metaUI.stockPreset5; presetData[5] = virtualModule.metaUI.stockPreset6; - + } void process(const ProcessArgs &args) override; @@ -141,13 +141,13 @@ struct Meta : Via { } sampleRateStore = sampleRate/(float)divideAmount; - + } json_t *dataToJson() override { json_t *rootJ = json_object(); - + // freq json_object_set_new(rootJ, "meta_modes", json_integer(virtualModule.metaUI.modeStateBuffer)); json_object_set_new(rootJ, "table_file", json_string(tablePath.c_str())); @@ -156,7 +156,7 @@ struct Meta : Via { } int32_t testMode; - + void dataFromJson(json_t *rootJ) override { json_t *modesJ = json_object_get(rootJ, "meta_modes"); @@ -173,7 +173,7 @@ struct Meta : Via { } } std::string tablePath = asset::plugin(pluginInstance, "res/original.meta"); - + }; void Meta::process(const ProcessArgs &args) { @@ -191,9 +191,9 @@ void Meta::process(const ProcessArgs &args) { virtualModule.slowConversionCallback(); virtualModule.ui_dispatch(SENSOR_EVENT_SIG); virtualModule.metaUI.incrementTimer(); - + processTriggerButton(); - + virtualModule.blinkTimerCount += virtualModule.blinkTimerEnable; virtualModule.blankTimerCount += virtualModule.blankTimerEnable; if (virtualModule.blinkTimerCount > virtualModule.blinkTimerOverflow) { @@ -215,7 +215,7 @@ void Meta::process(const ProcessArgs &args) { updateAudioRate(); } - + } // Custom parameter widgets @@ -245,14 +245,14 @@ struct MetaWidget : ModuleWidget { addParam(createParam(Vec(128.04 + .753, 30.90), module, Meta::CV2AMT_PARAM)); addParam(createParam(Vec(128.04 + .753, 100.4), module, Meta::A_PARAM)); addParam(createParam(Vec(128.04 + .753, 169.89), module, Meta::CV3AMT_PARAM)); - + addParam(createParam(Vec(10.5 + .753, 80), module, Meta::BUTTON1_PARAM)); addParam(createParam(Vec(47 + .753, 77.5), module, Meta::BUTTON2_PARAM)); addParam(createParam(Vec(85 + .753, 80), module, Meta::BUTTON3_PARAM)); addParam(createParam(Vec(10.5 + .753, 129), module, Meta::BUTTON4_PARAM)); addParam(createParam(Vec(46 + .753, 131.5), module, Meta::BUTTON5_PARAM)); addParam(createParam(Vec(85 + .753, 129), module, Meta::BUTTON6_PARAM)); - + addParam(createParam(Vec(132.7 + .753, 320), module, Meta::TRIGBUTTON_PARAM)); addInput(createInput(Vec(8.07 + 1.053, 241.12), module, Meta::A_INPUT)); @@ -396,18 +396,28 @@ struct MetaWidget : ModuleWidget { menu->addChild(stockPresets); struct TableSetHandler : MenuItem { - Meta *module; + Meta *module; void onAction(const event::Action &e) override { - - char* pathC = osdialog_file(OSDIALOG_OPEN, NULL, NULL, NULL); - if (!pathC) { - // Fail silently - return; - } - DEFER({ - std::free(pathC); - }); - +#ifdef USING_CARDINAL_NOT_RACK + Meta* module = this->module; + async_dialog_filebrowser(false, NULL, NULL, "Load Wavetable", [module](char* pathC) { + pathSelected(module, pathC); + }); +#else + char* pathC = osdialog_file(OSDIALOG_OPEN, NULL, NULL, NULL); + pathSelected(module, pathC); +#endif + } + + static void pathSelected(Meta* module, char* pathC) { + if (!pathC) { + // Fail silently + return; + } + DEFER({ + std::free(pathC); + }); + module->virtualModule.readTableSetFromFile(pathC); module->tablePath = pathC; } @@ -501,7 +511,7 @@ struct Meta::Time1Quantity : ViaKnobQuantity { timeBase1 *= 3.0; } - return timeBase1/META_WAVETABLE_LENGTH * metaModule->sampleRateStore; + return timeBase1/META_WAVETABLE_LENGTH * metaModule->sampleRateStore; } else if (freqMode == 0) { @@ -512,7 +522,7 @@ struct Meta::Time1Quantity : ViaKnobQuantity { timeBase1 /= 4.0; - return timeBase1/META_WAVETABLE_LENGTH * metaModule->sampleRateStore; + return timeBase1/META_WAVETABLE_LENGTH * metaModule->sampleRateStore; } else if (freqMode == 1) { @@ -527,8 +537,8 @@ struct Meta::Time1Quantity : ViaKnobQuantity { metaModule->expo.convert(1024) >> 9); return 1.0/(timeBase1/META_WAVETABLE_LENGTH * metaModule->sampleRateStore); - } - + } + } float translateInput(float userInput) override { @@ -547,7 +557,7 @@ struct Meta::Time1Quantity : ViaKnobQuantity { if (drumType < 2) { - targetScale = userInput/21.797; + targetScale = userInput/21.797; } else { @@ -555,17 +565,17 @@ struct Meta::Time1Quantity : ViaKnobQuantity { } - targetScale = log2(targetScale * 2.0); + targetScale = log2(targetScale * 2.0); float time1 = roundf(targetScale * 384.0 * (8.0/3.0)) - 1024.0; - - return time1; + + return time1; } else if (freqMode == 0) { float targetScale = userInput/16.34; - targetScale = log2(targetScale); + targetScale = log2(targetScale); float time1 = targetScale * 384.0 * (4.0/3.0); @@ -577,9 +587,9 @@ struct Meta::Time1Quantity : ViaKnobQuantity { timeBase1 = timeBase1/META_WAVETABLE_LENGTH * metaModule->sampleRateStore; - metaModule->paramQuantities[Meta::KNOB2_PARAM]->setValue((userInput/timeBase1 - 1.0) * 4095.0); - - return time1; + metaModule->paramQuantities[Meta::KNOB2_PARAM]->setValue((userInput/timeBase1 - 1.0) * 4095.0); + + return time1; } else if (freqMode == 1) { @@ -601,7 +611,7 @@ struct Meta::Time1Quantity : ViaKnobQuantity { return (4095.0 - (metaModule->reverseExpo(desiredIncrement)) * 384.0); - } + } }; void setLabel(void) override { @@ -614,7 +624,7 @@ struct Meta::Time1Quantity : ViaKnobQuantity { } int getDisplayPrecision(void) override { return 3; - } + } }; @@ -696,7 +706,7 @@ struct Meta::Time2Quantity : ViaKnobQuantity { timeBase1 /= 4.0; - return timeBase1/META_WAVETABLE_LENGTH * metaModule->sampleRateStore; + return timeBase1/META_WAVETABLE_LENGTH * metaModule->sampleRateStore; } else if (freqMode == 1) { @@ -710,8 +720,8 @@ struct Meta::Time2Quantity : ViaKnobQuantity { return (((float) metaModule->virtualModule.controls.knob2Value) / 4095.0) * 60.0 + 20.0; } - - + + } float translateInput(float userInput) override { @@ -737,7 +747,7 @@ struct Meta::Time2Quantity : ViaKnobQuantity { float targetScale = userInput/16.34; - targetScale = log2(targetScale); + targetScale = log2(targetScale); float time1 = targetScale * 384.0 * (4.0/3.0); @@ -749,9 +759,9 @@ struct Meta::Time2Quantity : ViaKnobQuantity { timeBase1 /= 4.0; - timeBase1 = timeBase1/META_WAVETABLE_LENGTH * metaModule->sampleRateStore; - - return (userInput/timeBase1 - 1.0) * 4095.0; + timeBase1 = timeBase1/META_WAVETABLE_LENGTH * metaModule->sampleRateStore; + + return (userInput/timeBase1 - 1.0) * 4095.0; } else if (freqMode == 1) { @@ -767,7 +777,7 @@ struct Meta::Time2Quantity : ViaKnobQuantity { return ((userInput - 20.0)/60.0) * 4095.0; - } + } }; @@ -798,8 +808,8 @@ struct Meta::WaveshapeQuantity : ViaKnobQuantity { Meta * metaModule = dynamic_cast(this->module); - return metaModule->virtualModule.metaWavetable.tableSize * value/4095.0; - + return metaModule->virtualModule.metaWavetable.tableSize * value/4095.0; + } float translateInput(float userInput) override { @@ -828,7 +838,7 @@ struct Meta::SHButtonQuantity : ViaButtonQuantity<6> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Meta * metaModule = dynamic_cast(this->module); @@ -859,7 +869,7 @@ struct Meta::TableButtonQuantity : ViaComplexButtonQuantity { modes = buttonModes[0]; numModes = 8; } - + int getModeEnumeration(void) override { Meta * metaModule = dynamic_cast(this->module); @@ -899,7 +909,7 @@ struct Meta::FreqButtonQuantity : ViaButtonQuantity<3> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Meta * metaModule = dynamic_cast(this->module); @@ -929,7 +939,7 @@ struct Meta::TrigButtonQuantity : ViaComplexButtonQuantity { modes = trigModes; numModes = 0; } - + int getModeEnumeration(void) override { Meta * metaModule = dynamic_cast(this->module); @@ -989,7 +999,7 @@ struct Meta::LoopButtonQuantity : ViaButtonQuantity<2> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Meta * metaModule = dynamic_cast(this->module); diff --git a/src/osc3.cpp b/src/osc3.cpp index d85df30..604d383 100644 --- a/src/osc3.cpp +++ b/src/osc3.cpp @@ -17,7 +17,7 @@ struct Osc3 : Via { struct DetuneButtonQuantity; float effectiveSR = 48000.0f; - + Osc3() : Via(), virtualModule(asset::plugin(pluginInstance, "res/original.osc3")) { virtualIO = &virtualModule; @@ -30,14 +30,14 @@ struct Osc3 : Via { configParam(CV2AMT_PARAM, 0, 1.0, 1.0, "2 + 3 Phase CV scale"); configParam(A_PARAM, -5.0, 5.0, 5.0, "Oscillator 2 level"); configParam(CV3AMT_PARAM, 0, 1.0, 1.0, "Detune CV scale"); - + configParam(BUTTON1_PARAM, 0.0, 1.0, 0.0, "Octave offset"); configParam(BUTTON2_PARAM, 0.0, 1.0, 0.0, "Waveshape"); configParam(BUTTON3_PARAM, 0.0, 1.0, 0.0, "Osc1 -> 2 and 3 level SH"); configParam(BUTTON4_PARAM, 0.0, 1.0, 0.0, "Octave offset"); configParam(BUTTON5_PARAM, 0.0, 1.0, 0.0, "Quantization"); configParam(BUTTON6_PARAM, 0.0, 1.0, 0.0, "Beat/detune mode"); - + configParam(TRIGBUTTON_PARAM, 0.0, 5.0, 0.0, "Unity"); configInput(A_INPUT, "Oscillator 2 level"); @@ -106,7 +106,7 @@ struct Osc3 : Via { effectiveSR = 48000.0; virtualModule.absoluteTune = 45729; } - + } json_t *dataToJson() override { @@ -116,15 +116,15 @@ struct Osc3 : Via { json_object_set_new(rootJ, "osc_modes", json_integer(virtualModule.osc3UI.modeStateBuffer)); json_object_set_new(rootJ, "optimization", json_integer(optimize)); json_object_set_new(rootJ, "scale_file", json_string(scalePath.c_str())); - + return rootJ; } - + void dataFromJson(json_t *rootJ) override { json_t *opt = json_object_get(rootJ, "optimization"); if (opt) { - optimize = json_integer_value(opt); + optimize = json_integer_value(opt); } json_t *modesJ = json_object_get(rootJ, "osc_modes"); @@ -386,9 +386,9 @@ struct Osc3 : Via { blampDelay2[1] = dac2Sample; blampDelay3[1] = dac3Sample; - dac1Sample = dac1Output + dac1PolyBlamp.process(); - dac2Sample = dac2Output + dac2PolyBlamp.process(); - dac3Sample = dac3Output + dac3PolyBlamp.process(); + dac1Sample = dac1Output + dac1PolyBlamp.process(); + dac2Sample = dac2Output + dac2PolyBlamp.process(); + dac3Sample = dac3Output + dac3PolyBlamp.process(); } else if (virtualModule.osc3UI.button2Mode == 3) { @@ -440,9 +440,9 @@ struct Osc3 : Via { blampDelay2[1] = dac2Sample; blampDelay3[1] = dac3Sample; - dac1Sample = dac1Output + dac1PolyBlamp.process(); - dac2Sample = dac2Output + dac2PolyBlamp.process(); - dac3Sample = dac3Output + dac3PolyBlamp.process(); + dac1Sample = dac1Output + dac1PolyBlamp.process(); + dac2Sample = dac2Output + dac2PolyBlamp.process(); + dac3Sample = dac3Output + dac3PolyBlamp.process(); } @@ -454,7 +454,7 @@ struct Osc3 : Via { // if (virtualModule.osc3UI.button2Mode == 0) { // if (dac1Sample) // } - + virtualIO->halfTransferCallback(); // "model" the circuit @@ -462,7 +462,7 @@ struct Osc3 : Via { float aIn = inputs[A_INPUT].isConnected() ? inputs[A_INPUT].getVoltage() : params[A_PARAM].getValue(); float bIn = inputs[B_INPUT].isConnected() ? inputs[B_INPUT].getVoltage() : 5.0; bIn *= params[B_PARAM].getValue(); - + // sample and holds // get a new sample on the rising edge at the sh control output if (virtualIO->shAState > shALast) { @@ -481,7 +481,7 @@ struct Osc3 : Via { // VCA/mixing stage // normalize 12 bits to 0-1 - outputs[MAIN_OUTPUT].setVoltage(bIn*(dac2Sample/4095.0) + aIn*(dac1Sample/4095.0)); + outputs[MAIN_OUTPUT].setVoltage(bIn*(dac2Sample/4095.0) + aIn*(dac1Sample/4095.0)); outputs[AUX_DAC_OUTPUT].setVoltage((dac3Sample/4095.0 - .5) * -10.666666666); outputs[LOGICA_OUTPUT].setVoltage(virtualIO->logicAState * 5.0); outputs[AUX_LOGIC_OUTPUT].setVoltage(virtualIO->auxLogicState * 5.0); @@ -491,7 +491,7 @@ struct Osc3 : Via { clockDivider = 0; } - + }; void Osc3::process(const ProcessArgs &args) { @@ -521,7 +521,7 @@ void Osc3::process(const ProcessArgs &args) { virtualModule.advanceMeasurementTimer(); } - + } struct Osc3Widget : ModuleWidget { @@ -546,14 +546,14 @@ struct Osc3Widget : ModuleWidget { addParam(createParam(Vec(128.04 + .753, 30.90), module, Osc3::CV2AMT_PARAM)); addParam(createParam(Vec(128.04 + .753, 100.4), module, Osc3::A_PARAM)); addParam(createParam(Vec(128.04 + .753, 169.89), module, Osc3::CV3AMT_PARAM)); - + addParam(createParam(Vec(10.5 + .753, 88), module, Osc3::BUTTON1_PARAM)); addParam(createParam(Vec(47 + .753, 77.5), module, Osc3::BUTTON2_PARAM)); addParam(createParam(Vec(85 + .753, 90), module, Osc3::BUTTON3_PARAM)); addParam(createParam(Vec(10.5 + .753, 129), module, Osc3::BUTTON4_PARAM)); addParam(createParam(Vec(47 + .753, 133.5), module, Osc3::BUTTON5_PARAM)); addParam(createParam(Vec(85 + .753, 129), module, Osc3::BUTTON6_PARAM)); - + addParam(createParam(Vec(132.7 + .753, 320), module, Osc3::TRIGBUTTON_PARAM)); addInput(createInput(Vec(8.07 + 1.053, 241.12), module, Osc3::A_INPUT)); @@ -600,18 +600,28 @@ struct Osc3Widget : ModuleWidget { }; struct ScaleSetHandler : MenuItem { - Osc3 *module; + Osc3 *module; void onAction(const event::Action &e) override { - - char* pathC = osdialog_file(OSDIALOG_OPEN, NULL, NULL, NULL); - if (!pathC) { - // Fail silently - return; - } - DEFER({ - std::free(pathC); - }); - +#ifdef USING_CARDINAL_NOT_RACK + Osc3* module = this->module; + async_dialog_filebrowser(false, NULL, NULL, "Load Scale", [module](char* pathC) { + pathSelected(module, pathC); + }); +#else + char* pathC = osdialog_file(OSDIALOG_OPEN, NULL, NULL, NULL); + pathSelected(module, pathC); +#endif + } + + static void pathSelected(Osc3* module, char* pathC) { + if (!pathC) { + // Fail silently + return; + } + DEFER({ + std::free(pathC); + }); + module->virtualModule.readScalesFromFile(pathC); module->scalePath = pathC; } @@ -634,7 +644,7 @@ struct Osc3Widget : ModuleWidget { menu->addChild(menuItem); } - + }; Model *modelOsc3 = createModel("OSC3"); @@ -698,7 +708,7 @@ struct Osc3::FreqKnobQuantity: ViaKnobQuantity { rootIncrement >>= 3; if (osc3Module->virtualModule.osc3UI.button5Mode) { - rootIncrement &= 0xFE0; + rootIncrement &= 0xFE0; } rootIncrement = osc3Module->virtualModule.expo.convert(rootIncrement) >> 3; @@ -710,9 +720,9 @@ struct Osc3::FreqKnobQuantity: ViaKnobQuantity { float frequency = osc3Module->effectiveSR * 32 * (rootIncrement/4294967296.0f); frequency *= pow(2, osc3Module->virtualModule.octaveRange); - - return frequency; - + + return frequency; + } void setDisplayValue(float input) override { @@ -803,7 +813,7 @@ struct Osc3::DetuneKnobQuantity: ViaKnobQuantity { unit = "Notes"; - int32_t chord = __USAT(((osc3Module->virtualModule.controls.knob3Value << 4)) + + int32_t chord = __USAT(((osc3Module->virtualModule.controls.knob3Value << 4)) + (int32_t) -osc3Module->virtualModule.inputs.cv3Samples[0], 16); chord >>= 12; @@ -845,7 +855,7 @@ struct Osc3::OctaveButtonQuantity : ViaButtonQuantity<6> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Osc3 * osc3Module = dynamic_cast(this->module); @@ -875,7 +885,7 @@ struct Osc3::WaveshapeButtonQuantity : ViaButtonQuantity<4> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Osc3 * osc3Module = dynamic_cast(this->module); @@ -905,7 +915,7 @@ struct Osc3::SHButtonQuantity : ViaButtonQuantity<2> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Osc3 * osc3Module = dynamic_cast(this->module); @@ -935,7 +945,7 @@ struct Osc3::QuantizationButtonQuantity : ViaButtonQuantity<4> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Osc3 * osc3Module = dynamic_cast(this->module); @@ -965,7 +975,7 @@ struct Osc3::DetuneButtonQuantity : ViaButtonQuantity<4> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Osc3 * osc3Module = dynamic_cast(this->module); diff --git a/src/scanner.cpp b/src/scanner.cpp index 318818e..a290100 100644 --- a/src/scanner.cpp +++ b/src/scanner.cpp @@ -11,7 +11,7 @@ struct Scanner : Via { struct YWorldQuantity; struct MapQuantity; struct XWorldQuantity; - + Scanner() : Via(), virtualModule(asset::plugin(pluginInstance, "res/original.scanner")) { virtualIO = &virtualModule; @@ -26,14 +26,14 @@ struct Scanner : Via { configParam(A_PARAM, -5.0, 5.0, 5.0, "A level"); paramQuantities[A_PARAM]->description = "Main scan out is bounded between A and B levels"; configParam(CV3AMT_PARAM, 0, 1.0, 1.0, "Y input attenuation"); - + configParam(BUTTON1_PARAM, 0.0, 1.0, 0.0, "JUMP input response"); configParam(BUTTON2_PARAM, 0.0, 1.0, 0.0, "Y scan world"); configParam(BUTTON3_PARAM, 0.0, 1.0, 0.0, "Map creation function"); configParam(BUTTON4_PARAM, 0.0, 1.0, 0.0, "X scan world"); configParam(BUTTON5_PARAM, 0.0, 1.0, 0.0, "Y scan world"); configParam(BUTTON6_PARAM, 0.0, 1.0, 0.0, "X scan world"); - + configParam(TRIGBUTTON_PARAM, 0.0, 5.0, 0.0, "Unused"); configInput(A_INPUT, "A"); @@ -59,7 +59,7 @@ struct Scanner : Via { presetData[3] = virtualModule.scannerUI.stockPreset4; presetData[4] = virtualModule.scannerUI.stockPreset5; presetData[5] = virtualModule.scannerUI.stockPreset6; - + } void step() override; @@ -69,7 +69,7 @@ struct Scanner : Via { float sampleRate = APP->engine->getSampleRate(); ledDecay = 16.0/sampleRate; - + if (sampleRate == 44100.0) { divideAmount = 1; } else if (sampleRate == 48000.0) { @@ -91,7 +91,7 @@ struct Scanner : Via { } else if (sampleRate == 768000.0) { divideAmount = 16; } - + } json_t *dataToJson() override { @@ -105,7 +105,7 @@ struct Scanner : Via { } int32_t testMode; - + void dataFromJson(json_t *rootJ) override { json_t *modesJ = json_object_get(rootJ, "scanner_modes"); @@ -122,7 +122,7 @@ struct Scanner : Via { } } std::string tablePath = asset::plugin(pluginInstance, "res/original.scanner"); - + }; void Scanner::step() { @@ -147,7 +147,7 @@ void Scanner::step() { updateAudioRate(); } - + } struct ScannerWidget : ModuleWidget { @@ -173,14 +173,14 @@ struct ScannerWidget : ModuleWidget { addParam(createParam(Vec(128.04 + .753, 30.90), module, Scanner::CV2AMT_PARAM)); addParam(createParam(Vec(128.04 + .753, 100.4), module, Scanner::A_PARAM)); addParam(createParam(Vec(128.04 + .753, 169.89), module, Scanner::CV3AMT_PARAM)); - + addParam(createParam(Vec(21 + .753, 105), module, Scanner::BUTTON4_PARAM)); addParam(createParam(Vec(47 + .753, 77.5), module, Scanner::BUTTON2_PARAM)); addParam(createParam(Vec(75 + .753, 105), module, Scanner::BUTTON6_PARAM)); addParam(createParam(Vec(7 + .753, 142), module, Scanner::BUTTON1_PARAM)); addParam(createParam(Vec(47 + .753, 131.5), module, Scanner::BUTTON5_PARAM)); addParam(createParam(Vec(89 + .753, 142), module, Scanner::BUTTON3_PARAM)); - + addParam(createParam(Vec(132.7 + .753, 320), module, Scanner::TRIGBUTTON_PARAM)); @@ -247,18 +247,28 @@ struct ScannerWidget : ModuleWidget { menu->addChild(stockPresets); struct TableSetHandler : MenuItem { - Scanner *module; + Scanner *module; void onAction(const event::Action &e) override { - - char* pathC = osdialog_file(OSDIALOG_OPEN, NULL, NULL, NULL); - if (!pathC) { - // Fail silently - return; - } - DEFER({ - std::free(pathC); - }); - +#ifdef USING_CARDINAL_NOT_RACK + Scanner* module = this->module; + async_dialog_filebrowser(false, NULL, NULL, "Load Wavetable", [module](char* pathC) { + pathSelected(module, pathC); + }); +#else + char* pathC = osdialog_file(OSDIALOG_OPEN, NULL, NULL, NULL); + pathSelected(module, pathC); +#endif + } + + static void pathSelected(Scanner* module, char* pathC) { + if (!pathC) { + // Fail silently + return; + } + DEFER({ + std::free(pathC); + }); + module->virtualModule.readTableSetFromFile(pathC); module->tablePath = pathC; } @@ -269,7 +279,7 @@ struct ScannerWidget : ModuleWidget { tableSetFile->module = module; menu->addChild(tableSetFile); } - + }; Model *modelScanner = createModel("SCANNER"); @@ -285,7 +295,7 @@ struct Scanner::JumpQuantity : ViaButtonQuantity<2> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Scanner * scannerModule = dynamic_cast(this->module); @@ -326,7 +336,7 @@ struct Scanner::YWorldQuantity : ViaButtonQuantity<8> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Scanner * scannerModule = dynamic_cast(this->module); @@ -360,7 +370,7 @@ struct Scanner::MapQuantity : ViaButtonQuantity<8> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Scanner * scannerModule = dynamic_cast(this->module); @@ -401,7 +411,7 @@ struct Scanner::XWorldQuantity : ViaButtonQuantity<8> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Scanner * scannerModule = dynamic_cast(this->module); diff --git a/src/sync.cpp b/src/sync.cpp index dd74fc7..bbf8f23 100644 --- a/src/sync.cpp +++ b/src/sync.cpp @@ -33,7 +33,7 @@ struct Sync : Via { configParam(A_PARAM, -5.0, 5.0, -5.0, "Manual A input"); paramQuantities[A_PARAM]->description = "Main output is bounded between A and B levels"; configParam(CV3AMT_PARAM, 0, 1.0, 1.0, "Wave shape CV amount"); - + configParam(BUTTON1_PARAM, 0.0, 1.0, 0.0, "S+H at A and B inputs"); configParam(BUTTON2_PARAM, 0.0, 1.0, 0.0, "Ratio grid"); configParam(BUTTON3_PARAM, 0.0, 1.0, 0.0, "MOD CV destination"); @@ -41,7 +41,7 @@ struct Sync : Via { configParam(BUTTON5_PARAM, 0.0, 1.0, 0.0, "Group"); paramQuantities[BUTTON5_PARAM]->description = "Purpose specific set of scales and waves"; configParam(BUTTON6_PARAM, 0.0, 1.0, 0.0, "Wavetable"); - + configParam(TRIGBUTTON_PARAM, 0.0, 5.0, 0.0, "Tap tempo"); configInput(A_INPUT, "A"); @@ -109,13 +109,13 @@ struct Sync : Via { json_t *dataToJson() override { json_t *rootJ = json_object(); - + json_object_set_new(rootJ, "sync_modes", json_integer(virtualModule.syncUI.modeStateBuffer)); json_object_set_new(rootJ, "table_file", json_string(tablePath.c_str())); - + return rootJ; } - + void dataFromJson(json_t *rootJ) override { json_t *modesJ = json_object_get(rootJ, "sync_modes"); @@ -166,9 +166,9 @@ struct Sync : Via { virtualModule.advanceMeasurementTimer(); } - + } - + }; struct Sync_Widget : ModuleWidget { @@ -193,14 +193,14 @@ struct Sync_Widget : ModuleWidget { addParam(createParam(Vec(128.04 + .753, 30.90), module, Sync::CV2AMT_PARAM)); addParam(createParam(Vec(128.04 + .753, 100.4), module, Sync::A_PARAM)); addParam(createParam(Vec(128.04 + .753, 169.89), module, Sync::CV3AMT_PARAM)); - + addParam(createParam(Vec(7 + .753, 82), module, Sync::BUTTON1_PARAM)); addParam(createParam(Vec(48 + .753, 79.5), module, Sync::BUTTON2_PARAM)); addParam(createParam(Vec(88.5 + .753, 82), module, Sync::BUTTON3_PARAM)); addParam(createParam(Vec(7 + .753, 136.5), module, Sync::BUTTON4_PARAM)); addParam(createParam(Vec(48 + .753, 135.5), module, Sync::BUTTON5_PARAM)); addParam(createParam(Vec(88.5 + .753, 136.5), module, Sync::BUTTON6_PARAM)); - + addParam(createParam(Vec(132.7 + .753, 320), module, Sync::TRIGBUTTON_PARAM)); addInput(createInput(Vec(8.07 + 1.053, 241.12), module, Sync::A_INPUT)); @@ -320,7 +320,7 @@ struct Sync_Widget : ModuleWidget { aux4Item->mode = i; menu->addChild(aux4Item); } - + struct PresetRecallItem : MenuItem { Sync *module; int preset; @@ -359,18 +359,28 @@ struct Sync_Widget : ModuleWidget { menu->addChild(stockPresets); struct TableSetHandler : MenuItem { - Sync *module; + Sync *module; void onAction(const event::Action &e) override { - - char* pathC = osdialog_file(OSDIALOG_OPEN, NULL, NULL, NULL); - if (!pathC) { - // Fail silently - return; - } - DEFER({ - std::free(pathC); - }); - +#ifdef USING_CARDINAL_NOT_RACK + Sync* module = this->module; + async_dialog_filebrowser(false, NULL, NULL, "Load Wavetable", [module](char* pathC) { + pathSelected(module, pathC); + }); +#else + char* pathC = osdialog_file(OSDIALOG_OPEN, NULL, NULL, NULL); + pathSelected(module, pathC); +#endif + } + + static void pathSelected(Sync* module, char* pathC) { + if (!pathC) { + // Fail silently + return; + } + DEFER({ + std::free(pathC); + }); + module->virtualModule.readTableSetFromFile(pathC); module->tablePath = pathC; } @@ -391,7 +401,7 @@ Model *modelSync = createModel("SYNC"); // Tooltip definitions struct Sync::RatioXQuantity : ViaKnobQuantity { - + float translateParameter(float value) override { Sync * syncModule = dynamic_cast(this->module); @@ -428,8 +438,8 @@ struct Sync::RatioXQuantity : ViaKnobQuantity { // } - return xIndex; - + return xIndex; + } float translateInput(float userInput) override { @@ -442,7 +452,7 @@ struct Sync::RatioXQuantity : ViaKnobQuantity { }; struct Sync::RatioYQuantity : ViaKnobQuantity { - + float translateParameter(float value) override { Sync * syncModule = dynamic_cast(this->module); @@ -478,8 +488,8 @@ struct Sync::RatioYQuantity : ViaKnobQuantity { // description = "Frequency ratio: " + std::to_string(numerator) + "/" + std::to_string(denominator) + "\n"; // } - return yIndex; - + return yIndex; + } float translateInput(float userInput) override { @@ -492,13 +502,13 @@ struct Sync::RatioYQuantity : ViaKnobQuantity { }; struct Sync::WaveshapeQuantity : ViaKnobQuantity { - + float translateParameter(float value) override { Sync * syncModule = dynamic_cast(this->module); - return syncModule->virtualModule.syncWavetable.tableSize * value/4095.0; - + return syncModule->virtualModule.syncWavetable.tableSize * value/4095.0; + } float translateInput(float userInput) override { @@ -529,7 +539,7 @@ struct Sync::SHButtonQuantity : ViaButtonQuantity<3> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Sync * syncModule = dynamic_cast(this->module); @@ -562,7 +572,7 @@ struct Sync::ScaleButtonQuantity : ViaComplexButtonQuantity { modes = buttonModes[0]; numModes = 4; } - + int getModeEnumeration(void) override { Sync * syncModule = dynamic_cast(this->module); @@ -602,7 +612,7 @@ struct Sync::ModButtonQuantity : ViaButtonQuantity<3> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Sync * syncModule = dynamic_cast(this->module); @@ -632,7 +642,7 @@ struct Sync::SyncButtonQuantity : ViaButtonQuantity<4> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Sync * syncModule = dynamic_cast(this->module); @@ -667,7 +677,7 @@ struct Sync::GroupButtonQuantity : ViaButtonQuantity<4> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Sync * syncModule = dynamic_cast(this->module); @@ -705,7 +715,7 @@ struct Sync::TableButtonQuantity : ViaComplexButtonQuantity { modes = buttonModes[0]; numModes = 4; } - + int getModeEnumeration(void) override { Sync * syncModule = dynamic_cast(this->module); diff --git a/src/sync3.cpp b/src/sync3.cpp index cef5779..4ec1e52 100644 --- a/src/sync3.cpp +++ b/src/sync3.cpp @@ -17,7 +17,7 @@ struct Sync3 : Via { struct IIButtonQuantity; struct CVButtonQuantity; struct IIIButtonQuantity; - + Sync3() : Via(), virtualModule(asset::plugin(pluginInstance, "res/original.sync3")) { virtualIO = &virtualModule; @@ -30,14 +30,14 @@ struct Sync3 : Via { configParam(CV2AMT_PARAM, 0, 1.0, 1.0, "II CV scale"); configParam(A_PARAM, -5.0, 5.0, 5.0, "Oscillator II level", "V"); configParam(CV3AMT_PARAM, 0, 1.0, 1.0, "III CV scale"); - + configParam(BUTTON1_PARAM, 0.0, 1.0, 0.0, "Oscillator I shape"); configParam(BUTTON2_PARAM, 0.0, 1.0, 0.0, "Ratio set"); configParam(BUTTON3_PARAM, 0.0, 1.0, 0.0, "Oscillator II shape"); configParam(BUTTON4_PARAM, 0.0, 1.0, 0.0, "CV mapping"); configParam(BUTTON5_PARAM, 0.0, 1.0, 0.0, "Ratio set"); configParam(BUTTON6_PARAM, 0.0, 1.0, 0.0, "Oscillator III shape"); - + configParam(TRIGBUTTON_PARAM, 0.0, 5.0, 0.0, "Tap tempo"); configInput(A_INPUT, "Oscillator II level"); @@ -86,7 +86,7 @@ struct Sync3 : Via { } else if (sampleRate == 768000.0) { divideAmount = 16; } - + } json_t *dataToJson() override { @@ -95,10 +95,10 @@ struct Sync3 : Via { json_object_set_new(rootJ, "osc_modes", json_integer(virtualModule.sync3UI.modeStateBuffer)); json_object_set_new(rootJ, "scale_file", json_string(scalePath.c_str())); - + return rootJ; } - + void dataFromJson(json_t *rootJ) override { json_t *modesJ = json_object_get(rootJ, "osc_modes"); @@ -194,7 +194,7 @@ struct Sync3 : Via { float dac3Output = blampDelay3[0]; blampDelay3[0] = blampDelay3[1]; blampDelay3[1] = dac3Sample; - dac3Sample = dac3Output + dac3PolyBlamp.process(); + dac3Sample = dac3Output + dac3PolyBlamp.process(); } @@ -242,7 +242,7 @@ struct Sync3 : Via { float dac1Output = blampDelay1[0]; blampDelay1[0] = blampDelay1[1]; blampDelay1[1] = dac1Sample; - dac1Sample = dac1Output + dac1PolyBlamp.process(); + dac1Sample = dac1Output + dac1PolyBlamp.process(); } @@ -290,7 +290,7 @@ struct Sync3 : Via { float dac2Output = blampDelay2[0]; blampDelay2[0] = blampDelay2[1]; blampDelay2[1] = dac2Sample; - dac2Sample = dac2Output + dac2PolyBlamp.process(); + dac2Sample = dac2Output + dac2PolyBlamp.process(); } @@ -298,7 +298,7 @@ struct Sync3 : Via { lastDac2Phase = virtualModule.phase4; lastDac3Phase = virtualModule.phase2; - + virtualIO->halfTransferCallback(); // "model" the circuit @@ -306,7 +306,7 @@ struct Sync3 : Via { float aIn = inputs[A_INPUT].isConnected() ? inputs[A_INPUT].getVoltage() : params[A_PARAM].getValue(); float bIn = inputs[B_INPUT].isConnected() ? inputs[B_INPUT].getVoltage() : 5.0; bIn *= params[B_PARAM].getValue(); - + // sample and holds // get a new sample on the rising edge at the sh control output if (virtualIO->shAState > shALast) { @@ -325,7 +325,7 @@ struct Sync3 : Via { // VCA/mixing stage // normalize 12 bits to 0-1 - outputs[MAIN_OUTPUT].setVoltage(bIn*(dac2Sample/4095.0) + aIn*(dac1Sample/4095.0)); + outputs[MAIN_OUTPUT].setVoltage(bIn*(dac2Sample/4095.0) + aIn*(dac1Sample/4095.0)); outputs[AUX_DAC_OUTPUT].setVoltage((dac3Sample/4095.0 - .5) * -10.666666666); outputs[LOGICA_OUTPUT].setVoltage(virtualIO->logicAState * 5.0); outputs[AUX_LOGIC_OUTPUT].setVoltage(virtualIO->auxLogicState * 5.0); @@ -335,7 +335,7 @@ struct Sync3 : Via { clockDivider = 0; } - + }; void Sync3::process(const ProcessArgs &args) { @@ -365,7 +365,7 @@ void Sync3::process(const ProcessArgs &args) { virtualModule.advanceTimer2(); } - + } struct Sync3Widget : ModuleWidget { @@ -390,14 +390,14 @@ struct Sync3Widget : ModuleWidget { addParam(createParam(Vec(128.04 + .753, 30.90), module, Sync3::CV2AMT_PARAM)); addParam(createParam(Vec(128.04 + .753, 100.4), module, Sync3::A_PARAM)); addParam(createParam(Vec(128.04 + .753, 169.89), module, Sync3::CV3AMT_PARAM)); - + addParam(createParam(Vec(10.5 + .753, 83), module, Sync3::BUTTON1_PARAM)); addParam(createParam(Vec(47 + .753, 90), module, Sync3::BUTTON2_PARAM)); addParam(createParam(Vec(83 + .753, 83), module, Sync3::BUTTON3_PARAM)); addParam(createParam(Vec(10.5 + .753, 133), module, Sync3::BUTTON4_PARAM)); addParam(createParam(Vec(47 + .753, 129.5), module, Sync3::BUTTON5_PARAM)); addParam(createParam(Vec(83 + .753, 133), module, Sync3::BUTTON6_PARAM)); - + addParam(createParam(Vec(132.7 + .753, 320), module, Sync3::TRIGBUTTON_PARAM)); addInput(createInput(Vec(8.07 + 1.053, 241.12), module, Sync3::A_INPUT)); @@ -444,18 +444,28 @@ struct Sync3Widget : ModuleWidget { }; struct ScaleSetHandler : MenuItem { - Sync3 *module; + Sync3 *module; void onAction(const event::Action &e) override { - - char* pathC = osdialog_file(OSDIALOG_OPEN, NULL, NULL, NULL); - if (!pathC) { - // Fail silently - return; - } - DEFER({ - std::free(pathC); - }); - +#ifdef USING_CARDINAL_NOT_RACK + Sync3* module = this->module; + async_dialog_filebrowser(false, NULL, NULL, "Load Scale", [module](char* pathC) { + pathSelected(module, pathC); + }); +#else + char* pathC = osdialog_file(OSDIALOG_OPEN, NULL, NULL, NULL); + pathSelected(module, pathC); +#endif + } + + static void pathSelected(Sync3* module, char* pathC) { + if (!pathC) { + // Fail silently + return; + } + DEFER({ + std::free(pathC); + }); + module->virtualModule.readScalesFromFile(pathC); module->scalePath = pathC; } @@ -477,7 +487,7 @@ struct Sync3Widget : ModuleWidget { menu->addChild(menuItem); } - + }; Model *modelSync3 = createModel("SYNC3"); @@ -490,7 +500,7 @@ struct Sync3::IRatioQuantity : ViaKnobQuantity { Sync3 * sync3Module = dynamic_cast(this->module); - return string::f("%d", sync3Module->virtualModule.numerator1Alt) + "/" + + return string::f("%d", sync3Module->virtualModule.numerator1Alt) + "/" + string::f("%d", sync3Module->virtualModule.denominator1Select); } @@ -503,7 +513,7 @@ struct Sync3::IIRatioQuantity : ViaKnobQuantity { Sync3 * sync3Module = dynamic_cast(this->module); - return string::f("%i", sync3Module->virtualModule.numerator2Alt) + "/" + + return string::f("%i", sync3Module->virtualModule.numerator2Alt) + "/" + string::f("%i", sync3Module->virtualModule.denominator2Select); } @@ -515,7 +525,7 @@ struct Sync3::IIIRatioQuantity : ViaKnobQuantity { Sync3 * sync3Module = dynamic_cast(this->module); - return string::f("%i", sync3Module->virtualModule.numerator3Alt) + "/" + + return string::f("%i", sync3Module->virtualModule.numerator3Alt) + "/" + string::f("%i", sync3Module->virtualModule.denominator3Select); } @@ -530,7 +540,7 @@ struct Sync3::IButtonQuantity : ViaButtonQuantity<3> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Sync3 * sync3Module = dynamic_cast(this->module); @@ -560,7 +570,7 @@ struct Sync3::RatioButtonQuantity : ViaButtonQuantity<8> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Sync3 * sync3Module = dynamic_cast(this->module); @@ -590,7 +600,7 @@ struct Sync3::IIButtonQuantity : ViaButtonQuantity<3> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Sync3 * sync3Module = dynamic_cast(this->module); @@ -620,7 +630,7 @@ struct Sync3::CVButtonQuantity : ViaButtonQuantity<2> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Sync3 * sync3Module = dynamic_cast(this->module); @@ -650,7 +660,7 @@ struct Sync3::IIIButtonQuantity : ViaButtonQuantity<3> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Sync3 * sync3Module = dynamic_cast(this->module); diff --git a/src/sync3xl.cpp b/src/sync3xl.cpp index bc2fa94..b187f2e 100644 --- a/src/sync3xl.cpp +++ b/src/sync3xl.cpp @@ -7,7 +7,7 @@ #define SYNC3_OVERSAMPLE_QUALITY 6 struct Sync3XL : Via { - + struct IRatioQuantity; struct IIRatioQuantity; struct IIIRatioQuantity; @@ -28,14 +28,14 @@ struct Sync3XL : Via { configParam(CV1AMT_PARAM, -1.f, 1.0, 1.0, "I CV Scale"); configParam(CV2AMT_PARAM, -1.f, 1.0, 1.0, "II CV Scale"); configParam(CV3AMT_PARAM, -1.f, 1.0, 1.0, "III CV Scale"); - + configParam(BUTTON1_PARAM, 0.0, 1.0, 0.0, "Oscillator I Shape"); configParam(BUTTON2_PARAM, 0.0, 1.0, 0.0, "Ratio Set"); configParam(BUTTON3_PARAM, 0.0, 1.0, 0.0, "Oscillator II Shape"); configParam(BUTTON4_PARAM, 0.0, 1.0, 0.0, "CV Mapping"); configParam(BUTTON5_PARAM, 0.0, 1.0, 0.0, "Ratio Set"); configParam(BUTTON6_PARAM, 0.0, 1.0, 0.0, "Oscillator III Shape"); - + configParam(RES1_PARAM, -5.f, 5.f, 0.f, "I resonance"); configParam(FREQ1_PARAM, -5.f, 5.f, 0.f, "I frequency"); configParam(MODE1_PARAM, -5.f, 5.f, 0.f, "I filter type"); @@ -72,8 +72,8 @@ struct Sync3XL : Via { onSampleRateChange(); virtualModule.displayRatio(); - rightExpander.producerMessage = new Sync3XLExpand; - rightExpander.consumerMessage = new Sync3XLExpand; + rightExpander.producerMessage = new Sync3XLExpand; + rightExpander.consumerMessage = new Sync3XLExpand; } @@ -178,7 +178,7 @@ struct Sync3XL : Via { } else if (sampleRate == 768000.0) { divideAmount = 16; } - + } json_t *dataToJson() override { @@ -187,10 +187,10 @@ struct Sync3XL : Via { json_object_set_new(rootJ, "osc_modes", json_integer(virtualModule.sync3UI.modeStateBuffer)); json_object_set_new(rootJ, "scale_file", json_string(scalePath.c_str())); - + return rootJ; } - + void dataFromJson(json_t *rootJ) override { json_t *modesJ = json_object_get(rootJ, "osc_modes"); @@ -270,7 +270,7 @@ struct Sync3XL : Via { } else if (!trigState && lastTrigState) { virtualIO->mainFallingEdgeCallback(); } - lastTrigState = trigState; + lastTrigState = trigState; lastLogicIn = thisLogicIn; @@ -293,11 +293,11 @@ struct Sync3XL : Via { } float_4 result = dacDecimator.process(dacDecimatorBuffer); - + float dac1Sample = result[0]; float dac2Sample = result[1]; float dac3Sample = result[2]; - + virtualIO->halfTransferCallback(); processOutputs(dac1Sample, dac2Sample, dac3Sample); @@ -382,7 +382,7 @@ struct Sync3XL : Via { float dac3Output = blampDelay3[0]; blampDelay3[0] = blampDelay3[1]; blampDelay3[1] = dac3Sample; - dac3Sample = dac3Output + dac3PolyBlamp.process(); + dac3Sample = dac3Output + dac3PolyBlamp.process(); } @@ -430,7 +430,7 @@ struct Sync3XL : Via { float dac1Output = blampDelay1[0]; blampDelay1[0] = blampDelay1[1]; blampDelay1[1] = dac1Sample; - dac1Sample = dac1Output + dac1PolyBlamp.process(); + dac1Sample = dac1Output + dac1PolyBlamp.process(); } @@ -478,7 +478,7 @@ struct Sync3XL : Via { float dac2Output = blampDelay2[0]; blampDelay2[0] = blampDelay2[1]; blampDelay2[1] = dac2Sample; - dac2Sample = dac2Output + dac2PolyBlamp.process(); + dac2Sample = dac2Output + dac2PolyBlamp.process(); } @@ -486,7 +486,7 @@ struct Sync3XL : Via { lastDac2Phase = virtualModule.phase4; lastDac3Phase = virtualModule.phase2; - + virtualIO->halfTransferCallback(); processOutputs(dac1Sample, dac2Sample, dac3Sample); @@ -496,11 +496,11 @@ struct Sync3XL : Via { clockDivider = 0; } - + ZDFSVF filters[3]; bool subaudioFilter = 0; - + float filterVoltageToCoeff(float voltage) { float ts = APP->engine->getSampleTime(); @@ -522,16 +522,16 @@ struct Sync3XL : Via { return res; } - float processFilterOuts(float modeVoltage, int filterIndex) { + float processFilterOuts(float modeVoltage, int filterIndex) { modeVoltage /= 5.f; float lpScale = clamp(-modeVoltage, 0.f, 1.f); float bpScale = 1.f - clamp(abs(modeVoltage), 0.f, 1.f); float hpScale = clamp(modeVoltage, 0.f, 1.f); - return filters[filterIndex].lpOut * lpScale + filters[filterIndex].bpOut * bpScale + filters[filterIndex].hpOut * hpScale; + return filters[filterIndex].lpOut * lpScale + filters[filterIndex].bpOut * bpScale + filters[filterIndex].hpOut * hpScale; } - void processOutputs(float dac1, float dac2, float dac3) { - + void processOutputs(float dac1, float dac2, float dac3) { + dac1 /= 4095.f; dac1 *= 10.f; dac1 -= 5.f; @@ -593,13 +593,13 @@ struct Sync3XL : Via { rightExpander.module->leftExpander.messageFlipRequested = true; } else { outMix = (out1 + out2 + out3)/3; - } + } outputs[OUT1_OUTPUT].setVoltage(out1); outputs[OUT2_OUTPUT].setVoltage(out2); outputs[OUT3_OUTPUT].setVoltage(out3); outputs[OUTMIX_OUTPUT].setVoltage(outMix); - + logicOut1 = virtualIO->logicAState; logicOut2 = (virtualIO->redLevelOut == 4095); logicOut3 = (virtualIO->blueLevelOut == 4095); @@ -612,7 +612,7 @@ struct Sync3XL : Via { bool expanderAttached = false; - void onExpanderChange(const ExpanderChangeEvent& e) override { + void onExpanderChange(const ExpanderChangeEvent& e) override { if (rightExpander.module && (rightExpander.module->model == modelSync3XLLevels)) { expanderAttached = true; } else { @@ -623,7 +623,7 @@ struct Sync3XL : Via { ~Sync3XL() { free(rightExpander.producerMessage); free(rightExpander.consumerMessage); - } + } }; void Sync3XL::process(const ProcessArgs &args) { @@ -650,11 +650,11 @@ void Sync3XL::process(const ProcessArgs &args) { virtualModule.advanceMeasurementTimer(); virtualModule.advanceTimer1(); virtualModule.advanceTimer2(); - + clockDivider = 0; } - + } @@ -752,18 +752,28 @@ struct Sync3XLWidget : ModuleWidget { }; struct ScaleSetHandler : MenuItem { - Sync3XL *module; + Sync3XL *module; void onAction(const event::Action &e) override { - - char* pathC = osdialog_file(OSDIALOG_OPEN, NULL, NULL, NULL); - if (!pathC) { - // Fail silently - return; - } - DEFER({ - std::free(pathC); - }); - +#ifdef USING_CARDINAL_NOT_RACK + Sync3XL* module = this->module; + async_dialog_filebrowser(false, NULL, NULL, "Load Scale", [module](char* pathC) { + pathSelected(module, pathC); + }); +#else + char* pathC = osdialog_file(OSDIALOG_OPEN, NULL, NULL, NULL); + pathSelected(module, pathC); +#endif + } + + static void pathSelected(Sync3XL* module, char* pathC) { + if (!pathC) { + // Fail silently + return; + } + DEFER({ + std::free(pathC); + }); + module->virtualModule.readScalesFromFile(pathC); module->scalePath = pathC; } @@ -799,7 +809,7 @@ struct Sync3XL::IRatioQuantity : ViaKnobQuantity { Sync3XL * sync3Module = dynamic_cast(this->module); - return string::f("%d", sync3Module->virtualModule.numerator1Alt) + "/" + + return string::f("%d", sync3Module->virtualModule.numerator1Alt) + "/" + string::f("%d", sync3Module->virtualModule.denominator1Select); } @@ -812,7 +822,7 @@ struct Sync3XL::IIRatioQuantity : ViaKnobQuantity { Sync3XL * sync3Module = dynamic_cast(this->module); - return string::f("%i", sync3Module->virtualModule.numerator2Alt) + "/" + + return string::f("%i", sync3Module->virtualModule.numerator2Alt) + "/" + string::f("%i", sync3Module->virtualModule.denominator2Select); } @@ -824,7 +834,7 @@ struct Sync3XL::IIIRatioQuantity : ViaKnobQuantity { Sync3XL * sync3Module = dynamic_cast(this->module); - return string::f("%i", sync3Module->virtualModule.numerator3Alt) + "/" + + return string::f("%i", sync3Module->virtualModule.numerator3Alt) + "/" + string::f("%i", sync3Module->virtualModule.denominator3Select); } @@ -839,7 +849,7 @@ struct Sync3XL::IButtonQuantity : ViaButtonQuantity<3> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Sync3XL * sync3Module = dynamic_cast(this->module); @@ -869,7 +879,7 @@ struct Sync3XL::RatioButtonQuantity : ViaButtonQuantity<8> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Sync3XL * sync3Module = dynamic_cast(this->module); @@ -899,7 +909,7 @@ struct Sync3XL::IIButtonQuantity : ViaButtonQuantity<3> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Sync3XL * sync3Module = dynamic_cast(this->module); @@ -929,7 +939,7 @@ struct Sync3XL::CVButtonQuantity : ViaButtonQuantity<2> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Sync3XL * sync3Module = dynamic_cast(this->module); @@ -959,7 +969,7 @@ struct Sync3XL::IIIButtonQuantity : ViaButtonQuantity<3> { modes[i] = buttonModes[i]; } } - + int getModeEnumeration(void) override { Sync3XL * sync3Module = dynamic_cast(this->module); @@ -979,4 +989,3 @@ struct Sync3XL::IIIButtonQuantity : ViaButtonQuantity<3> { } }; -