From ddf7f7ccb5eefa1ddbcf8286f160fa0a7764cd42 Mon Sep 17 00:00:00 2001 From: sommermorgentraum <24917424+zxkmm@users.noreply.github.com> Date: Tue, 4 Mar 2025 05:16:03 +0800 Subject: [PATCH] Allow disable/enable waveform in Audio app to remove decoding problem on some frequencies --- .../external/fmradio/ui_fmradio.hpp | 3 +- firmware/application/ui/ui_spectrum.hpp | 3 +- firmware/application/ui/ui_tv.hpp | 3 +- firmware/common/ui_widget.cpp | 117 +++++++++++++++++- firmware/common/ui_widget.hpp | 16 ++- 5 files changed, 134 insertions(+), 8 deletions(-) diff --git a/firmware/application/external/fmradio/ui_fmradio.hpp b/firmware/application/external/fmradio/ui_fmradio.hpp index 74fc65eaa..f204366fd 100644 --- a/firmware/application/external/fmradio/ui_fmradio.hpp +++ b/firmware/application/external/fmradio/ui_fmradio.hpp @@ -108,7 +108,8 @@ class FmRadioView : public View { 128, 0, false, - Theme::getInstance()->bg_darkest->foreground}; + Theme::getInstance()->bg_darkest->foreground, + true}; Button btn_fav_0{{2, FMR_BTNGRID_TOP + 0 * 34, 10 * 8, 28}, "---"}; Button btn_fav_1{{2 + 15 * 8, FMR_BTNGRID_TOP + 0 * 34, 10 * 8, 28}, "---"}; diff --git a/firmware/application/ui/ui_spectrum.hpp b/firmware/application/ui/ui_spectrum.hpp index 86b2a8158..9d0d70cb9 100644 --- a/firmware/application/ui/ui_spectrum.hpp +++ b/firmware/application/ui/ui_spectrum.hpp @@ -64,7 +64,8 @@ class AudioSpectrumView : public View { 128, 0, false, - Theme::getInstance()->bg_darkest->foreground}; + Theme::getInstance()->bg_darkest->foreground, + true}; }; class FrequencyScale : public Widget { diff --git a/firmware/application/ui/ui_tv.hpp b/firmware/application/ui/ui_tv.hpp index dd055027b..a000c396b 100644 --- a/firmware/application/ui/ui_tv.hpp +++ b/firmware/application/ui/ui_tv.hpp @@ -67,7 +67,8 @@ class TimeScopeView : public View { 128, 0, false, - Theme::getInstance()->bg_darkest->foreground}; + Theme::getInstance()->bg_darkest->foreground, + true}; }; class TVView : public Widget { diff --git a/firmware/common/ui_widget.cpp b/firmware/common/ui_widget.cpp index 9f405bb95..80f805a24 100644 --- a/firmware/common/ui_widget.cpp +++ b/firmware/common/ui_widget.cpp @@ -2606,15 +2606,19 @@ Waveform::Waveform( uint32_t length, uint32_t offset, bool digital, - Color color) + Color color, + bool clickable) : Widget{parent_rect}, data_{data}, length_{length}, offset_{offset}, digital_{digital}, - color_{color} { - // set_focusable(false); - // previous_data.resize(length_, 0); + color_{color}, + clickable_{clickable} { + if (clickable) { + set_focusable(true); + // previous_data.resize(length_, 0); + } } void Waveform::set_cursor(const uint32_t i, const int16_t position) { @@ -2641,9 +2645,107 @@ void Waveform::set_length(const uint32_t new_length) { } } +bool Waveform::is_paused() const { + return paused_; +} + +void Waveform::set_paused(bool paused) { + paused_ = paused; + set_dirty(); +} + +bool Waveform::is_clickable() const { + return clickable_; +} + +void Waveform::getAccessibilityText(std::string& result) { + // no idea what this is in use in any places, but others have it + result = paused_ ? "paused waveform" : "waveform"; +} + +void Waveform::getWidgetName(std::string& result) { + result = "Waveform"; +} + +bool Waveform::on_key(const KeyEvent key) { + if (!clickable_) return false; + + if (key == KeyEvent::Select) { + set_paused(!paused_); + if (on_select) { + on_select(*this); + } + return true; + } + return false; +} + +bool Waveform::on_keyboard(const KeyboardEvent key) { + // no idea what this is for, but others have it + if (!clickable_) return false; + + if (key == 32 || key == 10) { + set_paused(!paused_); + if (on_select) { + on_select(*this); + } + return true; + } + return false; +} + +bool Waveform::on_touch(const TouchEvent event) { + if (!clickable_) return false; + + switch (event.type) { + case TouchEvent::Type::Start: + focus(); + return true; + + case TouchEvent::Type::End: + set_paused(!paused_); + if (on_select) { + on_select(*this); + } + return true; + + default: + return false; + } +} + void Waveform::paint(Painter& painter) { // previously it's upside down , low level is up and high level is down, which doesn't make sense, // if that was made for a reason, feel free to revert. + + if (paused_) { + // TODO: this is bad: that it still enter this func and still consume resources. + // even do a if(paused_) return; comsume too, but not that much. + + // if (dirty()) { + // clear + // painter.fill_rectangle_unrolled8(screen_rect(), Theme::getInstance()->bg_darkest->background); + + // // draw "PAUSED" text + // const auto r = screen_rect(); + // painter.draw_string( + // {r.center().x() - 24, r.center().y() - 8}, + // style(), + // "PAUSED"); + + // if (show_cursors) { + // for (uint32_t n = 0; n < 2; n++) { + // painter.draw_vline( + // Point(std::min(screen_rect().size().width(), (int)cursors[n]), screen_rect().location().y()), + // screen_rect().size().height(), + // cursor_colors[n]); + // } + // } + // } + return; + } + + // not paused size_t n; Coord y, y_offset = screen_rect().location().y(); Coord prev_x = screen_rect().location().x(), prev_y; @@ -2701,6 +2803,13 @@ void Waveform::paint(Painter& painter) { cursor_colors[n]); } } + + // focused highlight border + if (clickable_ && has_focus()) { + painter.draw_rectangle( + screen_rect(), + Theme::getInstance()->fg_light->foreground); + } } /* VuMeter **************************************************************/ diff --git a/firmware/common/ui_widget.hpp b/firmware/common/ui_widget.hpp index e4c775247..5fa40e731 100644 --- a/firmware/common/ui_widget.hpp +++ b/firmware/common/ui_widget.hpp @@ -974,7 +974,9 @@ class SymField : public Widget { class Waveform : public Widget { public: - Waveform(Rect parent_rect, int16_t* data, uint32_t length, uint32_t offset, bool digital, Color color); + std::function on_select{}; + + Waveform(Rect parent_rect, int16_t* data, uint32_t length, uint32_t offset, bool digital, Color color, bool clickable = false); Waveform(const Waveform&) = delete; Waveform(Waveform&&) = delete; @@ -985,7 +987,17 @@ class Waveform : public Widget { void set_length(const uint32_t new_length); void set_cursor(const uint32_t i, const int16_t position); + bool is_paused() const; + void set_paused(bool paused); + bool is_clickable() const; + void paint(Painter& painter) override; + bool on_key(const KeyEvent key) override; + bool on_touch(const TouchEvent event) override; + bool on_keyboard(const KeyboardEvent event) override; + + void getAccessibilityText(std::string& result) override; + void getWidgetName(std::string& result) override; private: const Color cursor_colors[2] = {Theme::getInstance()->fg_cyan->foreground, Theme::getInstance()->fg_magenta->foreground}; @@ -997,6 +1009,8 @@ class Waveform : public Widget { Color color_; int16_t cursors[2]{}; bool show_cursors{false}; + bool paused_{false}; + bool clickable_{false}; }; class VuMeter : public Widget {