diff --git a/firmware/application/apps/ui_playlist.cpp b/firmware/application/apps/ui_playlist.cpp index 7d1987ff..6259f6aa 100644 --- a/firmware/application/apps/ui_playlist.cpp +++ b/firmware/application/apps/ui_playlist.cpp @@ -146,13 +146,15 @@ void PlaylistView::toggle() { track_number = 0; playlist_db.clear(); playlist_masterdb.clear(); - } else { + } else { // Thanks kallanreed for providing this logic! total_tracks = 0; track_number = 0; playlist_db.clear(); playlist_masterdb.clear(); 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: // 1. check_loop.value() is for the LOOP checkbox // 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. // 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); } } else if (!check_loop.value()) { - if (do_loop && (total_tracks >= track_number)) { + if (do_loop && (total_tracks > track_number)) { if (playlist_db.size() > 0) { start(); } else { @@ -316,7 +318,8 @@ void PlaylistView::on_hide() { void PlaylistView::set_parent_rect(const 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); } diff --git a/firmware/application/apps/ui_playlist.hpp b/firmware/application/apps/ui_playlist.hpp index 84f7fbd1..d3c3807e 100644 --- a/firmware/application/apps/ui_playlist.hpp +++ b/firmware/application/apps/ui_playlist.hpp @@ -39,10 +39,13 @@ namespace ui { class PlaylistView : public View { public: PlaylistView(NavigationView& nav); + ~PlaylistView(); void on_hide() override; + void set_parent_rect(const Rect new_parent_rect) override; + void focus() override; std::string title() const override { return "Playlist"; }; @@ -66,15 +69,14 @@ class PlaylistView : public View { static constexpr uint32_t baseband_bandwidth = 2500000; const size_t read_size{16384}; const size_t buffer_count{3}; + void load_file(std::filesystem::path playlist_path); 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_target_frequency_changed(rf::Frequency f); void on_tx_progress(const uint32_t progress); - void set_target_frequency(const rf::Frequency new_value); rf::Frequency target_frequency() const; - void toggle(); void start(); void stop(const bool do_loop); @@ -87,8 +89,8 @@ class PlaylistView : public View { std::filesystem::path file_path{}; std::unique_ptr replay_thread{}; bool ready_signal{false}; - int track_number{0}; - int total_tracks{0}; + size_t track_number{0}; + size_t total_tracks{0}; std::filesystem::path now_play_list_file{}; Button button_open{