2015-07-08 11:39:24 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __UI_SPECTRUM_H__
|
|
|
|
#define __UI_SPECTRUM_H__
|
|
|
|
|
|
|
|
#include "ui.hpp"
|
|
|
|
#include "ui_widget.hpp"
|
2015-08-01 17:31:51 -04:00
|
|
|
|
2016-05-12 01:53:09 -04:00
|
|
|
#include "event_m0.hpp"
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
#include "message.hpp"
|
|
|
|
|
|
|
|
#include <cstdint>
|
2015-12-16 22:33:30 -05:00
|
|
|
#include <cstddef>
|
2015-12-02 16:38:17 -05:00
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
namespace ui {
|
|
|
|
namespace spectrum {
|
|
|
|
|
2018-05-21 23:43:04 -04:00
|
|
|
class AudioSpectrumView : public View {
|
|
|
|
public:
|
|
|
|
AudioSpectrumView(const Rect parent_rect);
|
|
|
|
|
|
|
|
void paint(Painter& painter) override;
|
|
|
|
|
2018-06-12 02:55:12 -04:00
|
|
|
void on_audio_spectrum(const AudioSpectrum* spectrum);
|
2018-05-21 23:43:04 -04:00
|
|
|
|
|
|
|
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()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
class FrequencyScale : public Widget {
|
|
|
|
public:
|
2018-05-21 23:43:04 -04:00
|
|
|
std::function<void(int32_t offset)> on_select { };
|
|
|
|
|
2015-12-16 22:33:30 -05:00
|
|
|
void on_show() override;
|
2018-05-21 23:43:04 -04:00
|
|
|
void on_focus() override;
|
|
|
|
void on_blur() override;
|
|
|
|
|
|
|
|
bool on_encoder(const EncoderEvent delta) override;
|
|
|
|
bool on_key(const KeyEvent key) override;
|
2015-07-08 11:39:24 -04:00
|
|
|
|
2016-01-23 20:53:16 -05:00
|
|
|
void set_spectrum_sampling_rate(const int new_sampling_rate);
|
|
|
|
void set_channel_filter(const int pass_frequency, const int stop_frequency);
|
2015-07-21 00:55:51 -04:00
|
|
|
|
2015-12-16 22:33:30 -05:00
|
|
|
void paint(Painter& painter) override;
|
2015-07-21 00:55:51 -04:00
|
|
|
|
|
|
|
private:
|
2016-01-23 20:53:16 -05:00
|
|
|
static constexpr int filter_band_height = 4;
|
2015-07-21 00:55:51 -04:00
|
|
|
|
2018-05-21 23:43:04 -04:00
|
|
|
void on_tick_second();
|
|
|
|
|
|
|
|
bool _blink { false };
|
2018-04-18 17:44:41 -04:00
|
|
|
int32_t cursor_position { 0 };
|
2018-05-21 23:43:04 -04:00
|
|
|
SignalToken signal_token_tick_second { };
|
2016-01-23 20:53:16 -05:00
|
|
|
int spectrum_sampling_rate { 0 };
|
|
|
|
const int spectrum_bins = std::tuple_size<decltype(ChannelSpectrum::db)>::value;
|
|
|
|
int channel_filter_pass_frequency { 0 };
|
|
|
|
int channel_filter_stop_frequency { 0 };
|
2015-07-21 00:55:51 -04:00
|
|
|
|
2015-12-16 22:33:30 -05:00
|
|
|
void clear();
|
|
|
|
void clear_background(Painter& painter, const Rect r);
|
2015-07-08 11:39:24 -04:00
|
|
|
|
2015-12-16 22:33:30 -05:00
|
|
|
void draw_frequency_ticks(Painter& painter, const Rect r);
|
|
|
|
void draw_filter_ranges(Painter& painter, const Rect r);
|
2015-07-08 11:39:24 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class WaterfallView : public Widget {
|
|
|
|
public:
|
2015-12-16 22:33:30 -05:00
|
|
|
void on_show() override;
|
|
|
|
void on_hide() override;
|
2015-07-08 11:39:24 -04:00
|
|
|
|
2015-12-16 22:33:30 -05:00
|
|
|
void paint(Painter& painter) override;
|
2015-07-08 11:39:24 -04:00
|
|
|
|
2015-12-16 22:33:30 -05:00
|
|
|
void on_channel_spectrum(const ChannelSpectrum& spectrum);
|
2015-10-16 22:36:07 -04:00
|
|
|
|
|
|
|
private:
|
2015-12-16 22:33:30 -05:00
|
|
|
void clear();
|
2015-07-08 11:39:24 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class WaterfallWidget : public View {
|
|
|
|
public:
|
2018-04-18 17:44:41 -04:00
|
|
|
std::function<void(int32_t offset)> on_select { };
|
|
|
|
|
|
|
|
WaterfallWidget(const bool cursor = false);
|
2015-07-08 11:39:24 -04:00
|
|
|
|
2016-11-26 19:52:57 -05:00
|
|
|
WaterfallWidget(const WaterfallWidget&) = delete;
|
|
|
|
WaterfallWidget(WaterfallWidget&&) = delete;
|
|
|
|
WaterfallWidget& operator=(const WaterfallWidget&) = delete;
|
|
|
|
WaterfallWidget& operator=(WaterfallWidget&&) = delete;
|
|
|
|
|
2015-12-16 22:33:30 -05:00
|
|
|
void on_show() override;
|
|
|
|
void on_hide() override;
|
2015-07-08 11:39:24 -04:00
|
|
|
|
2015-12-16 22:33:30 -05:00
|
|
|
void set_parent_rect(const Rect new_parent_rect) override;
|
2018-05-21 13:46:48 -04:00
|
|
|
|
2018-05-21 23:43:04 -04:00
|
|
|
void show_audio_spectrum_view(const bool show);
|
2015-07-08 11:39:24 -04:00
|
|
|
|
2015-12-16 22:33:30 -05:00
|
|
|
void paint(Painter& painter) override;
|
2015-07-08 11:39:24 -04:00
|
|
|
|
|
|
|
private:
|
2018-05-21 23:43:04 -04:00
|
|
|
void update_widgets_rect();
|
2018-04-18 17:44:41 -04:00
|
|
|
|
2018-05-21 23:43:04 -04:00
|
|
|
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;
|
2018-05-21 13:46:48 -04:00
|
|
|
|
2016-11-26 19:50:44 -05:00
|
|
|
WaterfallView waterfall_view { };
|
|
|
|
FrequencyScale frequency_scale { };
|
2018-04-18 17:44:41 -04:00
|
|
|
|
2018-05-21 13:46:48 -04:00
|
|
|
ChannelSpectrumFIFO* channel_fifo { nullptr };
|
2018-06-12 02:55:12 -04:00
|
|
|
AudioSpectrum* audio_spectrum_data { nullptr };
|
|
|
|
bool audio_spectrum_update { false };
|
2018-05-21 13:46:48 -04:00
|
|
|
|
2018-05-21 23:43:04 -04:00
|
|
|
std::unique_ptr<AudioSpectrumView> audio_spectrum_view { };
|
|
|
|
|
2018-04-18 17:44:41 -04:00
|
|
|
int sampling_rate { 0 };
|
|
|
|
int32_t cursor_position { 0 };
|
2018-05-21 13:46:48 -04:00
|
|
|
ui::Rect waterfall_normal_rect { };
|
|
|
|
ui::Rect waterfall_reduced_rect { };
|
2015-07-08 11:39:24 -04:00
|
|
|
|
2018-05-21 13:46:48 -04:00
|
|
|
MessageHandlerRegistration message_handler_channel_spectrum_config {
|
2016-05-12 01:53:09 -04:00
|
|
|
Message::ID::ChannelSpectrumConfig,
|
|
|
|
[this](const Message* const p) {
|
|
|
|
const auto message = *reinterpret_cast<const ChannelSpectrumConfigMessage*>(p);
|
2018-05-21 13:46:48 -04:00
|
|
|
this->channel_fifo = message.fifo;
|
|
|
|
}
|
|
|
|
};
|
2018-06-12 02:55:12 -04:00
|
|
|
MessageHandlerRegistration message_handler_audio_spectrum {
|
|
|
|
Message::ID::AudioSpectrum,
|
2018-05-21 13:46:48 -04:00
|
|
|
[this](const Message* const p) {
|
2018-06-12 02:55:12 -04:00
|
|
|
const auto message = *reinterpret_cast<const AudioSpectrumMessage*>(p);
|
|
|
|
this->audio_spectrum_data = message.data;
|
|
|
|
this->audio_spectrum_update = true;
|
2016-05-12 01:53:09 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
MessageHandlerRegistration message_handler_frame_sync {
|
|
|
|
Message::ID::DisplayFrameSync,
|
|
|
|
[this](const Message* const) {
|
2018-05-21 13:46:48 -04:00
|
|
|
if( this->channel_fifo ) {
|
2016-05-12 01:53:09 -04:00
|
|
|
ChannelSpectrum channel_spectrum;
|
2018-05-21 13:46:48 -04:00
|
|
|
while( channel_fifo->out(channel_spectrum) ) {
|
2016-05-12 01:53:09 -04:00
|
|
|
this->on_channel_spectrum(channel_spectrum);
|
|
|
|
}
|
|
|
|
}
|
2018-06-12 02:55:12 -04:00
|
|
|
if (this->audio_spectrum_update) {
|
|
|
|
this->audio_spectrum_update = false;
|
|
|
|
this->on_audio_spectrum();
|
2018-05-21 13:46:48 -04:00
|
|
|
}
|
2016-05-12 01:53:09 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-12-16 22:33:30 -05:00
|
|
|
void on_channel_spectrum(const ChannelSpectrum& spectrum);
|
2018-06-12 02:55:12 -04:00
|
|
|
void on_audio_spectrum();
|
2015-07-08 11:39:24 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace spectrum */
|
|
|
|
} /* namespace ui */
|
|
|
|
|
|
|
|
#endif/*__UI_SPECTRUM_H__*/
|