WAV viewer tweaks (#1854)

This commit is contained in:
Mark Thompson 2024-02-07 02:15:46 -06:00 committed by GitHub
parent 0370b4eb55
commit e854261124
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 8 deletions

View File

@ -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);
});
};
};

View File

@ -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};