From e9a3047f00bd3405ddf1fc2f20e2d355f6502b7f Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Sun, 28 Apr 2024 10:50:20 +0100 Subject: [PATCH] Improve logging and FadeCurve generation. Tidy. --- app/classes.py | 18 ++++++++++-------- app/playlistmodel.py | 10 ++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/classes.py b/app/classes.py index 5372927..eb1ba0d 100644 --- a/app/classes.py +++ b/app/classes.py @@ -13,6 +13,7 @@ from sqlalchemy.orm import scoped_session # App imports from config import Config +from log import log from models import PlaylistRows import helpers @@ -29,6 +30,7 @@ class FadeCurve: audio = helpers.get_audio_segment(track_path) if not audio: + log.error(f"FadeCurve: could not get audio for {track_path=}") return None # Start point of curve is Config.FADE_CURVE_MS_BEFORE_FADE @@ -116,7 +118,7 @@ class PlaylistTrack: self.end_time: Optional[dt.datetime] = None self.fade_at: Optional[int] = None self.fade_graph: Optional[FadeCurve] = None - self.fade_graph_start_updates: Optional[datetime] = None + self.fade_graph_start_updates: Optional[dt.datetime] = None self.fade_length: Optional[int] = None self.path: Optional[str] = None self.playlist_id: Optional[int] = None @@ -163,7 +165,6 @@ class PlaylistTrack: self.fade_length = track.silence_at - track.fade_at # Initialise and add FadeCurve in a thread as it's slow - # Import in separate thread self.fadecurve_thread = QThread() self.worker = AddFadeCurve( self, @@ -197,10 +198,9 @@ class PlaylistTrack: milliseconds=update_graph_at_ms ) - # Calculate time fade_graph should start updating - if self.fade_at: + # Calculate time fade_graph should start updating update_graph_at_ms = max(0, self.fade_at - Config.FADE_CURVE_MS_BEFORE_FADE - 1) - self.fade_graph_start_updates = now + timedelta(milliseconds=update_graph_at_ms) + self.fade_graph_start_updates = now + dt.timedelta(milliseconds=update_graph_at_ms) class AddFadeCurve(QObject): @@ -229,9 +229,11 @@ class AddFadeCurve(QObject): Create fade curve and add to PlaylistTrack object """ - self.playlist_track.fade_graph = FadeCurve( - self.track_path, self.track_fade_at, self.track_silence_at - ) + fc = FadeCurve(self.track_path, self.track_fade_at, self.track_silence_at) + if not fc: + log.error(f"Failed to create FadeCurve for {self.track_path=}") + else: + self.playlist_track.fade_graph = fc self.finished.emit() diff --git a/app/playlistmodel.py b/app/playlistmodel.py index 81080f0..9ad063d 100644 --- a/app/playlistmodel.py +++ b/app/playlistmodel.py @@ -1240,9 +1240,19 @@ class PlaylistModel(QAbstractTableModel): if plr: # Check this isn't a header row if self.is_header_row(row_number): + log.error( + "Tried to set next row on header row: " + f"playlistmodel.set_next_track({row_number=}, " + f"{self.playlist_id=}" + ) return # Check track is readable if file_is_unreadable(plr.track.path): + log.error( + "Tried to set next row on unreadable row: " + f"playlistmodel.set_next_track({row_number=}, " + f"{self.playlist_id=}" + ) return track_sequence.next.set_plr(session, plr) self.signals.next_track_changed_signal.emit()