Rewrite track timings; looks to be working
This commit is contained in:
parent
db6fb7b367
commit
a2a9afb04f
@ -263,25 +263,17 @@ class PlaylistModel(QAbstractTableModel):
|
||||
- update track times
|
||||
"""
|
||||
|
||||
if play_track.playlist_id != self.playlist_id:
|
||||
if self.track_sequence.current is None:
|
||||
raise ApplicationError("track_started called with no current track")
|
||||
|
||||
if self.track_sequence.current.playlist_id != self.playlist_id:
|
||||
# Not for us
|
||||
return
|
||||
|
||||
track_id = play_track.track_id
|
||||
# Sanity check - 1
|
||||
track_id = self.track_sequence.current.track_id
|
||||
if not track_id:
|
||||
raise ApplicationError("track_started() called with no track_id")
|
||||
|
||||
# Sanity check - 2
|
||||
if self.track_sequence.current is None:
|
||||
raise ApplicationError("track_started callced with no current track")
|
||||
|
||||
row_number = self.track_sequence.current.row_number
|
||||
playlist_dto = self.playlist_rows[row_number]
|
||||
|
||||
# Sanity check - 3
|
||||
if playlist_dto.track_id != track_id:
|
||||
raise ApplicationError("track_id mismatch between playlist_rows and signal")
|
||||
|
||||
# Check for OBS scene change
|
||||
self.obs_scene_change(row_number)
|
||||
@ -1497,36 +1489,62 @@ class PlaylistModel(QAbstractTableModel):
|
||||
InsertTrack(playlist_id=self.playlist_id, track_id=track_id, note="")
|
||||
)
|
||||
|
||||
def get_end_time(self, row_number: int, start_time: dt.datetime) -> dt.datetime:
|
||||
"""
|
||||
Return the end time for row_number from the passed start_time and
|
||||
the row duration.
|
||||
"""
|
||||
|
||||
plr = self.playlist_rows[row_number]
|
||||
end_time = start_time + dt.timedelta(milliseconds=plr.duration)
|
||||
|
||||
return end_time
|
||||
|
||||
# @log_call
|
||||
def update_track_times(self) -> None:
|
||||
"""
|
||||
Update track start/end times in self.playlist_rows
|
||||
"""
|
||||
|
||||
next_start_time: Optional[dt.datetime] = None
|
||||
next_start_time: dt.datetime | None = None
|
||||
update_rows: list[int] = []
|
||||
|
||||
current_track_row_number: int | None = None
|
||||
next_track_row: int | None = None
|
||||
|
||||
row_count = len(self.playlist_rows)
|
||||
|
||||
current_track_row = None
|
||||
next_track_row = None
|
||||
# If we have a current track, use its start time
|
||||
if (
|
||||
self.track_sequence.current
|
||||
and self.track_sequence.current.playlist_id == self.playlist_id
|
||||
):
|
||||
current_track_row = self.track_sequence.current.row_number
|
||||
# Update current track details now so that they are available
|
||||
# when we deal with next track row which may be above current
|
||||
# track row.
|
||||
self.playlist_rows[current_track_row].set_forecast_start_time(
|
||||
update_rows, self.track_sequence.current.start_time
|
||||
)
|
||||
plr = self.track_sequence.current
|
||||
current_track_row_number = plr.row_number
|
||||
|
||||
new_start_time = self.track_sequence.current.start_time
|
||||
if not new_start_time:
|
||||
raise ApplicationError(
|
||||
f"Can't get start time for current track ({self.track_sequence.current=})")
|
||||
|
||||
if new_start_time != plr.forecast_start_time:
|
||||
plr.forecast_start_time = new_start_time
|
||||
update_rows.append(current_track_row_number)
|
||||
|
||||
next_start_time = self.get_end_time(current_track_row_number, new_start_time)
|
||||
if next_start_time != plr.forecast_end_time:
|
||||
plr.forecast_end_time = next_start_time
|
||||
update_rows.append(current_track_row_number)
|
||||
|
||||
# If we have a next track, note row number
|
||||
if (
|
||||
self.track_sequence.next
|
||||
and self.track_sequence.next.playlist_id == self.playlist_id
|
||||
and next_start_time
|
||||
):
|
||||
next_track_row = self.track_sequence.next.row_number
|
||||
|
||||
# Step through rows and update start/end times
|
||||
for row_number in range(row_count):
|
||||
plr = self.playlist_rows[row_number]
|
||||
|
||||
@ -1534,12 +1552,12 @@ class PlaylistModel(QAbstractTableModel):
|
||||
# unreadable tracks or for the current track, handled above.
|
||||
if (
|
||||
plr.played
|
||||
or row_number == current_track_row
|
||||
or row_number == current_track_row_number
|
||||
or (plr.path and file_is_unreadable(plr.path))
|
||||
):
|
||||
continue
|
||||
|
||||
# Reset start time if timing in header
|
||||
# Reset start time if timing in header; otherwise skip header
|
||||
if self.is_header_row(row_number):
|
||||
header_time = get_embedded_time(plr.note)
|
||||
if header_time:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user