fix for bad track count (#1069)

* fix for bad track count
* code format
* Thanks kallanreed for providing a more clear logic!
This commit is contained in:
zxkmm 2023-05-26 04:07:27 +08:00 committed by GitHub
parent 6b44a77ef6
commit 5bdf9363e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

View File

@ -146,13 +146,15 @@ void PlaylistView::toggle() {
track_number = 0; track_number = 0;
playlist_db.clear(); playlist_db.clear();
playlist_masterdb.clear(); playlist_masterdb.clear();
} else { } else { // Thanks kallanreed for providing this logic!
total_tracks = 0; total_tracks = 0;
track_number = 0; track_number = 0;
playlist_db.clear(); playlist_db.clear();
playlist_masterdb.clear(); playlist_masterdb.clear();
load_file(now_play_list_file); load_file(now_play_list_file);
start(); if (!playlist_db.empty()) {
start();
}
} }
} }
@ -207,7 +209,7 @@ void PlaylistView::stop(const bool do_loop) {
// Notes of the logic here in case if it needed to be changed in the future: // Notes of the logic here in case if it needed to be changed in the future:
// 1. check_loop.value() is for the LOOP checkbox // 1. check_loop.value() is for the LOOP checkbox
// 2. do_loop is a part of the replay thread, not a user - control thing. // 2. do_loop is a part of the replay thread, not a user - control thing.
// 3. when (total_tracks >= track_number) is true, it means that the current track is not the last track. // 3. when (total_tracks > track_number) is true, it means that the current track is not the last track.
// Thus, (do_loop && (total_tracks != track_number)) is for the case when the start() func were called with true AND not the last track. // Thus, (do_loop && (total_tracks != track_number)) is for the case when the start() func were called with true AND not the last track.
// Which means it do loop until the last track. // Which means it do loop until the last track.
@ -224,7 +226,7 @@ void PlaylistView::stop(const bool do_loop) {
button_play.set_bitmap(&bitmap_play); button_play.set_bitmap(&bitmap_play);
} }
} else if (!check_loop.value()) { } else if (!check_loop.value()) {
if (do_loop && (total_tracks >= track_number)) { if (do_loop && (total_tracks > track_number)) {
if (playlist_db.size() > 0) { if (playlist_db.size() > 0) {
start(); start();
} else { } else {
@ -316,7 +318,8 @@ void PlaylistView::on_hide() {
void PlaylistView::set_parent_rect(const Rect new_parent_rect) { void PlaylistView::set_parent_rect(const Rect new_parent_rect) {
View::set_parent_rect(new_parent_rect); View::set_parent_rect(new_parent_rect);
const ui::Rect waterfall_rect{0, header_height, new_parent_rect.width(), new_parent_rect.height() - header_height}; const ui::Rect waterfall_rect{0, header_height, new_parent_rect.width(),
new_parent_rect.height() - header_height};
waterfall.set_parent_rect(waterfall_rect); waterfall.set_parent_rect(waterfall_rect);
} }

View File

@ -39,10 +39,13 @@ namespace ui {
class PlaylistView : public View { class PlaylistView : public View {
public: public:
PlaylistView(NavigationView& nav); PlaylistView(NavigationView& nav);
~PlaylistView(); ~PlaylistView();
void on_hide() override; void on_hide() override;
void set_parent_rect(const Rect new_parent_rect) override; void set_parent_rect(const Rect new_parent_rect) override;
void focus() override; void focus() override;
std::string title() const override { return "Playlist"; }; std::string title() const override { return "Playlist"; };
@ -66,15 +69,14 @@ class PlaylistView : public View {
static constexpr uint32_t baseband_bandwidth = 2500000; static constexpr uint32_t baseband_bandwidth = 2500000;
const size_t read_size{16384}; const size_t read_size{16384};
const size_t buffer_count{3}; const size_t buffer_count{3};
void load_file(std::filesystem::path playlist_path); void load_file(std::filesystem::path playlist_path);
void txtline_process(std::string&); void txtline_process(std::string&);
void on_file_changed(std::filesystem::path new_file_path, rf::Frequency replay_frequency, uint32_t replay_sample_rate); void on_file_changed(std::filesystem::path new_file_path, rf::Frequency replay_frequency, uint32_t replay_sample_rate);
void on_target_frequency_changed(rf::Frequency f); void on_target_frequency_changed(rf::Frequency f);
void on_tx_progress(const uint32_t progress); void on_tx_progress(const uint32_t progress);
void set_target_frequency(const rf::Frequency new_value); void set_target_frequency(const rf::Frequency new_value);
rf::Frequency target_frequency() const; rf::Frequency target_frequency() const;
void toggle(); void toggle();
void start(); void start();
void stop(const bool do_loop); void stop(const bool do_loop);
@ -87,8 +89,8 @@ class PlaylistView : public View {
std::filesystem::path file_path{}; std::filesystem::path file_path{};
std::unique_ptr<ReplayThread> replay_thread{}; std::unique_ptr<ReplayThread> replay_thread{};
bool ready_signal{false}; bool ready_signal{false};
int track_number{0}; size_t track_number{0};
int total_tracks{0}; size_t total_tracks{0};
std::filesystem::path now_play_list_file{}; std::filesystem::path now_play_list_file{};
Button button_open{ Button button_open{