Skip to content

Commit

Permalink
Allow disable/enable waveform in Audio app to remove decoding problem…
Browse files Browse the repository at this point in the history
… on some frequencies
  • Loading branch information
zxkmm authored Mar 3, 2025
1 parent fcdccde commit ddf7f7c
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 8 deletions.
3 changes: 2 additions & 1 deletion firmware/application/external/fmradio/ui_fmradio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}, "---"};
Expand Down
3 changes: 2 additions & 1 deletion firmware/application/ui/ui_spectrum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion firmware/application/ui/ui_tv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
117 changes: 113 additions & 4 deletions firmware/common/ui_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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 **************************************************************/
Expand Down
16 changes: 15 additions & 1 deletion firmware/common/ui_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(Waveform&)> 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;
Expand All @@ -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};
Expand All @@ -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 {
Expand Down

0 comments on commit ddf7f7c

Please sign in to comment.