Improved SoundBoard app:

* No device freeze when you try to close app while it's transmitting
* Bypassed 100 .wav files limit by implementing paging functionality
* Removed useless progressbar and implemented page info line instead
This commit is contained in:
ITAxReal 2020-08-28 21:47:56 +03:00
parent 3425ca8d54
commit e466c14c88
2 changed files with 51 additions and 16 deletions

View File

@ -48,7 +48,7 @@ void SoundBoardView::stop() {
void SoundBoardView::handle_replay_thread_done(const uint32_t return_code) {
stop();
progressbar.set_value(0);
//progressbar.set_value(0);
if (return_code == ReplayThread::END_OF_FILE) {
if (check_random.value()) {
@ -90,7 +90,7 @@ void SoundBoardView::start_tx(const uint32_t id) {
playing_id = id;
progressbar.set_max(reader->sample_count());
//progressbar.set_max(reader->sample_count());
//button_play.set_bitmap(&bitmap_stop);
@ -130,7 +130,7 @@ void SoundBoardView::start_tx(const uint32_t id) {
}*/
void SoundBoardView::on_tx_progress(const uint32_t progress) {
progressbar.set_value(progress);
//progressbar.set_value(progress);
}
void SoundBoardView::on_select_entry() {
@ -141,8 +141,10 @@ void SoundBoardView::refresh_list() {
auto reader = std::make_unique<WAVFileReader>();
file_list.clear();
uint32_t c_page = page;
// List directories and files, put directories up top
uint32_t count = 0;
for (const auto& entry : std::filesystem::directory_iterator(u"WAV", u"*")) {
if (std::filesystem::is_regular_file(entry.status())) {
if (entry.path().string().length()) {
@ -158,21 +160,32 @@ void SoundBoardView::refresh_list() {
if ((reader->channels() == 1) && (reader->bits_per_sample() == 8)) {
//sounds[c].ms_duration = reader->ms_duration();
//sounds[c].path = u"WAV/" + entry.path().native();
file_list.push_back(entry.path());
if (file_list.size() == 100)
break;
if (count >= (page - 1) * 100 && count < page * 100){
file_list.push_back(entry.path());
if (file_list.size() == 100){
page++;
break;
}
}
count++;
}
}
}
}
}
}
if (!file_list.size()) {
// Hide widgets, show warning
menu_view.hidden(true);
text_empty.hidden(false);
set_dirty();
if (page == 1){
menu_view.hidden(true);
text_empty.hidden(false);
set_dirty();
}else{
page = 1;
refresh_list();
return;
}
} else {
// Hide warning, show widgets
menu_view.hidden(false);
@ -191,9 +204,14 @@ void SoundBoardView::refresh_list() {
}
});
}
page_info.set("Page: " + to_string_dec_uint(c_page) + " Songs: " + to_string_dec_uint(file_list.size()));
menu_view.set_highlighted(0); // Refresh
}
if (file_list.size() < 100){
page = 1;
}
}
SoundBoardView::SoundBoardView(
@ -209,13 +227,19 @@ SoundBoardView::SoundBoardView(
&options_tone_key,
//&text_title,
//&text_duration,
&progressbar,
//&progressbar,
&page_info,
&check_loop,
&check_random,
&button_next_page,
&tx_view
});
refresh_list();
button_next_page.on_select = [this](Button&) {
this->refresh_list();
};
//text_title.set(to_string_dec_uint(file_list.size()));
@ -243,6 +267,7 @@ SoundBoardView::SoundBoardView(
}
SoundBoardView::~SoundBoardView() {
stop();
transmitter_model.disable();
baseband::shutdown();
}

View File

@ -58,6 +58,7 @@ private:
tx_modes tx_mode = NORMAL;
uint32_t playing_id { };
uint32_t page = 1;
std::vector<std::filesystem::path> file_list { };
@ -83,7 +84,16 @@ private:
//{ { 0, 20 * 8 + 4 }, "Title:", Color::light_grey() },
{ { 0, 180 }, "Key:", Color::light_grey() }
};
Button button_next_page {
{ 18 * 10, 25 * 8, 10 * 4, 2 * 16 },
"=>"
};
Text page_info {
{ 0, 30 * 8 - 4, 30 * 8, 16 }
};
MenuView menu_view {
{ 0, 0, 240, 175 },
true
@ -119,9 +129,9 @@ private:
"Random"
};
ProgressBar progressbar {
{ 0 * 8, 30 * 8 - 4, 30 * 8, 16 }
};
//ProgressBar progressbar {
// { 0 * 8, 30 * 8 - 4, 30 * 8, 16 }
//};
TransmitterView tx_view {
16 * 16,