mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-08-07 06:02:20 -04:00
Allow disable/enable waveform in Audio app to remove decoding problem on some frequencies
This commit is contained in:
parent
fcdccdea85
commit
ddf7f7ccb5
5 changed files with 134 additions and 8 deletions
|
@ -108,7 +108,8 @@ class FmRadioView : public View {
|
||||||
128,
|
128,
|
||||||
0,
|
0,
|
||||||
false,
|
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_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}, "---"};
|
Button btn_fav_1{{2 + 15 * 8, FMR_BTNGRID_TOP + 0 * 34, 10 * 8, 28}, "---"};
|
||||||
|
|
|
@ -64,7 +64,8 @@ class AudioSpectrumView : public View {
|
||||||
128,
|
128,
|
||||||
0,
|
0,
|
||||||
false,
|
false,
|
||||||
Theme::getInstance()->bg_darkest->foreground};
|
Theme::getInstance()->bg_darkest->foreground,
|
||||||
|
true};
|
||||||
};
|
};
|
||||||
|
|
||||||
class FrequencyScale : public Widget {
|
class FrequencyScale : public Widget {
|
||||||
|
|
|
@ -67,7 +67,8 @@ class TimeScopeView : public View {
|
||||||
128,
|
128,
|
||||||
0,
|
0,
|
||||||
false,
|
false,
|
||||||
Theme::getInstance()->bg_darkest->foreground};
|
Theme::getInstance()->bg_darkest->foreground,
|
||||||
|
true};
|
||||||
};
|
};
|
||||||
|
|
||||||
class TVView : public Widget {
|
class TVView : public Widget {
|
||||||
|
|
|
@ -2606,15 +2606,19 @@ Waveform::Waveform(
|
||||||
uint32_t length,
|
uint32_t length,
|
||||||
uint32_t offset,
|
uint32_t offset,
|
||||||
bool digital,
|
bool digital,
|
||||||
Color color)
|
Color color,
|
||||||
|
bool clickable)
|
||||||
: Widget{parent_rect},
|
: Widget{parent_rect},
|
||||||
data_{data},
|
data_{data},
|
||||||
length_{length},
|
length_{length},
|
||||||
offset_{offset},
|
offset_{offset},
|
||||||
digital_{digital},
|
digital_{digital},
|
||||||
color_{color} {
|
color_{color},
|
||||||
// set_focusable(false);
|
clickable_{clickable} {
|
||||||
// previous_data.resize(length_, 0);
|
if (clickable) {
|
||||||
|
set_focusable(true);
|
||||||
|
// previous_data.resize(length_, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Waveform::set_cursor(const uint32_t i, const int16_t position) {
|
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) {
|
void Waveform::paint(Painter& painter) {
|
||||||
// previously it's upside down , low level is up and high level is down, which doesn't make sense,
|
// 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 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;
|
size_t n;
|
||||||
Coord y, y_offset = screen_rect().location().y();
|
Coord y, y_offset = screen_rect().location().y();
|
||||||
Coord prev_x = screen_rect().location().x(), prev_y;
|
Coord prev_x = screen_rect().location().x(), prev_y;
|
||||||
|
@ -2701,6 +2803,13 @@ void Waveform::paint(Painter& painter) {
|
||||||
cursor_colors[n]);
|
cursor_colors[n]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// focused highlight border
|
||||||
|
if (clickable_ && has_focus()) {
|
||||||
|
painter.draw_rectangle(
|
||||||
|
screen_rect(),
|
||||||
|
Theme::getInstance()->fg_light->foreground);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* VuMeter **************************************************************/
|
/* VuMeter **************************************************************/
|
||||||
|
|
|
@ -974,7 +974,9 @@ class SymField : public Widget {
|
||||||
|
|
||||||
class Waveform : public Widget {
|
class Waveform : public Widget {
|
||||||
public:
|
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(const Waveform&) = delete;
|
||||||
Waveform(Waveform&&) = delete;
|
Waveform(Waveform&&) = delete;
|
||||||
|
@ -985,7 +987,17 @@ class Waveform : public Widget {
|
||||||
void set_length(const uint32_t new_length);
|
void set_length(const uint32_t new_length);
|
||||||
void set_cursor(const uint32_t i, const int16_t position);
|
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;
|
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:
|
private:
|
||||||
const Color cursor_colors[2] = {Theme::getInstance()->fg_cyan->foreground, Theme::getInstance()->fg_magenta->foreground};
|
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_;
|
Color color_;
|
||||||
int16_t cursors[2]{};
|
int16_t cursors[2]{};
|
||||||
bool show_cursors{false};
|
bool show_cursors{false};
|
||||||
|
bool paused_{false};
|
||||||
|
bool clickable_{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
class VuMeter : public Widget {
|
class VuMeter : public Widget {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue