From d7fcc9c0b05a06cc9a71241c1adc948774aab9bc Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Tue, 11 Feb 2025 23:14:29 +0000 Subject: [PATCH] buttons switch LEDs --- plugin/chassis.hpp | 4 +++- plugin/ui.cpp | 18 +++++++++++++++++- plugin/ui.hpp | 5 ++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/plugin/chassis.hpp b/plugin/chassis.hpp index ecea3f3..c4d2c47 100644 --- a/plugin/chassis.hpp +++ b/plugin/chassis.hpp @@ -55,7 +55,9 @@ class Chassis : public Plugin { pChorus, - parameterCount + parameterCount, + + btn16, btn8, btn4, btnPls, btnSaw, btnCh0, btnCh1, btnCh2 }; Chassis(); diff --git a/plugin/ui.cpp b/plugin/ui.cpp index 08c49d7..204dd2a 100644 --- a/plugin/ui.cpp +++ b/plugin/ui.cpp @@ -157,13 +157,18 @@ DistrhoUIchassis::DistrhoUIchassis() : UI(Art::backgroundWidth, Art::backgroundH xBtn16ft = new ImageButton(this, Image(Art::orngBtnUp, Art::orngBtnWidth, Art::orngBtnHeight, kImageFormatRGB), Image(Art::orngBtnDn, Art::orngBtnWidth, Art::orngBtnHeight, kImageFormatRGB)); xBtn16ft->setAbsolutePos(149,103); + xBtn16ft->setId(Chassis::btn16); + xBtn16ft->setCallback(this); xBtn8ft = new ImageButton(this, Image(Art::orngBtnUp, Art::orngBtnWidth, Art::orngBtnHeight, kImageFormatRGB), Image(Art::orngBtnDn, Art::orngBtnWidth, Art::orngBtnHeight, kImageFormatRGB)); xBtn8ft->setAbsolutePos(190,103); + xBtn8ft->setId(Chassis::btn8); + xBtn8ft->setCallback(this); xBtn4ft = new ImageButton(this, Image(Art::orngBtnUp, Art::orngBtnWidth, Art::orngBtnHeight, kImageFormatRGB), Image(Art::orngBtnDn, Art::orngBtnWidth, Art::orngBtnHeight, kImageFormatRGB)); xBtn4ft->setAbsolutePos(231,103); - + xBtn4ft->setId(Chassis::btn4); + xBtn4ft->setCallback(this); programLoaded(0); } @@ -271,6 +276,17 @@ void DistrhoUIchassis::imageSliderValueChanged(ImageSlider* slider, float value) setParameterValue(slider->getId(), value); } +void DistrhoUIchassis::imageButtonClicked(ImageButton *imgBtn, int) { + int id = imgBtn->getId(); + //printf("imagebutton %d\n", id); + switch (id) { + case Chassis::btn16: sw1 &= 0xf8; sw1 |= 0x01; break; + case Chassis::btn8: sw1 &= 0xf8; sw1 |= 0x02; break; + case Chassis::btn4: sw1 &= 0xf8; sw1 |= 0x04; break; + default: break; + } +} + void DistrhoUIchassis::onDisplay() { const GraphicsContext& context(getGraphicsContext()); fImgBackground.draw(context); diff --git a/plugin/ui.hpp b/plugin/ui.hpp index 635f6e8..3ae5f66 100644 --- a/plugin/ui.hpp +++ b/plugin/ui.hpp @@ -8,7 +8,8 @@ START_NAMESPACE_DISTRHO class DistrhoUIchassis : public UI, - public ImageSlider::Callback { + public ImageSlider::Callback, + public ImageButton::Callback { public: DistrhoUIchassis(); ~DistrhoUIchassis() override; @@ -22,6 +23,8 @@ class DistrhoUIchassis : public UI, void imageSliderDragFinished(ImageSlider* slider) override; void imageSliderValueChanged(ImageSlider* slider, float value) override; + void imageButtonClicked(ImageButton *imageButton, int button) override; + private: Image fImgBackground; Image fImgLedOn;