From 317e8f920018a7b14bb15ab10a6597bec00c688e Mon Sep 17 00:00:00 2001 From: antisvin Date: Wed, 9 Dec 2020 23:47:57 +0300 Subject: [PATCH 1/2] Checkbox added --- FaustCode/owl.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/FaustCode/owl.cpp b/FaustCode/owl.cpp index 5095ee9a..cb4d9d74 100644 --- a/FaustCode/owl.cpp +++ b/FaustCode/owl.cpp @@ -344,6 +344,31 @@ 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); + if (isHigh && !wasHigh) { + // Rising edge detected + state = !state; + wasHigh = true; + } + else if (!isHigh && wasHigh) { + // Falling edge detected + wasHigh = false; + } + fPatch->setButton(fButton, state, 0); + *fZone = state; + } +}; + /************************************************************************************** * * OwlUI : Faust User Interface builder. Passed to buildUserInterface OwlU @@ -439,6 +464,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 @@ -488,7 +528,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) { From 455982b7e0aecc7d78d5c22aecf347dcc54a566f Mon Sep 17 00:00:00 2001 From: antisvin Date: Wed, 3 Mar 2021 21:25:46 +0300 Subject: [PATCH 2/2] Conditionals, begone --- FaustCode/owl.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/FaustCode/owl.cpp b/FaustCode/owl.cpp index 847c8061..eea79b5f 100644 --- a/FaustCode/owl.cpp +++ b/FaustCode/owl.cpp @@ -358,15 +358,8 @@ class OwlCheckbox : public OwlParameterBase { , fButton(button) {} void update() { bool isHigh = fPatch->isButtonPressed(fButton); - if (isHigh && !wasHigh) { - // Rising edge detected - state = !state; - wasHigh = true; - } - else if (!isHigh && wasHigh) { - // Falling edge detected - wasHigh = false; - } + state ^= isHigh && !wasHigh; + wasHigh = isHigh; fPatch->setButton(fButton, state, 0); *fZone = state; }