mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-02-04 08:55:21 -05:00
Added cursor to audio spectrum view
This commit is contained in:
parent
63c4a60cf7
commit
5c1ba9b90d
@ -208,8 +208,6 @@ void AnalogAudioView::remove_options_widget() {
|
||||
options_widget.reset();
|
||||
}
|
||||
|
||||
text_ctcss.hidden(true);
|
||||
|
||||
field_lna.set_style(nullptr);
|
||||
options_modulation.set_style(nullptr);
|
||||
field_frequency.set_style(nullptr);
|
||||
@ -257,21 +255,24 @@ void AnalogAudioView::on_show_options_modulation() {
|
||||
switch(modulation) {
|
||||
case ReceiverModel::Mode::AMAudio:
|
||||
widget = std::make_unique<AMOptionsView>(options_view_rect, &style_options_group);
|
||||
waterfall.set_fft_widget(false);
|
||||
waterfall.show_audio_spectrum_view(false);
|
||||
text_ctcss.hidden(true);
|
||||
break;
|
||||
|
||||
case ReceiverModel::Mode::NarrowbandFMAudio:
|
||||
widget = std::make_unique<NBFMOptionsView>(nbfm_view_rect, &style_options_group);
|
||||
waterfall.set_fft_widget(false);
|
||||
waterfall.show_audio_spectrum_view(false);
|
||||
text_ctcss.hidden(false);
|
||||
break;
|
||||
|
||||
case ReceiverModel::Mode::WidebandFMAudio:
|
||||
waterfall.set_fft_widget(true);
|
||||
waterfall.on_show();
|
||||
waterfall.show_audio_spectrum_view(true);
|
||||
text_ctcss.hidden(true);
|
||||
break;
|
||||
|
||||
case ReceiverModel::Mode::SpectrumAnalysis:
|
||||
waterfall.set_fft_widget(false);
|
||||
waterfall.show_audio_spectrum_view(false);
|
||||
text_ctcss.hidden(true);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -280,8 +281,6 @@ void AnalogAudioView::on_show_options_modulation() {
|
||||
|
||||
set_options_widget(std::move(widget));
|
||||
options_modulation.set_style(&style_options_group);
|
||||
|
||||
if (modulation == ReceiverModel::Mode::NarrowbandFMAudio) text_ctcss.hidden(false);
|
||||
}
|
||||
|
||||
void AnalogAudioView::on_frequency_step_changed(rf::Frequency f) {
|
||||
|
@ -43,6 +43,7 @@
|
||||
//GLITCH: Start of tx using ReplayThread plays a small bit of previous transmission (content of 1 buffer ?)
|
||||
// See fifo.reset_in() ?
|
||||
|
||||
//TODO: Increase resolution of audio FFT view ? Currently 48k/(256/2) (375Hz) because of the use of real values (half of FFT output)
|
||||
//TODO: DCS decoder
|
||||
//TODO: Make CTCSS display only when squelch is opened
|
||||
//TODO: Make play button larger in Replay
|
||||
|
@ -36,6 +36,50 @@ using namespace portapack;
|
||||
namespace ui {
|
||||
namespace spectrum {
|
||||
|
||||
/* AudioSpectrumView******************************************************/
|
||||
|
||||
AudioSpectrumView::AudioSpectrumView(
|
||||
const Rect parent_rect
|
||||
) : View { parent_rect }
|
||||
{
|
||||
set_focusable(true);
|
||||
|
||||
add_children({
|
||||
&labels,
|
||||
&field_frequency,
|
||||
&waveform
|
||||
});
|
||||
|
||||
field_frequency.on_change = [this](int32_t) {
|
||||
set_dirty();
|
||||
};
|
||||
field_frequency.set_value(0);
|
||||
}
|
||||
|
||||
void AudioSpectrumView::paint(Painter& painter) {
|
||||
const auto r = screen_rect();
|
||||
|
||||
painter.fill_rectangle(r, Color::black());
|
||||
|
||||
//if( !spectrum_sampling_rate ) return;
|
||||
|
||||
// Cursor
|
||||
const Rect r_cursor {
|
||||
field_frequency.value() / (48000 / 240), r.bottom() - 32 - cursor_band_height,
|
||||
1, cursor_band_height
|
||||
};
|
||||
painter.fill_rectangle(
|
||||
r_cursor,
|
||||
Color::red()
|
||||
);
|
||||
}
|
||||
|
||||
void AudioSpectrumView::on_audio_spectrum(const AudioSpectrum& spectrum) {
|
||||
for (size_t i = 0; i < spectrum.db.size(); i++)
|
||||
audio_spectrum[i] = ((int16_t)spectrum.db[i] - 127) * 256;
|
||||
waveform.set_dirty();
|
||||
}
|
||||
|
||||
/* FrequencyScale ********************************************************/
|
||||
|
||||
void FrequencyScale::on_show() {
|
||||
@ -61,19 +105,6 @@ void FrequencyScale::set_channel_filter(
|
||||
}
|
||||
}
|
||||
|
||||
void FrequencyScale::show_cursor(const bool v) {
|
||||
if (v != _show_cursor) {
|
||||
_show_cursor = v;
|
||||
set_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
void FrequencyScale::set_cursor_position(const int32_t value) {
|
||||
_show_cursor = true;
|
||||
cursor_position = value;
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
void FrequencyScale::paint(Painter& painter) {
|
||||
const auto r = screen_rect();
|
||||
|
||||
@ -87,7 +118,7 @@ void FrequencyScale::paint(Painter& painter) {
|
||||
draw_filter_ranges(painter, r);
|
||||
draw_frequency_ticks(painter, r);
|
||||
|
||||
if (_show_cursor) {
|
||||
if (_blink) {
|
||||
const Rect r_cursor {
|
||||
120 + cursor_position, r.bottom() - filter_band_height,
|
||||
2, filter_band_height
|
||||
@ -196,6 +227,48 @@ void FrequencyScale::draw_filter_ranges(Painter& painter, const Rect r) {
|
||||
}
|
||||
}
|
||||
|
||||
void FrequencyScale::on_focus() {
|
||||
_blink = true;
|
||||
on_tick_second();
|
||||
signal_token_tick_second = rtc_time::signal_tick_second += [this]() {
|
||||
this->on_tick_second();
|
||||
};
|
||||
}
|
||||
|
||||
void FrequencyScale::on_blur() {
|
||||
rtc_time::signal_tick_second -= signal_token_tick_second;
|
||||
_blink = false;
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
bool FrequencyScale::on_encoder(const EncoderEvent delta) {
|
||||
cursor_position += delta;
|
||||
|
||||
cursor_position = std::min<int32_t>(cursor_position, 119);
|
||||
cursor_position = std::max<int32_t>(cursor_position, -120);
|
||||
|
||||
set_dirty();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FrequencyScale::on_key(const KeyEvent key) {
|
||||
if( key == KeyEvent::Select ) {
|
||||
if( on_select ) {
|
||||
on_select((cursor_position * spectrum_sampling_rate) / 240);
|
||||
cursor_position = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void FrequencyScale::on_tick_second() {
|
||||
set_dirty();
|
||||
_blink = !_blink;
|
||||
}
|
||||
|
||||
/* WaterfallView *********************************************************/
|
||||
|
||||
void WaterfallView::on_show() {
|
||||
@ -251,21 +324,17 @@ void WaterfallView::clear() {
|
||||
/* WaterfallWidget *******************************************************/
|
||||
|
||||
WaterfallWidget::WaterfallWidget(const bool cursor) {
|
||||
set_focusable(cursor);
|
||||
|
||||
add_children({
|
||||
&waterfall_view,
|
||||
&frequency_scale
|
||||
});
|
||||
}
|
||||
|
||||
WaterfallWidget::~WaterfallWidget() {
|
||||
rtc_time::signal_tick_second -= signal_token_tick_second;
|
||||
}
|
||||
|
||||
void WaterfallWidget::on_tick_second() {
|
||||
frequency_scale.show_cursor(_blink);
|
||||
_blink = !_blink;
|
||||
|
||||
frequency_scale.set_focusable(cursor);
|
||||
|
||||
// Making the event climb up all the way up to here kinda sucks
|
||||
frequency_scale.on_select = [this](int32_t offset) {
|
||||
if (on_select) on_select(offset);
|
||||
};
|
||||
}
|
||||
|
||||
void WaterfallWidget::on_show() {
|
||||
@ -276,89 +345,39 @@ void WaterfallWidget::on_hide() {
|
||||
baseband::spectrum_streaming_stop();
|
||||
}
|
||||
|
||||
void WaterfallWidget::on_focus() {
|
||||
_blink = true;
|
||||
signal_token_tick_second = rtc_time::signal_tick_second += [this]() {
|
||||
this->on_tick_second();
|
||||
};
|
||||
}
|
||||
|
||||
void WaterfallWidget::on_blur() {
|
||||
frequency_scale.show_cursor(false);
|
||||
rtc_time::signal_tick_second -= signal_token_tick_second;
|
||||
}
|
||||
|
||||
bool WaterfallWidget::on_encoder(const EncoderEvent delta) {
|
||||
cursor_position += delta;
|
||||
|
||||
cursor_position = std::min<int32_t>(cursor_position, 119);
|
||||
cursor_position = std::max<int32_t>(cursor_position, -120);
|
||||
|
||||
frequency_scale.set_cursor_position(cursor_position);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WaterfallWidget::on_key(const KeyEvent key) {
|
||||
if( key == KeyEvent::Select ) {
|
||||
if( on_select ) {
|
||||
on_select((cursor_position * sampling_rate) / 240);
|
||||
cursor_position = 0;
|
||||
frequency_scale.set_cursor_position(cursor_position);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void WaterfallWidget::on_audio_spectrum(const AudioSpectrum& spectrum) {
|
||||
if (fft_widget) {
|
||||
for (size_t i = 0; i < spectrum.db.size(); i++)
|
||||
audio_spectrum[i] = ((int16_t)spectrum.db[i] - 127) * 256;
|
||||
fft_widget->set_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
void WaterfallWidget::set_fft_widget(const bool show) {
|
||||
if (fft_widget) {
|
||||
audio_fifo = nullptr;
|
||||
remove_child(fft_widget.get());
|
||||
fft_widget.reset();
|
||||
}
|
||||
void WaterfallWidget::show_audio_spectrum_view(const bool show) {
|
||||
if ((audio_spectrum_view && show) || (!audio_spectrum_view && !show)) return;
|
||||
|
||||
if (show) {
|
||||
waterfall_view.set_parent_rect(waterfall_reduced_rect);
|
||||
waterfall_view.on_show();
|
||||
fft_widget = std::make_unique<Waveform>(
|
||||
fft_widget_rect,
|
||||
audio_spectrum,
|
||||
128,
|
||||
0,
|
||||
false,
|
||||
Color::white());
|
||||
add_child(fft_widget.get());
|
||||
audio_spectrum_view = std::make_unique<AudioSpectrumView>(audio_spectrum_view_rect);
|
||||
add_child(audio_spectrum_view.get());
|
||||
update_widgets_rect();
|
||||
} else {
|
||||
waterfall_view.set_parent_rect(waterfall_normal_rect);
|
||||
waterfall_view.on_show();
|
||||
audio_fifo = nullptr;
|
||||
remove_child(audio_spectrum_view.get());
|
||||
audio_spectrum_view.reset();
|
||||
update_widgets_rect();
|
||||
}
|
||||
}
|
||||
|
||||
void WaterfallWidget::update_widgets_rect() {
|
||||
if (audio_spectrum_view) {
|
||||
frequency_scale.set_parent_rect({ 0, audio_spectrum_height, screen_rect().width(), scale_height });
|
||||
waterfall_view.set_parent_rect(waterfall_reduced_rect);
|
||||
} else {
|
||||
frequency_scale.set_parent_rect({ 0, 0, screen_rect().width(), scale_height });
|
||||
waterfall_view.set_parent_rect(waterfall_normal_rect);
|
||||
}
|
||||
waterfall_view.on_show();
|
||||
}
|
||||
|
||||
void WaterfallWidget::set_parent_rect(const Rect new_parent_rect) {
|
||||
constexpr Dim scale_height = 20;
|
||||
|
||||
View::set_parent_rect(new_parent_rect);
|
||||
|
||||
waterfall_normal_rect = { 0, scale_height, new_parent_rect.width(), new_parent_rect.height() - scale_height};
|
||||
waterfall_reduced_rect = { 0, scale_height, new_parent_rect.width(), new_parent_rect.height() - scale_height - audio_spectrum_height };
|
||||
waterfall_reduced_rect = { 0, audio_spectrum_height + scale_height, new_parent_rect.width(), new_parent_rect.height() - scale_height - audio_spectrum_height };
|
||||
|
||||
frequency_scale.set_parent_rect({ 0, 0, new_parent_rect.width(), scale_height });
|
||||
if (fft_widget)
|
||||
waterfall_view.set_parent_rect(waterfall_reduced_rect);
|
||||
else
|
||||
waterfall_view.set_parent_rect(waterfall_normal_rect);
|
||||
waterfall_view.on_show();
|
||||
|
||||
fft_widget_rect = { 0, new_parent_rect.height() - audio_spectrum_height, new_parent_rect.width(), audio_spectrum_height };
|
||||
update_widgets_rect();
|
||||
}
|
||||
|
||||
void WaterfallWidget::paint(Painter& painter) {
|
||||
@ -376,5 +395,9 @@ void WaterfallWidget::on_channel_spectrum(const ChannelSpectrum& spectrum) {
|
||||
);
|
||||
}
|
||||
|
||||
void WaterfallWidget::on_audio_spectrum(const AudioSpectrum& spectrum) {
|
||||
audio_spectrum_view->on_audio_spectrum(spectrum);
|
||||
}
|
||||
|
||||
} /* namespace spectrum */
|
||||
} /* namespace ui */
|
||||
|
@ -35,22 +35,65 @@
|
||||
namespace ui {
|
||||
namespace spectrum {
|
||||
|
||||
class AudioSpectrumView : public View {
|
||||
public:
|
||||
AudioSpectrumView(const Rect parent_rect);
|
||||
|
||||
void paint(Painter& painter) override;
|
||||
|
||||
void on_audio_spectrum(const AudioSpectrum& spectrum);
|
||||
|
||||
private:
|
||||
static constexpr int cursor_band_height = 4;
|
||||
|
||||
int16_t audio_spectrum[128] { 0 };
|
||||
|
||||
Labels labels {
|
||||
{ { 6 * 8, 0 * 16 }, "Hz", Color::light_grey() }
|
||||
};
|
||||
|
||||
NumberField field_frequency {
|
||||
{ 0 * 8, 0 * 16 },
|
||||
5,
|
||||
{ 0, 48000 },
|
||||
48000 / 240,
|
||||
' '
|
||||
};
|
||||
|
||||
Waveform waveform {
|
||||
{ 0, 1 * 16 + cursor_band_height, 30 * 8, 2 * 16 },
|
||||
audio_spectrum,
|
||||
128,
|
||||
0,
|
||||
false,
|
||||
Color::white()
|
||||
};
|
||||
};
|
||||
|
||||
class FrequencyScale : public Widget {
|
||||
public:
|
||||
std::function<void(int32_t offset)> on_select { };
|
||||
|
||||
void on_show() override;
|
||||
void on_focus() override;
|
||||
void on_blur() override;
|
||||
|
||||
bool on_encoder(const EncoderEvent delta) override;
|
||||
bool on_key(const KeyEvent key) override;
|
||||
|
||||
void set_spectrum_sampling_rate(const int new_sampling_rate);
|
||||
void set_channel_filter(const int pass_frequency, const int stop_frequency);
|
||||
void show_cursor(const bool v);
|
||||
void set_cursor_position(const int32_t value);
|
||||
|
||||
void paint(Painter& painter) override;
|
||||
|
||||
private:
|
||||
static constexpr int filter_band_height = 4;
|
||||
|
||||
bool _show_cursor { false };
|
||||
void on_tick_second();
|
||||
|
||||
bool _blink { false };
|
||||
int32_t cursor_position { 0 };
|
||||
SignalToken signal_token_tick_second { };
|
||||
int spectrum_sampling_rate { 0 };
|
||||
const int spectrum_bins = std::tuple_size<decltype(ChannelSpectrum::db)>::value;
|
||||
int channel_filter_pass_frequency { 0 };
|
||||
@ -81,7 +124,6 @@ public:
|
||||
std::function<void(int32_t offset)> on_select { };
|
||||
|
||||
WaterfallWidget(const bool cursor = false);
|
||||
~WaterfallWidget();
|
||||
|
||||
WaterfallWidget(const WaterfallWidget&) = delete;
|
||||
WaterfallWidget(WaterfallWidget&&) = delete;
|
||||
@ -90,23 +132,19 @@ public:
|
||||
|
||||
void on_show() override;
|
||||
void on_hide() override;
|
||||
void on_focus() override;
|
||||
void on_blur() override;
|
||||
|
||||
bool on_encoder(const EncoderEvent delta) override;
|
||||
bool on_key(const KeyEvent key) override;
|
||||
|
||||
void set_parent_rect(const Rect new_parent_rect) override;
|
||||
|
||||
void set_fft_widget(const bool show);
|
||||
void show_audio_spectrum_view(const bool show);
|
||||
|
||||
void paint(Painter& painter) override;
|
||||
|
||||
private:
|
||||
void on_tick_second();
|
||||
void update_widgets_rect();
|
||||
|
||||
//static constexpr ui::Dim audio_spectrum_scale_height = 16 + 2;
|
||||
static constexpr ui::Dim audio_spectrum_height = 2 * 16;
|
||||
const Rect audio_spectrum_view_rect { 0 * 8, 0 * 16, 30 * 8, 2 * 16 + 20 };
|
||||
static constexpr Dim audio_spectrum_height = 16 * 2 + 20;
|
||||
static constexpr Dim scale_height = 20;
|
||||
|
||||
WaterfallView waterfall_view { };
|
||||
FrequencyScale frequency_scale { };
|
||||
@ -114,15 +152,12 @@ private:
|
||||
ChannelSpectrumFIFO* channel_fifo { nullptr };
|
||||
AudioSpectrumFIFO* audio_fifo { nullptr };
|
||||
|
||||
std::unique_ptr<Widget> fft_widget { };
|
||||
bool _blink { false };
|
||||
std::unique_ptr<AudioSpectrumView> audio_spectrum_view { };
|
||||
|
||||
int sampling_rate { 0 };
|
||||
int32_t cursor_position { 0 };
|
||||
SignalToken signal_token_tick_second { };
|
||||
int16_t audio_spectrum[128] { 0 };
|
||||
ui::Rect waterfall_normal_rect { };
|
||||
ui::Rect waterfall_reduced_rect { };
|
||||
ui::Rect fft_widget_rect { };
|
||||
|
||||
MessageHandlerRegistration message_handler_channel_spectrum_config {
|
||||
Message::ID::ChannelSpectrumConfig,
|
||||
|
@ -1523,7 +1523,7 @@ void Waveform::set_length(const uint32_t new_length) {
|
||||
void Waveform::paint(Painter& painter) {
|
||||
size_t n;
|
||||
Coord y, y_offset = screen_rect().location().y();
|
||||
Coord prev_x, prev_y;
|
||||
Coord prev_x = screen_rect().location().x(), prev_y;
|
||||
float x, x_inc;
|
||||
Dim h = screen_rect().size().height();
|
||||
const float y_scale = (float)(h - 1) / 65536.0;
|
||||
@ -1535,18 +1535,6 @@ void Waveform::paint(Painter& painter) {
|
||||
|
||||
// Clear
|
||||
painter.fill_rectangle_unrolled8(screen_rect(), Color::black());
|
||||
/*prev_x = screen_rect().location().x();
|
||||
prev_y = previous_data[0];
|
||||
x = prev_x + x_inc;
|
||||
for (n = 1; n < length_; n++) {
|
||||
y = previous_data[n];
|
||||
display.draw_line( {prev_x, prev_y}, {(Coord)x, y}, Color::black());
|
||||
|
||||
prev_x = x;
|
||||
prev_y = y;
|
||||
x += x_inc;
|
||||
}*/
|
||||
prev_x = screen_rect().location().x();
|
||||
|
||||
if (digital_) {
|
||||
// Digital waveform: each value is an horizontal line
|
||||
@ -1570,10 +1558,8 @@ void Waveform::paint(Painter& painter) {
|
||||
x = prev_x + x_inc;
|
||||
h /= 2;
|
||||
prev_y = y_offset + h - (*(data_start++) * y_scale);
|
||||
//previous_data[0] = prev_y;
|
||||
for (n = 1; n < length_; n++) {
|
||||
y = y_offset + h - (*(data_start++) * y_scale);
|
||||
//previous_data[n] = y;
|
||||
display.draw_line( {prev_x, prev_y}, {(Coord)x, y}, color_);
|
||||
|
||||
prev_x = x;
|
||||
|
@ -617,7 +617,6 @@ private:
|
||||
const Color cursor_colors[2] = { Color::cyan(), Color::magenta() };
|
||||
|
||||
int16_t * data_;
|
||||
//std::vector<int16_t> previous_data { };
|
||||
uint32_t length_;
|
||||
uint32_t offset_;
|
||||
bool digital_ { false };
|
||||
|
Loading…
x
Reference in New Issue
Block a user