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-25 14:40:19 -04:00
|
|
|
#include "bitmap.hpp"
|
|
|
|
#include "file.hpp"
|
|
|
|
#include "metadata_file.hpp"
|
2023-06-14 03:57:20 -04:00
|
|
|
#include "radio_state.hpp"
|
2023-06-25 14:40:19 -04:00
|
|
|
#include "replay_thread.hpp"
|
2022-04-03 19:38:06 -04:00
|
|
|
#include "ui_navigation.hpp"
|
|
|
|
#include "ui_receiver.hpp"
|
|
|
|
#include "ui_spectrum.hpp"
|
2023-06-11 14:47:13 -04:00
|
|
|
#include "ui_transmitter.hpp"
|
2023-06-25 14:40:19 -04:00
|
|
|
#include "ui_widget.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
|
|
|
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-25 14:40:19 -04:00
|
|
|
static constexpr ui::Dim header_height = 6 * 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 {
|
2023-06-25 14:40:19 -04:00
|
|
|
std::filesystem::path path{};
|
|
|
|
capture_metadata metadata{};
|
|
|
|
File::Size file_size{};
|
|
|
|
uint32_t ms_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.
|
|
|
|
|
2023-06-25 14:40:19 -04:00
|
|
|
size_t current_index_{0};
|
|
|
|
bool playlist_dirty_{};
|
2023-06-17 16:01:46 -04:00
|
|
|
std::vector<playlist_entry> playlist_db_{};
|
|
|
|
std::filesystem::path playlist_path_{};
|
|
|
|
|
|
|
|
void load_file(const std::filesystem::path& path);
|
2023-06-25 14:40:19 -04:00
|
|
|
Optional<playlist_entry> load_entry(std::filesystem::path&& path);
|
2023-06-17 16:01:46 -04:00
|
|
|
void on_file_changed(const std::filesystem::path& path);
|
2023-06-25 14:40:19 -04:00
|
|
|
void open_file(bool prompt_save = true);
|
|
|
|
void save_file(bool show_dialogs = true);
|
|
|
|
void add_entry(std::filesystem::path&& path);
|
|
|
|
void delete_entry();
|
2023-06-17 16:01:46 -04:00
|
|
|
void reset();
|
|
|
|
void show_file_error(
|
|
|
|
const std::filesystem::path& path,
|
|
|
|
const std::string& message);
|
|
|
|
|
2023-06-26 13:44:01 -04:00
|
|
|
playlist_entry* current();
|
2023-06-25 14:40:19 -04:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
bool is_active() const;
|
2023-06-25 14:40:19 -04:00
|
|
|
bool at_end() const;
|
2023-06-17 16:01:46 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
Text text_filename{
|
2023-06-25 14:40:19 -04:00
|
|
|
{0 * 8, 0 * 16, 30 * 8, 16}};
|
2023-06-17 16:01:46 -04:00
|
|
|
|
2023-06-26 13:44:01 -04:00
|
|
|
FrequencyField field_frequency{
|
|
|
|
{0 * 8, 1 * 16}};
|
2023-05-18 16:16:05 -04:00
|
|
|
|
2023-06-25 14:40:19 -04:00
|
|
|
Text text_sample_rate{
|
|
|
|
{10 * 8, 1 * 16, 7 * 8, 16}};
|
2023-06-17 16:01:46 -04:00
|
|
|
|
|
|
|
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-25 14:40:19 -04:00
|
|
|
Text text_duration{
|
|
|
|
{0 * 8, 2 * 16, 5 * 8, 16}};
|
2023-05-18 16:16:05 -04:00
|
|
|
|
2023-06-26 13:44:01 -04:00
|
|
|
// TODO: delay duration field.
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
TransmitterView2 tx_view{
|
2023-06-25 14:40:19 -04:00
|
|
|
9 * 8, 1 * 8, SHORT_UI};
|
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
|
|
|
|
2023-06-25 14:40:19 -04:00
|
|
|
NewButton button_prev{
|
|
|
|
{0 * 8, 4 * 16, 4 * 8, 2 * 16},
|
|
|
|
"",
|
|
|
|
&bitmap_arrow_left,
|
|
|
|
Color::dark_grey()};
|
|
|
|
|
|
|
|
NewButton button_add{
|
|
|
|
{6 * 8, 4 * 16, 4 * 8, 2 * 16},
|
|
|
|
"",
|
|
|
|
&bitmap_icon_new_file,
|
|
|
|
Color::orange()};
|
|
|
|
|
|
|
|
NewButton button_delete{
|
|
|
|
{10 * 8, 4 * 16, 4 * 8, 2 * 16},
|
|
|
|
"",
|
|
|
|
&bitmap_icon_delete,
|
|
|
|
Color::orange()};
|
|
|
|
|
|
|
|
NewButton button_open{
|
|
|
|
{16 * 8, 4 * 16, 4 * 8, 2 * 16},
|
|
|
|
"",
|
|
|
|
&bitmap_icon_load,
|
|
|
|
Color::dark_blue()};
|
|
|
|
|
|
|
|
NewButton button_save{
|
|
|
|
{20 * 8, 4 * 16, 4 * 8, 2 * 16},
|
|
|
|
"",
|
|
|
|
&bitmap_icon_save,
|
|
|
|
Color::dark_blue()};
|
|
|
|
|
|
|
|
NewButton button_next{
|
|
|
|
{26 * 8, 4 * 16, 4 * 8, 2 * 16},
|
|
|
|
"",
|
|
|
|
&bitmap_arrow_right,
|
|
|
|
Color::dark_grey()};
|
|
|
|
|
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 */
|