Browse Source

Code cleanup.

faust
Stephane Letz 4 years ago
parent
commit
dad2f0c191
2 changed files with 20 additions and 14 deletions
  1. +2
    -2
      Faust.md
  2. +18
    -12
      src/FaustEngine.cpp

+ 2
- 2
Faust.md View File

@@ -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.


+ 18
- 12
src/FaustEngine.cpp View File

@@ -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:


Loading…
Cancel
Save