From d87927a7db5fc6dc2cf153acb24222c2de520448 Mon Sep 17 00:00:00 2001 From: G2-Games Date: Tue, 5 Dec 2023 08:19:10 -0600 Subject: [PATCH] Fixed an issue with CUE playback, fixed an issue with CUE file reading The CUE artist was being inserted as the Album title --- src/music_player.rs | 27 +++++++++++++++++---------- src/music_storage/music_db.rs | 5 ++++- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/music_player.rs b/src/music_player.rs index af42728..4f30286 100644 --- a/src/music_player.rs +++ b/src/music_player.rs @@ -73,8 +73,8 @@ impl Player { let end: Arc>> = Arc::new(RwLock::new(None)); let position_update = position.clone(); - let start_update = start.clone(); - let end_update = end.clone(); + let start_update = Arc::clone(&start); + let end_update = Arc::clone(&end); let (message_tx, message_rx) = bounded(1); std::thread::spawn(move || { loop { @@ -88,8 +88,6 @@ impl Player { && start_update.read().unwrap().is_some() && end_update.read().unwrap().is_some() { - if let Some(time) = *start_update.read().unwrap() { pos_temp = Some(pos_temp.unwrap() - time) } - let atf = end_update.read().unwrap().unwrap() - Duration::milliseconds(100); if pos_temp.unwrap() >= end_update.read().unwrap().unwrap() { message_tx.try_send(PlayerCmd::Eos).unwrap(); @@ -102,10 +100,16 @@ impl Player { *end_update.write().unwrap() = None; } else if pos_temp.unwrap() >= atf { match message_tx.try_send(PlayerCmd::AboutToFinish) { - Ok(_) => println!("Sent ATF"), - Err(err) => println!("{}", err), + Ok(_) => (), + Err(_) => (), } } + + // This has to be done AFTER the current time in the file + // is calculated, or everything else is wrong + if let Some(time) = *start_update.read().unwrap() { + pos_temp = Some(pos_temp.unwrap() - time) + } } *position_update.write().unwrap() = pos_temp; @@ -159,11 +163,14 @@ impl Player { self.pause().unwrap(); // Wait for it to be ready, and then move to the proper position - while self.playbin.read().unwrap().query_duration::().is_none() { + let now = std::time::Instant::now(); + while now.elapsed() < std::time::Duration::from_millis(20) { + if self.seek_to(Duration::from_std(*start).unwrap()).is_ok() { + return; + } std::thread::sleep(std::time::Duration::from_millis(1)); - }; - - self.seek_to(Duration::from_std(*start).unwrap()).unwrap(); + } + panic!("Couldn't seek to beginning of cue track in reasonable time (>20ms)"); }, _ => { self.playbin.write().unwrap().set_property("uri", source.as_uri()); diff --git a/src/music_storage/music_db.rs b/src/music_storage/music_db.rs index f66c8df..ec56547 100644 --- a/src/music_storage/music_db.rs +++ b/src/music_storage/music_db.rs @@ -149,6 +149,7 @@ impl Song { self.tags.get(target_key) } + /// Gets an internal field from a song pub fn get_field(&self, target_field: &str) -> Option { let lower_target = target_field.to_lowercase(); match lower_target.as_str() { @@ -164,10 +165,12 @@ impl Song { } } + /// Sets the value of a tag in the song pub fn set_tag(&mut self, target_key: Tag, new_value: String) { self.tags.insert(target_key, new_value); } + /// Deletes a tag from the song pub fn remove_tag(&mut self, target_key: &Tag) { self.tags.remove(target_key); } @@ -648,7 +651,7 @@ impl MusicLibrary { } match album_artist { Some(artist) => { - tags.insert(Tag::Album, artist.clone()); + tags.insert(Tag::Artist, artist.clone()); } None => (), }