Skip to content

Commit

Permalink
Merge pull request #88 from antisvin/feature/faust-checkbox
Browse files Browse the repository at this point in the history
FAUST checkbox widget support  - same as button, but toggled
  • Loading branch information
pingdynasty authored Mar 3, 2021
2 parents b71d248 + 455982b commit 60689ec
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion FaustCode/owl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,24 @@ class OwlButton : public OwlParameterBase {
}
};

class OwlCheckbox : public OwlParameterBase {
protected:
PatchButtonId fButton; // OWL button id : PUSHBUTTON, ...
bool wasHigh = false; // Flag for edge detection
bool state = false; // Current state
public:
OwlCheckbox(Patch* pp, PatchButtonId button, FAUSTFLOAT* z, const char* l)
: OwlParameterBase(pp, z, false)
, fButton(button) {}
void update() {
bool isHigh = fPatch->isButtonPressed(fButton);
state ^= isHigh && !wasHigh;
wasHigh = isHigh;
fPatch->setButton(fButton, state, 0);
*fZone = state;
}
};

/**************************************************************************************
*
* OwlUI : Faust User Interface builder. Passed to buildUserInterface OwlU
Expand Down Expand Up @@ -434,6 +452,21 @@ class OwlUI : public UI {
fButton = NO_BUTTON; // clear current button ID
}

void addOwlCheckbox(const char* label, FAUSTFLOAT* zone) {
if (fParameterIndex < MAXOWLPARAMETERS) {
if (meta.midiOn && strcasecmp(label, "gate") == 0) {
fParameterTable[fParameterIndex++] =
new OwlVariable(fPatch, &fGate, zone, label, 0.0f, 0.0f, 1.0f);
}
else if (fButton != NO_BUTTON) {
fParameterTable[fParameterIndex++] =
new OwlCheckbox(fPatch, fButton, zone, label);
}
}
fParameter = NO_PARAMETER;
fButton = NO_BUTTON; // clear current button ID
}

// we dont want to create a widget but we clear the current parameter ID just in case
void skip() {
fParameter = NO_PARAMETER; // clear current parameter ID
Expand Down Expand Up @@ -483,7 +516,7 @@ class OwlUI : public UI {
addOwlButton(label, zone);
}
virtual void addCheckButton(const char* label, FAUSTFLOAT* zone) {
addOwlButton(label, zone);
addOwlCheckbox(label, zone);
}
virtual void addVerticalSlider(const char* label, FAUSTFLOAT* zone,
FAUSTFLOAT init, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step) {
Expand Down

0 comments on commit 60689ec

Please sign in to comment.