Browse Source

Implement checkbox.

faust
Stephane Letz Andrew Belt 4 years ago
parent
commit
2ac58de03b
2 changed files with 40 additions and 3 deletions
  1. +8
    -3
      examples/test1.dsp
  2. +32
    -0
      src/FaustEngine.cpp

+ 8
- 3
examples/test1.dsp View File

@@ -17,6 +17,10 @@ freq2 = hslider("freq2 [knob:4] [unit:Hz] ", 300, 200, 300, 1);


gate = button("gate [switch: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) // 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); 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) // 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, process = os.osc(freq1) * vol1,
os.sawtooth(freq2) * vol2 * gate, 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):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); (os.osc(1):swl_2_r + os.osc(1.2):swl_2_g + os.osc(1.7):swl_2_b);

+ 32
- 0
src/FaustEngine.cpp View File

@@ -45,6 +45,11 @@ struct RackUI : public GenericUI
vector<ConverterZoneControl*> fConverters; vector<ConverterZoneControl*> fConverters;
vector<updateFunction> fUpdateFunIn; vector<updateFunction> fUpdateFunIn;
vector<updateFunction> fUpdateFunOut; vector<updateFunction> fUpdateFunOut;
// For checkbox handling
struct CheckBox { float fLast = 0.0f; };
map <FAUSTFLOAT*, CheckBox> fCheckBoxes;
string fKey, fValue, fScale; string fKey, fValue, fScale;
int getIndex(const string& value) int getIndex(const string& value)
@@ -78,11 +83,37 @@ struct RackUI : public GenericUI
fUpdateFunIn.push_back([=] (ProcessBlock* block) { *zone = block->switches[index-1]; }); 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) void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{ {
addNumEntry(label, zone, init, min, max, step); addNumEntry(label, zone, init, min, max, step);
} }
void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{ {
addNumEntry(label, zone, init, min, max, step); addNumEntry(label, zone, init, min, max, step);
@@ -127,6 +158,7 @@ struct RackUI : public GenericUI
{ {
addBarGraph(zone); addBarGraph(zone);
} }
void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
{ {
addBarGraph(zone); addBarGraph(zone);


Loading…
Cancel
Save