From e854261124a0042fc16332d9f65a029604125810 Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Wed, 7 Feb 2024 02:15:46 -0600 Subject: [PATCH] WAV viewer tweaks (#1854) --- firmware/application/apps/ui_view_wav.cpp | 25 +++++++++++++++++++---- firmware/application/apps/ui_view_wav.hpp | 10 +++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/firmware/application/apps/ui_view_wav.cpp b/firmware/application/apps/ui_view_wav.cpp index 5d8d10a3..617b7ac0 100644 --- a/firmware/application/apps/ui_view_wav.cpp +++ b/firmware/application/apps/ui_view_wav.cpp @@ -38,6 +38,13 @@ void ViewWavView::update_scale(int32_t new_scale) { } void ViewWavView::refresh_waveform() { + // NB: We can't read from the file to update the waveform when playback is in progress, so defer til playback done. + // (This only happens if the user messes with position or scale fields while playback is occurring) + if (playback_in_progress) { + waveform_update_needed = true; + return; + } + uint8_t bits_per_sample = wav_reader->bits_per_sample(); for (size_t i = 0; i < 240; i++) { @@ -151,6 +158,10 @@ void ViewWavView::reset_controls() { field_pos_samples.set_value(0); field_cursor_a.set_value(0); field_cursor_b.set_value(0); + field_pos_seconds.set_range(0, wav_reader->ms_duration() / 1000); + field_pos_milliseconds.set_range(0, (wav_reader->ms_duration() < 1000) ? wav_reader->ms_duration() % 1000 : 999); + field_pos_samples.set_range(0, wav_reader->sample_count() - 1); + field_scale.set_range(1, std::min(99999ul, wav_reader->sample_count() / 240)); } bool ViewWavView::is_active() { @@ -175,6 +186,13 @@ void ViewWavView::handle_replay_thread_done(const uint32_t return_code) { if (return_code == ReplayThread::READ_ERROR) file_error(); + + // Playback complete - now it's safe to update waveform view + playback_in_progress = false; + if (waveform_update_needed) { + waveform_update_needed = false; + refresh_waveform(); + } } void ViewWavView::set_ready() { @@ -198,6 +216,8 @@ void ViewWavView::start_playback() { return; } + playback_in_progress = true; + button_play.set_bitmap(&bitmap_stop); sample_rate = reader->sample_rate(); @@ -234,6 +254,7 @@ void ViewWavView::start_playback() { void ViewWavView::on_playback_progress(const uint32_t progress) { progressbar.set_value(progress); + field_pos_samples.set_value(progress); } ViewWavView::ViewWavView( @@ -278,10 +299,6 @@ ViewWavView::ViewWavView( } load_wav(file_path); field_pos_seconds.focus(); - field_pos_seconds.set_range(0, wav_reader->ms_duration() / 1000); - field_pos_milliseconds.set_range(0, (wav_reader->ms_duration() < 1000) ? wav_reader->ms_duration() % 1000 : 999); - field_pos_samples.set_range(0, wav_reader->sample_count() - 1); - field_scale.set_range(1, wav_reader->sample_count() / 240); }); }; }; diff --git a/firmware/application/apps/ui_view_wav.hpp b/firmware/application/apps/ui_view_wav.hpp index 0d02951f..46febabe 100644 --- a/firmware/application/apps/ui_view_wav.hpp +++ b/firmware/application/apps/ui_view_wav.hpp @@ -76,13 +76,15 @@ class ViewWavView : public View { uint64_t ns_per_pixel{}; uint64_t position{}; bool updating_position{false}; + bool playback_in_progress{false}; + bool waveform_update_needed{false}; Labels labels{ {{0 * 8, 0 * 16}, "File:", Color::light_grey()}, {{2 * 8, 1 * 16}, "-bit mono", Color::light_grey()}, {{0 * 8, 2 * 16}, "Title:", Color::light_grey()}, {{0 * 8, 3 * 16}, "Duration:", Color::light_grey()}, - {{0 * 8, 12 * 16}, "Position: . s Scale:", Color::light_grey()}, + {{0 * 8, 12 * 16}, "Position: . s Scale:", Color::light_grey()}, {{0 * 8, 13 * 16}, " Sample:", Color::light_grey()}, {{0 * 8, 14 * 16}, "Cursor A:", Color::dark_cyan()}, {{0 * 8, 15 * 16}, "Cursor B:", Color::dark_magenta()}, @@ -148,9 +150,9 @@ class ViewWavView : public View { '0', true}; NumberField field_scale{ - {26 * 8, 12 * 16}, - 4, - {1, 9999}, + {25 * 8, 12 * 16}, + 5, + {1, 1}, 1, ' ', true};