Compare commits

..

No commits in common. "dcab21bdde20e5a37e28006c46057fec0e4524e9" and "cb2017e9539383f83575feec74a022790ae25488" have entirely different histories.

2 changed files with 35 additions and 28 deletions

View File

@ -79,6 +79,7 @@ class Config(object):
SCROLL_TOP_MARGIN = 3 SCROLL_TOP_MARGIN = 3
TEXT_NO_TRACK_NO_NOTE = "[Section header]" TEXT_NO_TRACK_NO_NOTE = "[Section header]"
TOD_TIME_FORMAT = "%H:%M:%S" TOD_TIME_FORMAT = "%H:%M:%S"
TIMER_MS = 10
TRACK_TIME_FORMAT = "%H:%M:%S" TRACK_TIME_FORMAT = "%H:%M:%S"
VOLUME_VLC_DEFAULT = 75 VOLUME_VLC_DEFAULT = 75
VOLUME_VLC_DROP3db = 65 VOLUME_VLC_DROP3db = 65

View File

@ -59,7 +59,7 @@ from dbconfig import (
scoped_session, scoped_session,
) )
import helpers import helpers
import icons_rc # noqa F401 import icons_rc
import music import music
from models import Base, Carts, Playdates, PlaylistRows, Playlists, Settings, Tracks from models import Base, Carts, Playdates, PlaylistRows, Playlists, Settings, Tracks
from config import Config from config import Config
@ -319,9 +319,8 @@ class Window(QMainWindow, Ui_MainWindow):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.setupUi(self) self.setupUi(self)
self.timer10: QTimer = QTimer() self.timer: QTimer = QTimer()
self.timer500: QTimer = QTimer() self.clock_counter: int = 0
self.timer1000: QTimer = QTimer()
self.music: music.Music = music.Music() self.music: music.Music = music.Music()
self.playing: bool = False self.playing: bool = False
@ -361,9 +360,7 @@ class Window(QMainWindow, Ui_MainWindow):
self.carts_init() self.carts_init()
self.enable_play_next_controls() self.enable_play_next_controls()
self.clock_counter = 0 self.clock_counter = 0
self.timer10.start(10) self.timer.start(Config.TIMER_MS)
self.timer500.start(500)
self.timer1000.start(1000)
self.connect_signals_slots() self.connect_signals_slots()
def about(self) -> None: def about(self) -> None:
@ -674,9 +671,7 @@ class Window(QMainWindow, Ui_MainWindow):
self.tabBar.tabMoved.connect(self.move_tab) self.tabBar.tabMoved.connect(self.move_tab)
self.txtSearch.returnPressed.connect(self.search_playlist_return) self.txtSearch.returnPressed.connect(self.search_playlist_return)
self.timer10.timeout.connect(self.tick_10ms) self.timer.timeout.connect(self.tick)
self.timer500.timeout.connect(self.tick_500ms)
self.timer1000.timeout.connect(self.tick_1000ms)
def create_playlist( def create_playlist(
self, session: scoped_session, playlist_name: Optional[str] = None self, session: scoped_session, playlist_name: Optional[str] = None
@ -817,8 +812,8 @@ class Window(QMainWindow, Ui_MainWindow):
- Enable controls - Enable controls
""" """
# Set flag to say we're not playing a track so that timer ticks # Set flag to say we're not playing a track so that tick()
# don't see player=None and kick off end-of-track actions # doesn't see player=None and kick off end-of-track actions
self.playing = False self.playing = False
# Tell playlist_tab track has finished # Tell playlist_tab track has finished
@ -836,7 +831,8 @@ class Window(QMainWindow, Ui_MainWindow):
# Reset clocks # Reset clocks
self.frame_fade.setStyleSheet("") self.frame_fade.setStyleSheet("")
self.frame_silent.setStyleSheet("") self.frame_silent.setStyleSheet("")
self.label_elapsed_timer.setText("00:00 / 00:00") self.label_elapsed_timer.setText("00:00")
self.label_end_timer.setText("00:00")
self.label_fade_timer.setText("00:00") self.label_fade_timer.setText("00:00")
self.label_silent_timer.setText("00:00") self.label_silent_timer.setText("00:00")
@ -1399,12 +1395,6 @@ class Window(QMainWindow, Ui_MainWindow):
) )
self.play_next(self.previous_track_position) self.play_next(self.previous_track_position)
# Adjust track info so that clocks and graph are correct.
# Easiest way is to fake the start time.
if self.current_track.start_time and self.current_track.duration:
elapsed_ms = self.current_track.duration * self.previous_track_position
self.current_track.start_time -= timedelta(milliseconds=elapsed_ms)
# If a track was playing when we were called, get details to # If a track was playing when we were called, get details to
# set it as the next track # set it as the next track
if playing_track: if playing_track:
@ -1678,6 +1668,24 @@ class Window(QMainWindow, Ui_MainWindow):
self.next_track.playlist_tab, QColor(Config.COLOUR_NEXT_TAB) self.next_track.playlist_tab, QColor(Config.COLOUR_NEXT_TAB)
) )
def tick(self) -> None:
"""
Called every Config.TIMER_MS milliseconds. Call periodic functions
as required.
"""
# Get current number of milliseconds
self.clock_counter += Config.TIMER_MS
self.clock_counter %= 1000
# Call periodic functions
if self.clock_counter % 10 == 0:
self.tick_10ms()
if self.clock_counter % 500 == 0:
self.tick_500ms()
if self.clock_counter == 0:
self.tick_1000ms()
def tick_10ms(self) -> None: def tick_10ms(self) -> None:
""" """
Called every 10ms Called every 10ms
@ -1708,9 +1716,6 @@ class Window(QMainWindow, Ui_MainWindow):
Called every 1000ms Called every 1000ms
""" """
# Ensure preview button is reset if preview finishes playing
self.btnPreview.setChecked(mixer.music.get_busy())
# Only update play clocks once a second so that their updates # Only update play clocks once a second so that their updates
# are synchronised (otherwise it looks odd) # are synchronised (otherwise it looks odd)
@ -1734,6 +1739,7 @@ class Window(QMainWindow, Ui_MainWindow):
playtime = self.get_playtime() playtime = self.get_playtime()
time_to_fade = self.current_track.fade_at - playtime time_to_fade = self.current_track.fade_at - playtime
time_to_silence = self.current_track.silence_at - playtime time_to_silence = self.current_track.silence_at - playtime
time_to_end = self.current_track.duration - playtime
# Elapsed time # Elapsed time
self.label_elapsed_timer.setText( self.label_elapsed_timer.setText(
@ -1748,15 +1754,15 @@ class Window(QMainWindow, Ui_MainWindow):
# If silent in the next 5 seconds, put warning colour on # If silent in the next 5 seconds, put warning colour on
# time to silence box and enable play controls # time to silence box and enable play controls
if time_to_silence <= 5500: if time_to_silence <= 5500:
css_silence = f"background: {Config.COLOUR_ENDING_TIMER}" self.frame_silent.setStyleSheet(
if self.frame_silent.styleSheet() != css_silence: f"background: {Config.COLOUR_ENDING_TIMER}"
self.frame_silent.setStyleSheet(css_silence) )
self.enable_play_next_controls() self.enable_play_next_controls()
# Set warning colour on time to silence box when fade starts # Set warning colour on time to silence box when fade starts
elif time_to_fade <= 500: elif time_to_fade <= 500:
css_fade = f"background: {Config.COLOUR_WARNING_TIMER}" self.frame_silent.setStyleSheet(
if self.frame_silent.styleSheet() != css_fade: f"background: {Config.COLOUR_WARNING_TIMER}"
self.frame_silent.setStyleSheet(css_fade) )
# Five seconds before fade starts, set warning colour on # Five seconds before fade starts, set warning colour on
# time to silence box and enable play controls # time to silence box and enable play controls
elif time_to_fade <= 5500: elif time_to_fade <= 5500: