WIP: playlist refacton: start/end times
Clean up function. If next track is above current track, flow start times around current track rather than resetting them at current track.
This commit is contained in:
parent
613fa4343b
commit
634637f42c
@ -1411,6 +1411,17 @@ class PlaylistTab(QTableWidget):
|
|||||||
|
|
||||||
return self.musicmuster.current_track.end_time
|
return self.musicmuster.current_track.end_time
|
||||||
|
|
||||||
|
def _get_current_track_start_time(self) -> Optional[datetime]:
|
||||||
|
"""
|
||||||
|
Return current track start time or None if no current track
|
||||||
|
"""
|
||||||
|
|
||||||
|
current_track_row = self._get_current_track_row_number()
|
||||||
|
if current_track_row is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return self.musicmuster.current_track.start_time
|
||||||
|
|
||||||
def _get_current_track_row_number(self) -> Optional[int]:
|
def _get_current_track_row_number(self) -> Optional[int]:
|
||||||
"""Return current track row or None"""
|
"""Return current track row or None"""
|
||||||
|
|
||||||
@ -2151,6 +2162,18 @@ class PlaylistTab(QTableWidget):
|
|||||||
|
|
||||||
return self._set_item_text(row, START_TIME, time_str)
|
return self._set_item_text(row, START_TIME, time_str)
|
||||||
|
|
||||||
|
def _set_row_times(self, row: int, start: datetime,
|
||||||
|
duration: int) -> datetime:
|
||||||
|
"""
|
||||||
|
Set row start and end times, return end time
|
||||||
|
"""
|
||||||
|
|
||||||
|
self._set_row_start_time(row, start)
|
||||||
|
end_time = self._calculate_end_time(start, duration)
|
||||||
|
self._set_row_end_time(row, end_time)
|
||||||
|
|
||||||
|
return end_time
|
||||||
|
|
||||||
def _set_row_title(self, row: int,
|
def _set_row_title(self, row: int,
|
||||||
title: Optional[str]) -> QTableWidgetItem:
|
title: Optional[str]) -> QTableWidgetItem:
|
||||||
"""
|
"""
|
||||||
@ -2236,11 +2259,11 @@ class PlaylistTab(QTableWidget):
|
|||||||
def _update_start_end_times(self) -> None:
|
def _update_start_end_times(self) -> None:
|
||||||
""" Update track start and end times """
|
""" Update track start and end times """
|
||||||
|
|
||||||
next_start_time = None
|
|
||||||
|
|
||||||
with Session() as session:
|
with Session() as session:
|
||||||
current_track_end_time = self._get_current_track_end_time()
|
current_track_end_time = self._get_current_track_end_time()
|
||||||
current_track_row = self._get_current_track_row_number()
|
current_track_row = self._get_current_track_row_number()
|
||||||
|
current_track_start_time = self._get_current_track_start_time()
|
||||||
|
next_start_time = None
|
||||||
next_track_row = self._get_next_track_row_number()
|
next_track_row = self._get_next_track_row_number()
|
||||||
played_rows = self._get_played_rows(session)
|
played_rows = self._get_played_rows(session)
|
||||||
|
|
||||||
@ -2251,60 +2274,52 @@ class PlaylistTab(QTableWidget):
|
|||||||
current_track_row, next_track_row]:
|
current_track_row, next_track_row]:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
a_track_row = self._get_row_track_id(row) > 0
|
# Get any timing from header row (that's all we need)
|
||||||
if not a_track_row:
|
if self._get_row_track_id(row) == 0:
|
||||||
note_time = self._get_section_start_time(session, row)
|
note_time = self._get_section_start_time(session, row)
|
||||||
if note_time:
|
if note_time:
|
||||||
next_start_time = note_time
|
next_start_time = note_time
|
||||||
# We have any timings from note; there's no track; go to
|
|
||||||
# next row
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Here means we have a track. Skip if track is
|
# We have a track. Skip if it is unreadable
|
||||||
# unreadable
|
|
||||||
if not file_is_readable(self._get_row_path(row)):
|
if not file_is_readable(self._get_row_path(row)):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Set next track start from end of current track
|
||||||
if row == next_track_row:
|
if row == next_track_row:
|
||||||
# If we have a current track, set this next track start
|
|
||||||
# time from it
|
|
||||||
if current_track_end_time:
|
if current_track_end_time:
|
||||||
self._set_row_start_time(row, current_track_end_time)
|
next_start_time = self._set_row_times(
|
||||||
next_start_time = self._calculate_end_time(
|
row, current_track_end_time,
|
||||||
current_track_end_time,
|
|
||||||
self._get_row_duration(row))
|
self._get_row_duration(row))
|
||||||
self._set_row_end_time(row, next_start_time)
|
|
||||||
continue
|
continue
|
||||||
# Fall through to set times if next_start_time is
|
# Else set track times below
|
||||||
# set
|
|
||||||
|
|
||||||
if row == current_track_row:
|
if row == current_track_row:
|
||||||
track_start = self.musicmuster.current_track.start_time
|
if not current_track_start_time:
|
||||||
if not track_start:
|
|
||||||
continue
|
continue
|
||||||
self._set_row_start_time(row, track_start)
|
self._set_row_start_time(row, current_track_start_time)
|
||||||
next_start_time = self._calculate_end_time(
|
self._set_row_end_time(row, current_track_end_time)
|
||||||
track_start, self._get_row_duration(row))
|
# Next track may be above us so only reset
|
||||||
self._set_row_end_time(row, next_start_time)
|
# next_start_time if it's not set
|
||||||
|
if not next_start_time:
|
||||||
|
next_start_time = current_track_end_time
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not next_start_time:
|
if not next_start_time:
|
||||||
|
# Clear any existing times
|
||||||
|
self._set_row_start_time(row, None)
|
||||||
|
self._set_row_end_time(row, None)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# If we're between the current and next row, zero out
|
# If we're between the current and next row, zero out
|
||||||
# times
|
# times
|
||||||
if (
|
if (current_track_row and next_track_row and
|
||||||
current_track_row and
|
current_track_row < row < next_track_row):
|
||||||
next_track_row and
|
|
||||||
current_track_row < row < next_track_row
|
|
||||||
):
|
|
||||||
self._set_row_start_time(row, None)
|
self._set_row_start_time(row, None)
|
||||||
self._set_row_end_time(row, None)
|
self._set_row_end_time(row, None)
|
||||||
else:
|
else:
|
||||||
self._set_row_start_time(row, next_start_time)
|
next_start_time = self._set_row_times(
|
||||||
next_start_time = self._calculate_end_time(
|
row, next_start_time, self._get_row_duration(row))
|
||||||
next_start_time, self._get_row_duration(row))
|
|
||||||
self._set_row_end_time(row, next_start_time)
|
|
||||||
|
|
||||||
def _wikipedia(self, row_number: int) -> None:
|
def _wikipedia(self, row_number: int) -> None:
|
||||||
"""Look up passed row title in Wikipedia and display info tab"""
|
"""Look up passed row title in Wikipedia and display info tab"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user