2022-04-03 19:38:06 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
* Copyright (C) 2016 Furrtek
|
2023-06-17 16:01:46 -04:00
|
|
|
* Copyright (C) 2023 Kyle Reed, zxkmm
|
2022-04-03 19:38:06 -04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
#define SHORT_UI true
|
|
|
|
#define NORMAL_UI false
|
2022-04-03 19:38:06 -04:00
|
|
|
|
2023-06-11 14:47:13 -04:00
|
|
|
#include "app_settings.hpp"
|
2023-06-14 03:57:20 -04:00
|
|
|
#include "radio_state.hpp"
|
2022-04-03 19:38:06 -04:00
|
|
|
#include "ui_widget.hpp"
|
|
|
|
#include "ui_navigation.hpp"
|
|
|
|
#include "ui_receiver.hpp"
|
|
|
|
#include "replay_thread.hpp"
|
|
|
|
#include "ui_spectrum.hpp"
|
2023-06-11 14:47:13 -04:00
|
|
|
#include "ui_transmitter.hpp"
|
2022-04-03 19:38:06 -04:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
2023-06-17 16:01:46 -04:00
|
|
|
#include <vector>
|
2022-04-03 19:38:06 -04:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
class PlaylistView : public View {
|
2023-05-18 16:16:05 -04:00
|
|
|
public:
|
|
|
|
PlaylistView(NavigationView& nav);
|
|
|
|
~PlaylistView();
|
|
|
|
|
2023-06-17 16:01:46 -04:00
|
|
|
// Disable copy to make -Weffc++ happy.
|
|
|
|
PlaylistView(const PlaylistView&) = delete;
|
|
|
|
PlaylistView& operator=(const PlaylistView&) = delete;
|
2023-05-25 16:07:27 -04:00
|
|
|
|
2023-06-17 16:01:46 -04:00
|
|
|
void set_parent_rect(Rect new_parent_rect) override;
|
|
|
|
void on_hide() override;
|
2023-05-18 16:16:05 -04:00
|
|
|
void focus() override;
|
|
|
|
|
|
|
|
std::string title() const override { return "Playlist"; };
|
|
|
|
|
|
|
|
private:
|
|
|
|
NavigationView& nav_;
|
2023-06-14 03:57:20 -04:00
|
|
|
TxRadioState radio_state_{};
|
2023-06-11 14:47:13 -04:00
|
|
|
app_settings::SettingsManager settings_{
|
|
|
|
"tx_playlist", app_settings::Mode::TX};
|
2023-05-18 16:16:05 -04:00
|
|
|
|
2023-06-17 16:01:46 -04:00
|
|
|
// More header == less spectrum view.
|
2023-06-12 01:25:25 -04:00
|
|
|
static constexpr ui::Dim header_height = 4 * 16;
|
2023-06-17 16:01:46 -04:00
|
|
|
static constexpr uint32_t baseband_bandwidth = 2500000;
|
2023-05-18 16:16:05 -04:00
|
|
|
|
|
|
|
struct playlist_entry {
|
|
|
|
rf::Frequency replay_frequency{0};
|
2023-06-17 16:01:46 -04:00
|
|
|
std::filesystem::path replay_file{};
|
2023-05-18 16:16:05 -04:00
|
|
|
uint32_t sample_rate{};
|
2023-06-17 16:01:46 -04:00
|
|
|
uint32_t initial_delay{};
|
2023-05-18 16:16:05 -04:00
|
|
|
};
|
2023-06-17 16:01:46 -04:00
|
|
|
|
|
|
|
std::unique_ptr<ReplayThread> replay_thread_{};
|
|
|
|
bool ready_signal_{}; // Used to signal the ReplayThread.
|
|
|
|
|
|
|
|
size_t current_track_{0};
|
|
|
|
const playlist_entry* current_entry_{};
|
|
|
|
size_t current_entry_size_{0};
|
|
|
|
std::vector<playlist_entry> playlist_db_{};
|
|
|
|
std::filesystem::path playlist_path_{};
|
|
|
|
|
|
|
|
void load_file(const std::filesystem::path& path);
|
|
|
|
void on_file_changed(const std::filesystem::path& path);
|
|
|
|
void reset();
|
|
|
|
void show_file_error(
|
|
|
|
const std::filesystem::path& path,
|
|
|
|
const std::string& message);
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
bool is_active() const;
|
|
|
|
bool loop() const;
|
2023-06-17 16:01:46 -04:00
|
|
|
bool is_done() const;
|
|
|
|
|
|
|
|
void toggle();
|
|
|
|
void start();
|
|
|
|
bool next_track();
|
|
|
|
void send_current_track();
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
void update_ui();
|
|
|
|
|
|
|
|
/* There are called by Message handlers. */
|
|
|
|
void on_tx_progress(uint32_t progress);
|
|
|
|
void handle_replay_thread_done(uint32_t return_code);
|
2023-05-18 16:16:05 -04:00
|
|
|
|
|
|
|
Button button_open{
|
|
|
|
{0 * 8, 0 * 16, 10 * 8, 2 * 16},
|
2023-06-17 16:01:46 -04:00
|
|
|
"Open PPL"};
|
2023-05-18 16:16:05 -04:00
|
|
|
|
|
|
|
Text text_filename{
|
2023-06-17 16:01:46 -04:00
|
|
|
{11 * 8, 0 * 16, 12 * 8, 16}};
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
Text text_sample_rate{
|
2023-06-17 16:01:46 -04:00
|
|
|
{24 * 8, 0 * 16, 6 * 8, 16}};
|
2023-05-18 16:16:05 -04:00
|
|
|
|
|
|
|
Text text_duration{
|
2023-06-17 16:01:46 -04:00
|
|
|
{11 * 8, 1 * 16, 6 * 8, 16}};
|
|
|
|
|
|
|
|
ProgressBar progressbar_track{
|
2023-06-11 12:22:15 -04:00
|
|
|
{18 * 8, 1 * 16, 12 * 8, 8}};
|
|
|
|
|
2023-06-17 16:01:46 -04:00
|
|
|
ProgressBar progressbar_transmit{
|
2023-06-11 12:22:15 -04:00
|
|
|
{18 * 8, 3 * 8, 12 * 8, 8}};
|
2023-05-18 16:16:05 -04:00
|
|
|
|
2023-06-17 16:01:46 -04:00
|
|
|
Text text_frequency{
|
|
|
|
{0 * 8, 2 * 16, 9 * 8, 16}};
|
2023-05-18 16:16:05 -04:00
|
|
|
|
|
|
|
TransmitterView2 tx_view{
|
2023-06-17 16:01:46 -04:00
|
|
|
74, 1 * 8, SHORT_UI // x(columns), y (line) position.
|
2023-05-18 16:16:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
Checkbox check_loop{
|
|
|
|
{21 * 8, 2 * 16},
|
|
|
|
4,
|
|
|
|
"Loop",
|
|
|
|
true};
|
2023-06-17 16:01:46 -04:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
ImageButton button_play{
|
|
|
|
{28 * 8, 2 * 16, 2 * 8, 1 * 16},
|
|
|
|
&bitmap_play,
|
|
|
|
Color::green(),
|
|
|
|
Color::black()};
|
2023-06-12 01:25:25 -04:00
|
|
|
|
|
|
|
Text text_track{
|
2023-06-17 16:01:46 -04:00
|
|
|
{0 * 8, 3 * 16, 30 * 8, 16}};
|
2023-05-18 16:16:05 -04:00
|
|
|
|
|
|
|
spectrum::WaterfallWidget waterfall{};
|
|
|
|
|
|
|
|
MessageHandlerRegistration message_handler_replay_thread_error{
|
|
|
|
Message::ID::ReplayThreadDone,
|
2023-06-17 16:01:46 -04:00
|
|
|
[this](const Message* p) {
|
|
|
|
auto message = *reinterpret_cast<const ReplayThreadDoneMessage*>(p);
|
|
|
|
handle_replay_thread_done(message.return_code);
|
2023-05-18 16:16:05 -04:00
|
|
|
}};
|
|
|
|
|
|
|
|
MessageHandlerRegistration message_handler_fifo_signal{
|
|
|
|
Message::ID::RequestSignal,
|
2023-06-17 16:01:46 -04:00
|
|
|
[this](const Message* p) {
|
|
|
|
auto message = static_cast<const RequestSignalMessage*>(p);
|
2023-05-18 16:16:05 -04:00
|
|
|
if (message->signal == RequestSignalMessage::Signal::FillRequest) {
|
2023-06-17 16:01:46 -04:00
|
|
|
ready_signal_ = true;
|
2023-05-18 16:16:05 -04:00
|
|
|
}
|
|
|
|
}};
|
|
|
|
|
|
|
|
MessageHandlerRegistration message_handler_tx_progress{
|
|
|
|
Message::ID::TXProgress,
|
2023-06-17 16:01:46 -04:00
|
|
|
[this](const Message* p) {
|
|
|
|
auto message = *reinterpret_cast<const TXProgressMessage*>(p);
|
|
|
|
on_tx_progress(message.progress);
|
2023-05-18 16:16:05 -04:00
|
|
|
}};
|
2022-04-03 19:38:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace ui */
|