diff --git a/FaustCode/owl.cpp b/FaustCode/owl.cpp index 5919c24d..eea79b5f 100644 --- a/FaustCode/owl.cpp +++ b/FaustCode/owl.cpp @@ -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 @@ -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 @@ -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) {