Merge pull request #174 from ITAxReal/ax_fork

SoundBoard App Improvements
This commit is contained in:
Erwin Ried 2020-09-14 22:46:00 +02:00 committed by GitHub
commit 1a94f4a1ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 66 additions and 17 deletions

View File

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

View File

@ -58,6 +58,8 @@ private:
tx_modes tx_mode = NORMAL; tx_modes tx_mode = NORMAL;
uint32_t playing_id { }; uint32_t playing_id { };
uint32_t page = 1;
uint32_t c_page = 1;
std::vector<std::filesystem::path> file_list { }; std::vector<std::filesystem::path> file_list { };
@ -83,7 +85,21 @@ private:
//{ { 0, 20 * 8 + 4 }, "Title:", Color::light_grey() }, //{ { 0, 20 * 8 + 4 }, "Title:", Color::light_grey() },
{ { 0, 180 }, "Key:", Color::light_grey() } { { 0, 180 }, "Key:", Color::light_grey() }
}; };
Button button_next_page {
{ 30 * 7, 25 * 8, 10 * 3, 2 * 14 },
"=>"
};
Button button_prev_page {
{ 17 * 10, 25 * 8, 10 * 3, 2 * 14 },
"<="
};
Text page_info {
{ 0, 30 * 8 - 4, 30 * 8, 16 }
};
MenuView menu_view { MenuView menu_view {
{ 0, 0, 240, 175 }, { 0, 0, 240, 175 },
true true
@ -114,14 +130,14 @@ private:
}; };
Checkbox check_random { Checkbox check_random {
{ 10 * 8, 25 * 8 + 4 }, { 10 * 7, 25 * 8 + 4 },
6, 6,
"Random" "Random"
}; };
ProgressBar progressbar { //ProgressBar progressbar {
{ 0 * 8, 30 * 8 - 4, 30 * 8, 16 } // { 0 * 8, 30 * 8 - 4, 30 * 8, 16 }
}; //};
TransmitterView tx_view { TransmitterView tx_view {
16 * 16, 16 * 16,