V3 WIP: implement playing_track structure
This commit is contained in:
parent
a8ac67b9e3
commit
c20dc0288f
@ -212,8 +212,9 @@ class AddFadeCurve(QObject):
|
|||||||
self.finished.emit()
|
self.finished.emit()
|
||||||
|
|
||||||
|
|
||||||
cnp_tracks = dict(
|
class PlayingTrack:
|
||||||
CurrentTrack=PlaylistTrack(),
|
next = PlaylistTrack()
|
||||||
NextTrack=PlaylistTrack(),
|
now = PlaylistTrack()
|
||||||
PreviousTrack=PlaylistTrack(),
|
previous = PlaylistTrack()
|
||||||
)
|
|
||||||
|
playing_track = PlayingTrack()
|
||||||
|
|||||||
@ -52,7 +52,7 @@ from sqlalchemy import text
|
|||||||
import stackprinter # type: ignore
|
import stackprinter # type: ignore
|
||||||
|
|
||||||
from classes import (
|
from classes import (
|
||||||
cnp_tracks,
|
playing_track,
|
||||||
FadeCurve,
|
FadeCurve,
|
||||||
MusicMusterSignals,
|
MusicMusterSignals,
|
||||||
PlaylistTrack,
|
PlaylistTrack,
|
||||||
@ -387,7 +387,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
Clear next track
|
Clear next track
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cnp_tracks["NextTrack"] = PlaylistTrack()
|
playing_track.next = PlaylistTrack()
|
||||||
self.update_headers()
|
self.update_headers()
|
||||||
|
|
||||||
def clear_selection(self) -> None:
|
def clear_selection(self) -> None:
|
||||||
@ -708,13 +708,13 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
# self.current_track.playlist_tab.play_ended()
|
# self.current_track.playlist_tab.play_ended()
|
||||||
|
|
||||||
# Reset fade graph
|
# Reset fade graph
|
||||||
if cnp_tracks["CurrentTrack"].fade_graph:
|
if playing_track.now.fade_graph:
|
||||||
cnp_tracks["CurrentTrack"].fade_graph.clear()
|
playing_track.now.fade_graph.clear()
|
||||||
|
|
||||||
# Reset PlaylistTrack objects
|
# Reset PlaylistTrack objects
|
||||||
if cnp_tracks["CurrentTrack"].track_id:
|
if playing_track.now.track_id:
|
||||||
cnp_tracks["PreviousTrack"] = cnp_tracks["CurrentTrack"]
|
playing_track.previous = playing_track.now
|
||||||
cnp_tracks["CurrentTrack"] = PlaylistTrack()
|
playing_track.now = PlaylistTrack()
|
||||||
|
|
||||||
# Reset clocks
|
# Reset clocks
|
||||||
self.frame_fade.setStyleSheet("")
|
self.frame_fade.setStyleSheet("")
|
||||||
@ -786,13 +786,13 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if (
|
if (
|
||||||
cnp_tracks["CurrentTrack"].track_id is None
|
playing_track.now.track_id is None
|
||||||
or cnp_tracks["CurrentTrack"].start_time is None
|
or playing_track.now.start_time is None
|
||||||
):
|
):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
track_start = cnp_tracks["CurrentTrack"].start_time
|
track_start = playing_track.now.start_time
|
||||||
elapsed_seconds = (now - track_start).total_seconds()
|
elapsed_seconds = (now - track_start).total_seconds()
|
||||||
return int(elapsed_seconds * 1000)
|
return int(elapsed_seconds * 1000)
|
||||||
|
|
||||||
@ -946,7 +946,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
plr
|
plr
|
||||||
for plr in playlistrows
|
for plr in playlistrows
|
||||||
if plr.id
|
if plr.id
|
||||||
not in [cnp_tracks["CurrentTrack"].plr_id, cnp_tracks["NextTrack"].plr_id]
|
not in [playing_track.now.plr_id, playing_track.next.plr_id]
|
||||||
]
|
]
|
||||||
|
|
||||||
rows_to_delete = [
|
rows_to_delete = [
|
||||||
@ -1154,10 +1154,10 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# If there is no next track set, return.
|
# If there is no next track set, return.
|
||||||
if not cnp_tracks["NextTrack"].track_id:
|
if not playing_track.next.track_id:
|
||||||
log.debug("musicmuster.play_next(): no next track selected")
|
log.debug("musicmuster.play_next(): no next track selected")
|
||||||
return
|
return
|
||||||
if not cnp_tracks["NextTrack"].path:
|
if not playing_track.next.path:
|
||||||
log.debug("musicmuster.play_next(): no path for next track")
|
log.debug("musicmuster.play_next(): no path for next track")
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -1167,7 +1167,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
# Move next track to current track.
|
# Move next track to current track.
|
||||||
# stop_playing() above has called end_of_track_actions()
|
# stop_playing() above has called end_of_track_actions()
|
||||||
# which will have populated self.previous_track
|
# which will have populated self.previous_track
|
||||||
cnp_tracks["CurrentTrack"] = cnp_tracks["NextTrack"]
|
playing_track.now = playing_track.next
|
||||||
|
|
||||||
# Clear next track
|
# Clear next track
|
||||||
self.clear_next()
|
self.clear_next()
|
||||||
@ -1183,10 +1183,10 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
self.btnDrop3db.setChecked(False)
|
self.btnDrop3db.setChecked(False)
|
||||||
|
|
||||||
# Play (new) current track
|
# Play (new) current track
|
||||||
if not cnp_tracks["CurrentTrack"].path:
|
if not playing_track.now.path:
|
||||||
return
|
return
|
||||||
cnp_tracks["CurrentTrack"].start()
|
playing_track.now.start()
|
||||||
self.music.play(cnp_tracks["CurrentTrack"].path, position)
|
self.music.play(playing_track.now.path, position)
|
||||||
|
|
||||||
# Ensure 100% volume
|
# Ensure 100% volume
|
||||||
# For as-yet unknown reasons. sometimes the volume gets
|
# For as-yet unknown reasons. sometimes the volume gets
|
||||||
@ -1203,8 +1203,8 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
|
|
||||||
# Show closing volume graph
|
# Show closing volume graph
|
||||||
if cnp_tracks["CurrentTrack"].fade_graph:
|
if playing_track.now.fade_graph:
|
||||||
cnp_tracks["CurrentTrack"].fade_graph.plot()
|
playing_track.now.fade_graph.plot()
|
||||||
|
|
||||||
# Notify model
|
# Notify model
|
||||||
self.active_model().current_track_started()
|
self.active_model().current_track_started()
|
||||||
@ -1230,7 +1230,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
track_path = self.active_tab().get_selected_row_track_path()
|
track_path = self.active_tab().get_selected_row_track_path()
|
||||||
if not track_path:
|
if not track_path:
|
||||||
# Otherwise get path to next track to play
|
# Otherwise get path to next track to play
|
||||||
track_path = cnp_tracks["NextTrack"].path
|
track_path = playing_track.next.path
|
||||||
if not track_path:
|
if not track_path:
|
||||||
self.btnPreview.setChecked(False)
|
self.btnPreview.setChecked(False)
|
||||||
return
|
return
|
||||||
@ -1527,7 +1527,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
Set passed plr_id as next track to play, or clear next track if None
|
Set passed plr_id as next track to play, or clear next track if None
|
||||||
|
|
||||||
Actions required:
|
Actions required:
|
||||||
- Update cnp_tracks
|
- Update playing_track
|
||||||
- Tell playlist tabs to update their 'next track' highlighting
|
- Tell playlist tabs to update their 'next track' highlighting
|
||||||
- Update headers
|
- Update headers
|
||||||
- Set playlist tab colours
|
- Set playlist tab colours
|
||||||
@ -1606,14 +1606,14 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
# Update volume fade curve
|
# Update volume fade curve
|
||||||
if (
|
if (
|
||||||
cnp_tracks["CurrentTrack"].track_id
|
playing_track.now.track_id
|
||||||
and cnp_tracks["CurrentTrack"].fade_graph
|
and playing_track.now.fade_graph
|
||||||
and cnp_tracks["CurrentTrack"].start_time
|
and playing_track.now.start_time
|
||||||
):
|
):
|
||||||
play_time = (
|
play_time = (
|
||||||
datetime.now() - cnp_tracks["CurrentTrack"].start_time
|
datetime.now() - playing_track.now.start_time
|
||||||
).total_seconds() * 1000
|
).total_seconds() * 1000
|
||||||
cnp_tracks["CurrentTrack"].fade_graph.tick(play_time)
|
playing_track.now.fade_graph.tick(play_time)
|
||||||
|
|
||||||
def tick_500ms(self) -> None:
|
def tick_500ms(self) -> None:
|
||||||
"""
|
"""
|
||||||
@ -1645,22 +1645,22 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
# starting play.
|
# starting play.
|
||||||
if (
|
if (
|
||||||
self.music.player
|
self.music.player
|
||||||
and cnp_tracks["CurrentTrack"].start_time
|
and playing_track.now.start_time
|
||||||
and (
|
and (
|
||||||
self.music.player.is_playing()
|
self.music.player.is_playing()
|
||||||
or (datetime.now() - cnp_tracks["CurrentTrack"].start_time)
|
or (datetime.now() - playing_track.now.start_time)
|
||||||
< timedelta(microseconds=Config.PLAY_SETTLE)
|
< timedelta(microseconds=Config.PLAY_SETTLE)
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
playtime = self.get_playtime()
|
playtime = self.get_playtime()
|
||||||
time_to_fade = cnp_tracks["CurrentTrack"].fade_at - playtime
|
time_to_fade = playing_track.now.fade_at - playtime
|
||||||
time_to_silence = cnp_tracks["CurrentTrack"].silence_at - playtime
|
time_to_silence = playing_track.now.silence_at - playtime
|
||||||
|
|
||||||
# Elapsed time
|
# Elapsed time
|
||||||
self.label_elapsed_timer.setText(
|
self.label_elapsed_timer.setText(
|
||||||
helpers.ms_to_mmss(playtime)
|
helpers.ms_to_mmss(playtime)
|
||||||
+ " / "
|
+ " / "
|
||||||
+ helpers.ms_to_mmss(cnp_tracks["CurrentTrack"].duration)
|
+ helpers.ms_to_mmss(playing_track.now.duration)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Time to fade
|
# Time to fade
|
||||||
@ -1703,25 +1703,25 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
Update last / current / next track headers
|
Update last / current / next track headers
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if cnp_tracks["PreviousTrack"].title and cnp_tracks["PreviousTrack"].artist:
|
if playing_track.previous.title and playing_track.previous.artist:
|
||||||
self.hdrPreviousTrack.setText(
|
self.hdrPreviousTrack.setText(
|
||||||
f"{cnp_tracks['PreviousTrack'].title} - {cnp_tracks['PreviousTrack'].artist}"
|
f"{playing_track.previous.title} - {playing_track.previous.artist}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.hdrPreviousTrack.setText("")
|
self.hdrPreviousTrack.setText("")
|
||||||
|
|
||||||
if cnp_tracks["CurrentTrack"].title and cnp_tracks["CurrentTrack"].artist:
|
if playing_track.now.title and playing_track.now.artist:
|
||||||
self.hdrCurrentTrack.setText(
|
self.hdrCurrentTrack.setText(
|
||||||
f"{cnp_tracks['CurrentTrack'].title.replace('&', '&&')} - "
|
f"{playing_track.now.title.replace('&', '&&')} - "
|
||||||
f"{cnp_tracks['CurrentTrack'].artist.replace('&', '&&')}"
|
f"{playing_track.now.artist.replace('&', '&&')}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.hdrCurrentTrack.setText("")
|
self.hdrCurrentTrack.setText("")
|
||||||
|
|
||||||
if cnp_tracks["NextTrack"].title and cnp_tracks["NextTrack"].artist:
|
if playing_track.next.title and playing_track.next.artist:
|
||||||
self.hdrNextTrack.setText(
|
self.hdrNextTrack.setText(
|
||||||
f"{cnp_tracks['NextTrack'].title.replace('&', '&&')} - "
|
f"{playing_track.next.title.replace('&', '&&')} - "
|
||||||
f"{cnp_tracks['NextTrack'].artist.replace('&', '&&')}"
|
f"{playing_track.next.artist.replace('&', '&&')}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.hdrNextTrack.setText("")
|
self.hdrNextTrack.setText("")
|
||||||
|
|||||||
@ -14,7 +14,7 @@ from PyQt6.QtGui import (
|
|||||||
QFont,
|
QFont,
|
||||||
)
|
)
|
||||||
|
|
||||||
from classes import cnp_tracks, MusicMusterSignals, PlaylistTrack
|
from classes import playing_track, 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
|
from helpers import file_is_unreadable
|
||||||
@ -191,10 +191,10 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
if file_is_unreadable(prd.path):
|
if file_is_unreadable(prd.path):
|
||||||
return QBrush(QColor(Config.COLOUR_UNREADABLE))
|
return QBrush(QColor(Config.COLOUR_UNREADABLE))
|
||||||
# Current track
|
# Current track
|
||||||
if prd.plrid == cnp_tracks["CurrentTrack"].plr_id:
|
if prd.plrid == playing_track.now.plr_id:
|
||||||
return QBrush(QColor(Config.COLOUR_CURRENT_PLAYLIST))
|
return QBrush(QColor(Config.COLOUR_CURRENT_PLAYLIST))
|
||||||
# Next track
|
# Next track
|
||||||
if prd.plrid == cnp_tracks["NextTrack"].plr_id:
|
if prd.plrid == playing_track.next.plr_id:
|
||||||
return QBrush(QColor(Config.COLOUR_NEXT_PLAYLIST))
|
return QBrush(QColor(Config.COLOUR_NEXT_PLAYLIST))
|
||||||
|
|
||||||
# Individual cell colouring
|
# Individual cell colouring
|
||||||
@ -231,28 +231,28 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Sanity check
|
# Sanity check
|
||||||
if not cnp_tracks["CurrentTrack"].track_id:
|
if not playing_track.now.track_id:
|
||||||
log.error(
|
log.error(
|
||||||
"playlistmodel:current_track_started called with no current track"
|
"playlistmodel:current_track_started called with no current track"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
if cnp_tracks["CurrentTrack"].plr_rownum is None:
|
if playing_track.now.plr_rownum is None:
|
||||||
log.error(
|
log.error(
|
||||||
"playlistmodel:current_track_started called with no row number "
|
"playlistmodel:current_track_started called with no row number "
|
||||||
f"({cnp_tracks['CurrentTrack']=})"
|
f"({playing_track.now=})"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Update display
|
# Update display
|
||||||
self.invalidate_row(cnp_tracks["CurrentTrack"].plr_rownum)
|
self.invalidate_row(playing_track.now.plr_rownum)
|
||||||
|
|
||||||
# Update track times
|
# Update track times
|
||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
# Update Playdates in database
|
# Update Playdates in database
|
||||||
with Session() as session:
|
with Session() as session:
|
||||||
Playdates(session, cnp_tracks["CurrentTrack"].track_id)
|
Playdates(session, playing_track.now.track_id)
|
||||||
plr = session.get(PlaylistRows, cnp_tracks["CurrentTrack"].plr_id)
|
plr = session.get(PlaylistRows, playing_track.now.plr_id)
|
||||||
if plr:
|
if plr:
|
||||||
plr.played = True
|
plr.played = True
|
||||||
|
|
||||||
@ -271,7 +271,7 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
[
|
[
|
||||||
a
|
a
|
||||||
for a in unplayed_rows
|
for a in unplayed_rows
|
||||||
if a > cnp_tracks["CurrentTrack"].plr_rownum
|
if a > playing_track.now.plr_rownum
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -589,9 +589,9 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
Set row_number as next track
|
Set row_number as next track
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Update cnp_tracks
|
# Update playing_trtack
|
||||||
with Session() as session:
|
with Session() as session:
|
||||||
cnp_tracks["NextTrack"] = PlaylistTrack()
|
playing_track.next = PlaylistTrack()
|
||||||
try:
|
try:
|
||||||
plrid = self.playlist_rows[row_number].plrid
|
plrid = self.playlist_rows[row_number].plrid
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@ -608,7 +608,7 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
# Check track is readable
|
# Check track is readable
|
||||||
if file_is_unreadable(plr.track.path):
|
if file_is_unreadable(plr.track.path):
|
||||||
return
|
return
|
||||||
cnp_tracks["NextTrack"].set_plr(session, plr)
|
playing_track.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)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user