diff --git a/examples/test1.dsp b/examples/test1.dsp index cf19d1a..04c8599 100644 --- a/examples/test1.dsp +++ b/examples/test1.dsp @@ -17,6 +17,10 @@ freq2 = hslider("freq2 [knob:4] [unit:Hz] ", 300, 200, 300, 1); gate = button("gate [switch:1]"); +// Checkbox can be used, the switch button will go be white when checked + +check = checkbox("check [switch:2]"); + // Using bargraph to control lights ([light_red|green|blue:::N] metadata with :N from 1 to 6, to control 3 colors) light_1_r = vbargraph("[light_red:1]", 0, 1); @@ -25,11 +29,12 @@ light_1_b = vbargraph("[light_blue:1]", 0, 1); // Using bargraph to control switchlights ([switchlight_red|green|blue:::N] metadata with :N from 1 to 6, to control 3 colors) -swl_2_r = vbargraph("[switchlight_red:2]", 0, 1); -swl_2_g = vbargraph("[switchlight_green:2]", 0, 1); -swl_2_b = vbargraph("[switchlight_blue:2]", 0, 1); +swl_2_r = vbargraph("[switchlight_red:3]", 0, 1); +swl_2_g = vbargraph("[switchlight_green:3]", 0, 1); +swl_2_b = vbargraph("[switchlight_blue:3]", 0, 1); process = os.osc(freq1) * vol1, os.sawtooth(freq2) * vol2 * gate, + os.square(freq2) * vol2 * check, (os.osc(1):light_1_r + os.osc(1.4):light_1_g + os.osc(1.7):light_1_b), (os.osc(1):swl_2_r + os.osc(1.2):swl_2_g + os.osc(1.7):swl_2_b); diff --git a/src/FaustEngine.cpp b/src/FaustEngine.cpp index 9961450..3a09e7e 100644 --- a/src/FaustEngine.cpp +++ b/src/FaustEngine.cpp @@ -45,6 +45,11 @@ struct RackUI : public GenericUI vector fConverters; vector fUpdateFunIn; vector fUpdateFunOut; + + // For checkbox handling + struct CheckBox { float fLast = 0.0f; }; + map fCheckBoxes; + string fKey, fValue, fScale; int getIndex(const string& value) @@ -78,11 +83,37 @@ struct RackUI : public GenericUI fUpdateFunIn.push_back([=] (ProcessBlock* block) { *zone = block->switches[index-1]; }); } } + + void addCheckButton(const char* label, FAUSTFLOAT* zone) + { + int index = getIndex(fValue); + if (fKey == "switch" && (index != -1)) { + // Add a checkbox + fCheckBoxes[zone] = CheckBox(); + // Update function + fUpdateFunIn.push_back([=] (ProcessBlock* block) + { + float state = block->switches[index-1]; + // Detect upfront + if (state == 1.0 && (state != fCheckBoxes[zone].fLast)) { + // Swich button state + *zone = !*zone; + // And set the color + block->switchLights[index-1][0] = *zone; + block->switchLights[index-1][1] = *zone; + block->switchLights[index-1][2] = *zone; + } + // Always keep previous button state + fCheckBoxes[zone].fLast = state; + }); + } + } void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) { addNumEntry(label, zone, init, min, max, step); } + void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) { addNumEntry(label, zone, init, min, max, step); @@ -127,6 +158,7 @@ struct RackUI : public GenericUI { addBarGraph(zone); } + void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) { addBarGraph(zone);