Skip to content

Commit

Permalink
fix lyrics not cleared after switching song
Browse files Browse the repository at this point in the history
  • Loading branch information
feois committed Jun 25, 2024
1 parent dc95431 commit beabbc1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/lyrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub trait LyricsTrait {
type Error;

fn new(layout: LyricsLayout) -> std::result::Result<Self, Self::Error> where Self: Sized;
fn begin(&mut self, _lyrics: impl IntoIterator<Item = (Duration, String)>) -> Result<(), Self::Error> { Ok(()) }
fn end(&mut self) -> Result<(), Self::Error> { Ok(()) }
fn set_lyrics(&mut self, _lyrics: impl IntoIterator<Item = (Duration, String)>) -> Result<(), Self::Error> { Ok(()) }
fn clear(&mut self) -> Result<(), Self::Error> { Ok(()) }
fn update(&mut self, _time: Duration) -> Result<(), Self::Error> { Ok(()) }
fn set_layout(&mut self, _layout: LyricsLayout) -> Result<(), Self::Error> { Ok(()) }
}
Expand Down Expand Up @@ -198,7 +198,7 @@ mod xosd {
}

#[inline(always)]
fn begin(&mut self, lyrics: impl IntoIterator<Item = (Duration, String)>) -> Result<()> {
fn set_lyrics(&mut self, lyrics: impl IntoIterator<Item = (Duration, String)>) -> Result<()> {
self.lines = lyrics.into_iter().collect();
self.lines.sort_by_key(|&(t, _)| t);
self.index = Some(0);
Expand All @@ -208,7 +208,7 @@ mod xosd {
}

#[inline(always)]
fn end(&mut self) -> Result<()> {
fn clear(&mut self) -> Result<()> {
self.index = None;
self.update_text()?;

Expand Down
19 changes: 10 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl App {

println!("STATUS: Idle");

app.end_lyrics();
app.clear_lyrics();
}
}
_ => {}
Expand Down Expand Up @@ -307,7 +307,7 @@ impl App {
self.request_duration = true;
self.show_lyrics(song);
}
"STOP" => { self.player.stop(); self.end_lyrics() }
"STOP" => { self.player.stop(); self.clear_lyrics() }
"REPLAY" => if let Some(song) = self.playlist.get_history().get_current().cloned() { self.play(&song) }
"PREV" => if let Some(song) = self.playlist.look_back() { self.play(&song); }
"SKIP" => self.player.skip(),
Expand Down Expand Up @@ -382,7 +382,7 @@ impl App {
if comb == self.stop_player {
["STOP"].gui_write_if(self);
self.player.stop();
self.end_lyrics();
self.clear_lyrics();
}

if comb == self.volume_increase {
Expand Down Expand Up @@ -596,23 +596,24 @@ impl App {
match Tag::read_from_path(path) {
Ok(tag) => {
if let Some(l) = tag.synchronised_lyrics().find(|l| l.lang == "eng") {
if let Err(e) = lyrics.begin(l.content.iter().map(|(t, s)| (Duration::from_millis((*t).into()), s.clone()))) {
if let Err(e) = lyrics.set_lyrics(l.content.iter().map(|(t, s)| (Duration::from_millis((*t).into()), s.clone()))) {
println!("RUST-ERROR: Failed to display lyrics {}", e)
}
}
else {
self.clear_lyrics();
}
}
Err(e) => println!("RUST-ERROR: Failed to read tag from {} ({})", path, e)
}
}
}

#[inline(always)]
fn end_lyrics(&mut self) {
println!("ended");

fn clear_lyrics(&mut self) {
if let Some(lyrics) = &mut self.lyrics {
if let Err(e) = lyrics.end() {
println!("RUST-ERROR: Failed to reset lyrics {}", e)
if let Err(e) = lyrics.clear() {
println!("RUST-ERROR: Failed to clear lyrics {}", e)
}
}
}
Expand Down

0 comments on commit beabbc1

Please sign in to comment.