2022-04-03 23:38:06 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
* Copyright (C) 2016 Furrtek
|
2023-06-17 20:01:46 +00:00
|
|
|
* Copyright (C) 2023 Kyle Reed, zxkmm
|
2022-04-03 23:38:06 +00: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 20:16:05 +00:00
|
|
|
#define SHORT_UI true
|
|
|
|
#define NORMAL_UI false
|
2022-04-03 23:38:06 +00:00
|
|
|
|
2023-06-11 18:47:13 +00:00
|
|
|
#include "app_settings.hpp"
|
2023-06-25 18:40:19 +00:00
|
|
|
#include "bitmap.hpp"
|
|
|
|
#include "file.hpp"
|
|
|
|
#include "metadata_file.hpp"
|
2023-06-14 07:57:20 +00:00
|
|
|
#include "radio_state.hpp"
|
2023-06-25 18:40:19 +00:00
|
|
|
#include "replay_thread.hpp"
|
2022-04-03 23:38:06 +00:00
|
|
|
#include "ui_navigation.hpp"
|
|
|
|
#include "ui_receiver.hpp"
|
|
|
|
#include "ui_spectrum.hpp"
|
2023-06-11 18:47:13 +00:00
|
|
|
#include "ui_transmitter.hpp"
|
2023-06-25 18:40:19 +00:00
|
|
|
#include "ui_widget.hpp"
|
2022-04-03 23:38:06 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
2023-06-17 20:01:46 +00:00
|
|
|
#include <vector>
|
2022-04-03 23:38:06 +00:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
class PlaylistView : public View {
|
2023-05-18 20:16:05 +00:00
|
|
|
public:
|
|
|
|
PlaylistView(NavigationView& nav);
|
2023-06-28 17:02:06 +00:00
|
|
|
PlaylistView(NavigationView& nav, const std::filesystem::path& path);
|
2023-05-18 20:16:05 +00:00
|
|
|
~PlaylistView();
|
|
|
|
|
2023-06-28 19:50:11 +00:00
|
|
|
// Following 2 called by 'NavigationView::update_view' after view is created.
|
2023-06-17 20:01:46 +00:00
|
|
|
void set_parent_rect(Rect new_parent_rect) override;
|
2023-06-28 19:50:11 +00:00
|
|
|
void focus() override;
|
2023-06-17 20:01:46 +00:00
|
|
|
void on_hide() override;
|
2023-05-18 20:16:05 +00:00
|
|
|
|
2023-06-28 17:02:06 +00:00
|
|
|
std::string title() const override { return "Replay"; };
|
2023-05-18 20:16:05 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
NavigationView& nav_;
|
2023-06-14 07:57:20 +00:00
|
|
|
TxRadioState radio_state_{};
|
2023-06-11 18:47:13 +00:00
|
|
|
app_settings::SettingsManager settings_{
|
|
|
|
"tx_playlist", app_settings::Mode::TX};
|
2023-05-18 20:16:05 +00:00
|
|
|
|
2023-06-17 20:01:46 +00:00
|
|
|
// More header == less spectrum view.
|
2023-06-25 18:40:19 +00:00
|
|
|
static constexpr ui::Dim header_height = 6 * 16;
|
2023-06-17 20:01:46 +00:00
|
|
|
static constexpr uint32_t baseband_bandwidth = 2500000;
|
2023-05-18 20:16:05 +00:00
|
|
|
|
|
|
|
struct playlist_entry {
|
2023-06-25 18:40:19 +00:00
|
|
|
std::filesystem::path path{};
|
|
|
|
capture_metadata metadata{};
|
|
|
|
File::Size file_size{};
|
|
|
|
uint32_t ms_delay{};
|
2023-05-18 20:16:05 +00:00
|
|
|
};
|
2023-06-17 20:01:46 +00:00
|
|
|
|
|
|
|
std::unique_ptr<ReplayThread> replay_thread_{};
|
|
|
|
bool ready_signal_{}; // Used to signal the ReplayThread.
|
|
|
|
|
2023-06-25 18:40:19 +00:00
|
|
|
size_t current_index_{0};
|
|
|
|
bool playlist_dirty_{};
|
2023-06-17 20:01:46 +00:00
|
|
|
std::vector<playlist_entry> playlist_db_{};
|
|
|
|
std::filesystem::path playlist_path_{};
|
|
|
|
|
|
|
|
void load_file(const std::filesystem::path& path);
|
2023-06-25 18:40:19 +00:00
|
|
|
Optional<playlist_entry> load_entry(std::filesystem::path&& path);
|
2023-06-17 20:01:46 +00:00
|
|
|
void on_file_changed(const std::filesystem::path& path);
|
2023-06-25 18:40:19 +00: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 20:01:46 +00:00
|
|
|
void reset();
|
|
|
|
void show_file_error(
|
|
|
|
const std::filesystem::path& path,
|
|
|
|
const std::string& message);
|
|
|
|
|
2023-06-26 17:44:01 +00:00
|
|
|
playlist_entry* current();
|
2023-06-25 18:40:19 +00:00
|
|
|
|
2023-05-18 20:16:05 +00:00
|
|
|
bool is_active() const;
|
2023-06-25 18:40:19 +00:00
|
|
|
bool at_end() const;
|
2023-06-17 20:01:46 +00: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 20:16:05 +00:00
|
|
|
|
|
|
|
Text text_filename{
|
2023-06-25 18:40:19 +00:00
|
|
|
{0 * 8, 0 * 16, 30 * 8, 16}};
|
2023-06-17 20:01:46 +00:00
|
|
|
|
2023-06-26 17:44:01 +00:00
|
|
|
FrequencyField field_frequency{
|
|
|
|
{0 * 8, 1 * 16}};
|
2023-05-18 20:16:05 +00:00
|
|
|
|
2023-06-25 18:40:19 +00:00
|
|
|
Text text_sample_rate{
|
|
|
|
{10 * 8, 1 * 16, 7 * 8, 16}};
|
2023-06-17 20:01:46 +00:00
|
|
|
|
2023-06-29 16:24:18 +00:00
|
|
|
/*v making there's 1px line (instead of two) between two progress bars,
|
|
|
|
* by letting 1px overlapped.
|
|
|
|
* So, since they overlapped 1px, they are visually same, and looks better.
|
|
|
|
*/
|
|
|
|
|
2023-06-17 20:01:46 +00:00
|
|
|
ProgressBar progressbar_track{
|
2023-06-29 16:24:18 +00:00
|
|
|
{18 * 8, 1 * 16, 12 * 8, 8 + 1}};
|
2023-06-11 16:22:15 +00:00
|
|
|
|
2023-06-17 20:01:46 +00:00
|
|
|
ProgressBar progressbar_transmit{
|
2023-06-29 16:24:18 +00:00
|
|
|
{18 * 8, 3 * 8 - 1, 12 * 8, 8}};
|
2023-05-18 20:16:05 +00:00
|
|
|
|
2023-06-25 18:40:19 +00:00
|
|
|
Text text_duration{
|
|
|
|
{0 * 8, 2 * 16, 5 * 8, 16}};
|
2023-05-18 20:16:05 +00:00
|
|
|
|
2023-06-26 17:44:01 +00:00
|
|
|
// TODO: delay duration field.
|
|
|
|
|
2023-05-18 20:16:05 +00:00
|
|
|
TransmitterView2 tx_view{
|
2023-06-25 18:40:19 +00:00
|
|
|
9 * 8, 1 * 8, SHORT_UI};
|
2023-05-18 20:16:05 +00:00
|
|
|
|
|
|
|
Checkbox check_loop{
|
|
|
|
{21 * 8, 2 * 16},
|
|
|
|
4,
|
|
|
|
"Loop",
|
|
|
|
true};
|
2023-06-17 20:01:46 +00:00
|
|
|
|
2023-05-18 20:16:05 +00:00
|
|
|
ImageButton button_play{
|
|
|
|
{28 * 8, 2 * 16, 2 * 8, 1 * 16},
|
|
|
|
&bitmap_play,
|
|
|
|
Color::green(),
|
|
|
|
Color::black()};
|
2023-06-12 05:25:25 +00:00
|
|
|
|
|
|
|
Text text_track{
|
2023-06-17 20:01:46 +00:00
|
|
|
{0 * 8, 3 * 16, 30 * 8, 16}};
|
2023-05-18 20:16:05 +00:00
|
|
|
|
2023-06-25 18:40:19 +00:00
|
|
|
NewButton button_prev{
|
2023-06-28 17:02:06 +00:00
|
|
|
{2 * 8, 4 * 16, 4 * 8, 2 * 16},
|
2023-06-25 18:40:19 +00:00
|
|
|
"",
|
|
|
|
&bitmap_arrow_left,
|
|
|
|
Color::dark_grey()};
|
|
|
|
|
2023-06-28 17:02:06 +00:00
|
|
|
NewButton button_next{
|
2023-06-25 18:40:19 +00:00
|
|
|
{6 * 8, 4 * 16, 4 * 8, 2 * 16},
|
|
|
|
"",
|
2023-06-28 17:02:06 +00:00
|
|
|
&bitmap_arrow_right,
|
|
|
|
Color::dark_grey()};
|
|
|
|
|
|
|
|
NewButton button_add{
|
|
|
|
{11 * 8, 4 * 16, 4 * 8, 2 * 16},
|
|
|
|
"",
|
2023-06-25 18:40:19 +00:00
|
|
|
&bitmap_icon_new_file,
|
|
|
|
Color::orange()};
|
|
|
|
|
|
|
|
NewButton button_delete{
|
2023-06-28 17:02:06 +00:00
|
|
|
{15 * 8, 4 * 16, 4 * 8, 2 * 16},
|
2023-06-25 18:40:19 +00:00
|
|
|
"",
|
|
|
|
&bitmap_icon_delete,
|
|
|
|
Color::orange()};
|
|
|
|
|
|
|
|
NewButton button_open{
|
2023-06-28 17:02:06 +00:00
|
|
|
{20 * 8, 4 * 16, 4 * 8, 2 * 16},
|
2023-06-25 18:40:19 +00:00
|
|
|
"",
|
|
|
|
&bitmap_icon_load,
|
|
|
|
Color::dark_blue()};
|
|
|
|
|
|
|
|
NewButton button_save{
|
2023-06-28 17:02:06 +00:00
|
|
|
{24 * 8, 4 * 16, 4 * 8, 2 * 16},
|
2023-06-25 18:40:19 +00:00
|
|
|
"",
|
|
|
|
&bitmap_icon_save,
|
|
|
|
Color::dark_blue()};
|
|
|
|
|
2023-06-30 05:34:19 +00:00
|
|
|
spectrum::WaterfallView waterfall{};
|
2023-05-18 20:16:05 +00:00
|
|
|
|
|
|
|
MessageHandlerRegistration message_handler_replay_thread_error{
|
|
|
|
Message::ID::ReplayThreadDone,
|
2023-06-17 20:01:46 +00:00
|
|
|
[this](const Message* p) {
|
|
|
|
auto message = *reinterpret_cast<const ReplayThreadDoneMessage*>(p);
|
|
|
|
handle_replay_thread_done(message.return_code);
|
2023-05-18 20:16:05 +00:00
|
|
|
}};
|
|
|
|
|
|
|
|
MessageHandlerRegistration message_handler_fifo_signal{
|
|
|
|
Message::ID::RequestSignal,
|
2023-06-17 20:01:46 +00:00
|
|
|
[this](const Message* p) {
|
|
|
|
auto message = static_cast<const RequestSignalMessage*>(p);
|
2023-05-18 20:16:05 +00:00
|
|
|
if (message->signal == RequestSignalMessage::Signal::FillRequest) {
|
2023-06-17 20:01:46 +00:00
|
|
|
ready_signal_ = true;
|
2023-05-18 20:16:05 +00:00
|
|
|
}
|
|
|
|
}};
|
|
|
|
|
|
|
|
MessageHandlerRegistration message_handler_tx_progress{
|
|
|
|
Message::ID::TXProgress,
|
2023-06-17 20:01:46 +00:00
|
|
|
[this](const Message* p) {
|
|
|
|
auto message = *reinterpret_cast<const TXProgressMessage*>(p);
|
|
|
|
on_tx_progress(message.progress);
|
2023-05-18 20:16:05 +00:00
|
|
|
}};
|
2022-04-03 23:38:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace ui */
|