WIP V3: track start/end times working
This commit is contained in:
parent
698fa4625a
commit
b3262b2ede
@ -17,7 +17,7 @@ from PyQt6.QtGui import (
|
|||||||
from classes import track_sequence, MusicMusterSignals, PlaylistTrack
|
from classes import track_sequence, MusicMusterSignals, PlaylistTrack
|
||||||
from config import Config
|
from config import Config
|
||||||
from dbconfig import scoped_session, Session
|
from dbconfig import scoped_session, Session
|
||||||
from helpers import file_is_unreadable, get_embedded_time
|
from helpers import file_is_unreadable, get_embedded_time, ms_to_mmss
|
||||||
from log import log
|
from log import log
|
||||||
from models import Playdates, PlaylistRows, Tracks
|
from models import Playdates, PlaylistRows, Tracks
|
||||||
|
|
||||||
@ -250,16 +250,6 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Update display
|
|
||||||
self.invalidate_row(row_number)
|
|
||||||
|
|
||||||
# Update track times
|
|
||||||
self.playlist_rows[row_number].start_time = datetime.now()
|
|
||||||
self.playlist_rows[row_number].end_time = datetime.now() + timedelta(
|
|
||||||
milliseconds=self.playlist_rows[row_number].duration
|
|
||||||
)
|
|
||||||
self.update_track_times()
|
|
||||||
|
|
||||||
# Update Playdates in database
|
# Update Playdates in database
|
||||||
with Session() as session:
|
with Session() as session:
|
||||||
Playdates(session, track_sequence.now.track_id)
|
Playdates(session, track_sequence.now.track_id)
|
||||||
@ -268,6 +258,16 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
plr.played = True
|
plr.played = True
|
||||||
self.refresh_row(session, plr.plr_rownum)
|
self.refresh_row(session, plr.plr_rownum)
|
||||||
|
|
||||||
|
# Update track times
|
||||||
|
self.playlist_rows[row_number].start_time = datetime.now()
|
||||||
|
self.playlist_rows[row_number].end_time = datetime.now() + timedelta(
|
||||||
|
milliseconds=self.playlist_rows[row_number].duration
|
||||||
|
)
|
||||||
|
# Update colour and times for current row
|
||||||
|
self.invalidate_row(row_number)
|
||||||
|
# Update all other track times
|
||||||
|
self.update_track_times()
|
||||||
|
|
||||||
# Find next track
|
# Find next track
|
||||||
# Get all unplayed track rows
|
# Get all unplayed track rows
|
||||||
next_row = None
|
next_row = None
|
||||||
@ -279,9 +279,7 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
if unplayed_rows:
|
if unplayed_rows:
|
||||||
try:
|
try:
|
||||||
# Find next row after current track
|
# Find next row after current track
|
||||||
next_row = min(
|
next_row = min([a for a in unplayed_rows if a > row_number])
|
||||||
[a for a in unplayed_rows if a > track_sequence.now.plr_rownum]
|
|
||||||
)
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# Find first unplayed track
|
# Find first unplayed track
|
||||||
next_row = min(unplayed_rows)
|
next_row = min(unplayed_rows)
|
||||||
@ -352,7 +350,7 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
if column == Col.ARTIST.value:
|
if column == Col.ARTIST.value:
|
||||||
return QVariant(prd.artist)
|
return QVariant(prd.artist)
|
||||||
if column == Col.DURATION.value:
|
if column == Col.DURATION.value:
|
||||||
return QVariant(prd.duration)
|
return QVariant(ms_to_mmss(prd.duration))
|
||||||
if column == Col.START_TIME.value:
|
if column == Col.START_TIME.value:
|
||||||
if prd.start_time:
|
if prd.start_time:
|
||||||
return QVariant(prd.start_time.strftime(Config.TRACK_TIME_FORMAT))
|
return QVariant(prd.start_time.strftime(Config.TRACK_TIME_FORMAT))
|
||||||
@ -666,6 +664,7 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
track_sequence.next.set_plr(session, plr)
|
track_sequence.next.set_plr(session, plr)
|
||||||
self.signals.next_track_changed_signal.emit()
|
self.signals.next_track_changed_signal.emit()
|
||||||
self.invalidate_row(row_number)
|
self.invalidate_row(row_number)
|
||||||
|
self.update_track_times()
|
||||||
|
|
||||||
def setData(
|
def setData(
|
||||||
self, index: QModelIndex, value: QVariant, role: int = Qt.ItemDataRole.EditRole
|
self, index: QModelIndex, value: QVariant, role: int = Qt.ItemDataRole.EditRole
|
||||||
@ -719,23 +718,53 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
next_start_time: Optional[datetime] = None
|
next_start_time: Optional[datetime] = None
|
||||||
|
update_rows: List[int] = []
|
||||||
|
|
||||||
for row_number in range(len(self.playlist_rows)):
|
for row_number in range(len(self.playlist_rows)):
|
||||||
plr = self.playlist_rows[row_number]
|
prd = self.playlist_rows[row_number]
|
||||||
|
|
||||||
# Reset start_time if this is the current row
|
# Reset start_time if this is the current row
|
||||||
if row_number == track_sequence.now.plr_rownum:
|
if row_number == track_sequence.now.plr_rownum:
|
||||||
next_start_time = plr.end_time = track_sequence.now.end_time
|
# Start/end times for current track are set in current_track_started
|
||||||
|
if not next_start_time:
|
||||||
|
next_start_time = prd.end_time
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Set start time for next row if we have a current track
|
||||||
|
current_end_time = track_sequence.now.end_time
|
||||||
|
if row_number == track_sequence.next.plr_rownum and current_end_time:
|
||||||
|
prd.start_time = current_end_time
|
||||||
|
prd.end_time = current_end_time + timedelta(milliseconds=prd.duration)
|
||||||
|
next_start_time = prd.end_time
|
||||||
|
update_rows.append(row_number)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Don't update times for tracks that have been played
|
# Don't update times for tracks that have been played
|
||||||
if plr.played:
|
if prd.played:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Reset start time if timing in hearer or at current track
|
# Don't schedule unplayable tracks
|
||||||
if not plr.path:
|
if file_is_unreadable(prd.path):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# If we're between the current and next row, zero out
|
||||||
|
# times
|
||||||
|
if (
|
||||||
|
track_sequence.now.plr_rownum is not None
|
||||||
|
and track_sequence.next.plr_rownum is not None
|
||||||
|
and track_sequence.now.plr_rownum
|
||||||
|
< row_number
|
||||||
|
< track_sequence.next.plr_rownum
|
||||||
|
):
|
||||||
|
prd.start_time = None
|
||||||
|
prd.end_time = None
|
||||||
|
update_rows.append(row_number)
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Reset start time if timing in header or at current track
|
||||||
|
if not prd.path:
|
||||||
# This is a header row
|
# This is a header row
|
||||||
header_time = get_embedded_time(plr.note)
|
header_time = get_embedded_time(prd.note)
|
||||||
if header_time:
|
if header_time:
|
||||||
next_start_time = header_time
|
next_start_time = header_time
|
||||||
else:
|
else:
|
||||||
@ -743,7 +772,19 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
# start time
|
# start time
|
||||||
if next_start_time is None:
|
if next_start_time is None:
|
||||||
continue
|
continue
|
||||||
plr.start_time = next_start_time
|
if prd.start_time != next_start_time:
|
||||||
next_start_time = plr.end_time = next_start_time + timedelta(
|
prd.start_time = next_start_time
|
||||||
|
update_rows.append(row_number)
|
||||||
|
next_start_time += timedelta(
|
||||||
milliseconds=self.playlist_rows[row_number].duration
|
milliseconds=self.playlist_rows[row_number].duration
|
||||||
)
|
)
|
||||||
|
if prd.end_time != next_start_time:
|
||||||
|
prd.end_time = next_start_time
|
||||||
|
update_rows.append(row_number)
|
||||||
|
|
||||||
|
# Update start/stop times of rows that have changed
|
||||||
|
for updated_row in update_rows:
|
||||||
|
self.dataChanged.emit(
|
||||||
|
self.index(updated_row, Col.START_TIME.value),
|
||||||
|
self.index(updated_row, Col.END_TIME.value),
|
||||||
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user