From dad2f0c1916122f2006017356a2fbf371ce24ee5 Mon Sep 17 00:00:00 2001 From: Stephane Letz Date: Wed, 11 Nov 2020 20:39:50 +0100 Subject: [PATCH] Code cleanup. --- Faust.md | 4 ++-- src/FaustEngine.cpp | 30 ++++++++++++++++++------------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Faust.md b/Faust.md index 7c4622d..3929190 100644 --- a/Faust.md +++ b/Faust.md @@ -19,8 +19,8 @@ The 6 *switches*, *knobs* as well as the *lights* and *switchLights* can be conn - `[switchlight_red:N|switchlight_green:N|switchlight_blue:N]` (with N from 1 to 6) has to be used in a `vbargraph` or `hbargraph` to connect it to the prototype interface switchLight number N So a button or checkbox UI item can use the `[switch:N]` metadata to be associated with the corresponding GUI switch, which color can be controlled using the `switchlight_xx:N` metadata. For instance: -- `gate = button("gate [switch:1") : hbargraph("[switchlight_red:1]", 0, 1); ` can be written to describe a button which become red when pressed -- ` check = checkbox("check [switch:2]") : vbargraph("[switchlight_red:2]", 0, 1) : vbargraph("[switchlight_green:2]", 0, 1) : vbargraph("[switchlight_blue:2]", 0, 1); ` can be written to describe a checkbox which become white when checked +- `gate = button("gate [switch:1") : hbargraph("[switchlight_red:1]", 0, 1);` can be written to describe a button which become red when pressed +- `check = checkbox("check [switch:2]") : vbargraph("[switchlight_red:2]", 0, 1) : vbargraph("[switchlight_green:2]", 0, 1) : vbargraph("[switchlight_blue:2]", 0, 1);` can be written to describe a checkbox which become white when checked Other metadata: - `[scale:lin|log|exp]` metadata is implemented. diff --git a/src/FaustEngine.cpp b/src/FaustEngine.cpp index 5ee254a..bfb002a 100644 --- a/src/FaustEngine.cpp +++ b/src/FaustEngine.cpp @@ -94,8 +94,10 @@ struct RackUI : public GenericUI { } void addButton(const char* label, FAUSTFLOAT* zone) override { - int index = getIndex(fValue); - if (fKey == "switch" && (index != -1)) { + int index = getIndex(fValue); + if (index == -1) return; + + if (fKey == "switch") { fUpdateFunIn.push_back([ = ](ProcessBlock * block) { *zone = block->switches[index - 1]; }); @@ -105,7 +107,9 @@ struct RackUI : public GenericUI { void addCheckButton(const char* label, FAUSTFLOAT* zone) override { int index = getIndex(fValue); - if (fKey == "switch" && (index != -1)) { + if (index == -1) return; + + if (fKey == "switch") { // Add a checkbox fCheckBoxes[zone] = CheckBox(); // Update function @@ -133,7 +137,7 @@ struct RackUI : public GenericUI { void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) override { int index = getIndex(fValue); - if (fKey == "knob" && (index != -1)) { + if (fKey == "knob") { ConverterZoneControl* converter; if (fScale == "log") { converter = new ConverterZoneControl(zone, new LogValueConverter(0., 1., min, max)); @@ -154,33 +158,35 @@ struct RackUI : public GenericUI { } void addBarGraph(FAUSTFLOAT* zone) { - int index = getIndex(fValue); - if ((fKey == "light_red") && (index != -1)) { + int index = getIndex(fValue); + if (index == -1) return; + + if ((fKey == "light_red")) { fUpdateFunOut.push_back([ = ](ProcessBlock * block) { block->lights[index - 1][0] = *zone; }); } - else if ((fKey == "light_green") && (index != -1)) { + else if ((fKey == "light_green")) { fUpdateFunOut.push_back([ = ](ProcessBlock * block) { block->lights[index - 1][1] = *zone; }); } - else if ((fKey == "light_blue") && (index != -1)) { + else if ((fKey == "light_blue")) { fUpdateFunOut.push_back([ = ](ProcessBlock * block) { block->lights[index - 1][2] = *zone; }); } - else if ((fKey == "switchlight_red") && (index != -1)) { + else if ((fKey == "switchlight_red")) { fUpdateFunOut.push_back([ = ](ProcessBlock * block) { block->switchLights[index - 1][0] = *zone; }); } - else if ((fKey == "switchlight_green") && (index != -1)) { + else if ((fKey == "switchlight_green")) { fUpdateFunOut.push_back([ = ](ProcessBlock * block) { block->switchLights[index - 1][1] = *zone; }); } - else if ((fKey == "switchlight_blue") && (index != -1)) { + else if ((fKey == "switchlight_blue")) { fUpdateFunOut.push_back([ = ](ProcessBlock * block) { block->switchLights[index - 1][2] = *zone; }); @@ -212,7 +218,7 @@ struct RackUI : public GenericUI { } }; -// Faust engine using libfaust/LLVM +// Faust engine using libfaust + LLVM or Interp backends class FaustEngine : public ScriptEngine { public: