@@ -344,6 +344,31 @@ class OwlButton : public OwlParameterBase {
344344 }
345345};
346346
347+ class OwlCheckbox : public OwlParameterBase {
348+ protected:
349+ PatchButtonId fButton ; // OWL button id : PUSHBUTTON, ...
350+ bool wasHigh = false ; // Flag for edge detection
351+ bool state = false ; // Current state
352+ public:
353+ OwlCheckbox (Patch* pp, PatchButtonId button, FAUSTFLOAT* z, const char * l)
354+ : OwlParameterBase(pp, z, false )
355+ , fButton (button) {}
356+ void update () {
357+ bool isHigh = fPatch ->isButtonPressed (fButton );
358+ if (isHigh && !wasHigh) {
359+ // Rising edge detected
360+ state = !state;
361+ wasHigh = true ;
362+ }
363+ else if (!isHigh && wasHigh) {
364+ // Falling edge detected
365+ wasHigh = false ;
366+ }
367+ fPatch ->setButton (fButton , state, 0 );
368+ *fZone = state;
369+ }
370+ };
371+
347372/* *************************************************************************************
348373 *
349374 * OwlUI : Faust User Interface builder. Passed to buildUserInterface OwlU
@@ -439,6 +464,21 @@ class OwlUI : public UI {
439464 fButton = NO_BUTTON; // clear current button ID
440465 }
441466
467+ void addOwlCheckbox (const char * label, FAUSTFLOAT* zone) {
468+ if (fParameterIndex < MAXOWLPARAMETERS) {
469+ if (meta.midiOn && strcasecmp (label, " gate" ) == 0 ) {
470+ fParameterTable [fParameterIndex ++] =
471+ new OwlVariable (fPatch , &fGate , zone, label, 0 .0f , 0 .0f , 1 .0f );
472+ }
473+ else if (fButton != NO_BUTTON) {
474+ fParameterTable [fParameterIndex ++] =
475+ new OwlCheckbox (fPatch , fButton , zone, label);
476+ }
477+ }
478+ fParameter = NO_PARAMETER;
479+ fButton = NO_BUTTON; // clear current button ID
480+ }
481+
442482 // we dont want to create a widget but we clear the current parameter ID just in case
443483 void skip () {
444484 fParameter = NO_PARAMETER; // clear current parameter ID
@@ -488,7 +528,7 @@ class OwlUI : public UI {
488528 addOwlButton (label, zone);
489529 }
490530 virtual void addCheckButton (const char * label, FAUSTFLOAT* zone) {
491- addOwlButton (label, zone);
531+ addOwlCheckbox (label, zone);
492532 }
493533 virtual void addVerticalSlider (const char * label, FAUSTFLOAT* zone,
494534 FAUSTFLOAT init, FAUSTFLOAT lo, FAUSTFLOAT hi, FAUSTFLOAT step) {
0 commit comments