Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gui: calculate queue time after receiving new Collection #96

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ Types of changes:

# Festival GUI Unreleased
## Added
- `QueueRepeat` mode to repeat queue but start paused ([#90](https://github.com/hinto-janai/festival/pull/90))
- `QueueRepeat` mode that repeats the queue but starts paused ([#90](https://github.com/hinto-janai/festival/pull/90))

## Fixed
* Queue tab: total runtime being `0 seconds` on restart ([#96](https://github.com/hinto-janai/festival/pull/96))


---
Expand Down
15 changes: 15 additions & 0 deletions gui/src/func/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ impl Gui {
// state keys are not referencing invalid keys.
self.state_restore
.update_state(&mut self.state, &self.collection);

// Update queue time.
self.calculate_and_set_queue_time();
}

// Sets the [`egui::Ui`]'s `Visual` from our current `Settings`
Expand Down Expand Up @@ -394,4 +397,16 @@ impl Gui {
None
}
}

/// Given the current [`AudioState`] queue, calculate the
/// total runtime and set the ephemeral state to reflect it.
pub fn calculate_and_set_queue_time(&mut self) {
self.queue_time = self
.audio_state
.queue
.iter()
.map(|k| self.collection.songs[k].runtime.inner() as u64)
.sum::<u64>()
.into();
}
}
8 changes: 1 addition & 7 deletions gui/src/ui/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,7 @@ impl eframe::App for Gui {
if self.kernel_returned && queue_diff &&
/* needed to prevent panic */ !self.resetting_collection
{
self.queue_time = self
.audio_state
.queue
.iter()
.map(|k| self.collection.songs[k].runtime.inner() as u64)
.sum::<u64>()
.into();
self.calculate_and_set_queue_time();
}
// Auto-save state.
if (self.kernel_returned && !self.resetting_collection)
Expand Down
Loading