Compare commits

..

No commits in common. "d3834928fd2190a2b507004f888c667d4e00b124" and "b706008101e90da5d3318a86f3fa0d1dc0d02b91" have entirely different histories.

3 changed files with 89 additions and 105 deletions

View File

@ -69,6 +69,7 @@ class Config(object):
MAX_MISSING_FILES_TO_REPORT = 10 MAX_MISSING_FILES_TO_REPORT = 10
MILLISECOND_SIGFIGS = 0 MILLISECOND_SIGFIGS = 0
MINIMUM_ROW_HEIGHT = 30 MINIMUM_ROW_HEIGHT = 30
MYSQL_CONNECT = os.environ.get('MYSQL_CONNECT') or "mysql+mysqldb://musicmuster:musicmuster@localhost/musicmuster_v2" # noqa E501
NOTE_TIME_FORMAT = "%H:%M:%S" NOTE_TIME_FORMAT = "%H:%M:%S"
OBS_HOST = "localhost" OBS_HOST = "localhost"
OBS_PASSWORD = "auster" OBS_PASSWORD = "auster"

View File

@ -91,6 +91,14 @@ class Music:
fader = FadeTrack(p) fader = FadeTrack(p)
pool.start(fader) pool.start(fader)
def get_playtime(self) -> Optional[int]:
"""Return elapsed play time"""
if not self.player:
return None
return self.player.get_time()
def get_position(self) -> Optional[float]: def get_position(self) -> Optional[float]:
"""Return current position""" """Return current position"""

View File

@ -357,7 +357,6 @@ class Window(QMainWindow, Ui_MainWindow):
mixer.init() mixer.init()
self.widgetFadeVolume.hideAxis('bottom') self.widgetFadeVolume.hideAxis('bottom')
self.widgetFadeVolume.hideAxis('left') self.widgetFadeVolume.hideAxis('left')
self.widgetFadeVolume.setDefaultPadding(0)
self.widgetFadeVolume.setBackground(Config.FADE_CURVE_BACKGROUND) self.widgetFadeVolume.setBackground(Config.FADE_CURVE_BACKGROUND)
FadeCurve.GraphWidget = self.widgetFadeVolume FadeCurve.GraphWidget = self.widgetFadeVolume
@ -916,24 +915,6 @@ class Window(QMainWindow, Ui_MainWindow):
else: else:
return None return None
def get_playtime(self) -> int:
"""
Return number of milliseconds current track has been playing or
zero if not playing. The vlc function get_time() only updates 3-4
times a second; this function has much better resolution.
"""
if (
self.current_track.track_id is None or
self.current_track.start_time is None
):
return 0
now = datetime.now()
track_start = self.current_track.start_time
elapsed_seconds = (now - track_start).total_seconds()
return int(elapsed_seconds * 1000)
def hide_played(self): def hide_played(self):
"""Toggle hide played tracks""" """Toggle hide played tracks"""
@ -1690,25 +1671,29 @@ class Window(QMainWindow, Ui_MainWindow):
def tick(self) -> None: def tick(self) -> None:
""" """
Called every Config.TIMER_MS milliseconds. Call periodic functions Carry out clock tick actions.
as required.
"""
# Get current number of milliseconds self.clock_counter is incrememted at each tick (100ms), and this
self.clock_counter += Config.TIMER_MS value is used to determine the actions to take.
self.clock_counter %= 1000
# Call periodic functions The Fade Volume graph is updated every 10ms.
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: The Time of Day clock and any cart progress bars are updated
""" every 500ms.
Called every 10ms
All other timers are updated every second. As the timer displays
have a one-second resolution, updating every 500ms can result in
some timers updating and then, 500ms later, other timers
updating. That looks odd.
Actions required:
- Update Fade Volume graph
- Update TOD clock
- Call cart_tick
- If track is playing:
update track clocks time and colours
- Else:
run stop_track
""" """
# Update volume fade curve # Update volume fade curve
@ -1722,84 +1707,74 @@ class Window(QMainWindow, Ui_MainWindow):
).total_seconds() * 1000 ).total_seconds() * 1000
self.current_track.fade_graph.tick(play_time) self.current_track.fade_graph.tick(play_time)
def tick_500ms(self) -> None: if self.clock_counter % 20 == 0:
""" # Update TOD clock
Called every 500ms self.lblTOD.setText(datetime.now().strftime(
""" Config.TOD_TIME_FORMAT))
# Update carts
self.cart_tick()
self.lblTOD.setText(datetime.now().strftime( if self.clock_counter % 50 == 0:
Config.TOD_TIME_FORMAT)) if not self.playing:
# Update carts return
self.cart_tick()
def tick_1000ms(self) -> None: # If track is playing, update track clocks time and colours
""" # There is a discrete time between starting playing a track and
Called every 1000ms # player.is_playing() returning True, so assume playing if less
""" # than Config.PLAY_SETTLE microseconds have passed since
# starting play.
if self.music.player and self.current_track.start_time and (
self.music.player.is_playing() or
(datetime.now() - self.current_track.start_time)
< timedelta(microseconds=Config.PLAY_SETTLE)):
playtime = self.music.get_playtime()
time_to_fade = (self.current_track.fade_at - playtime)
time_to_silence = (
self.current_track.silence_at - playtime)
time_to_end = (self.current_track.duration - playtime)
# Only update play clocks once a second so that their updates # Elapsed time
# are synchronised (otherwise it looks odd) self.label_elapsed_timer.setText(helpers.ms_to_mmss(playtime))
if not self.playing: # Time to fade
return self.label_fade_timer.setText(helpers.ms_to_mmss(time_to_fade))
# If track is playing, update track clocks time and colours # If silent in the next 5 seconds, put warning colour on
# There is a discrete time between starting playing a track and # time to silence box and enable play controls
# player.is_playing() returning True, so assume playing if less if time_to_silence <= 5500:
# than Config.PLAY_SETTLE microseconds have passed since self.frame_silent.setStyleSheet(
# starting play. f"background: {Config.COLOUR_ENDING_TIMER}"
if self.music.player and self.current_track.start_time and ( )
self.music.player.is_playing() or self.enable_play_next_controls()
(datetime.now() - self.current_track.start_time) # Set warning colour on time to silence box when fade starts
< timedelta(microseconds=Config.PLAY_SETTLE)): elif time_to_fade <= 500:
playtime = self.get_playtime() self.frame_silent.setStyleSheet(
time_to_fade = (self.current_track.fade_at - playtime) f"background: {Config.COLOUR_WARNING_TIMER}"
time_to_silence = ( )
self.current_track.silence_at - playtime) # Five seconds before fade starts, set warning colour on
time_to_end = (self.current_track.duration - playtime) # time to silence box and enable play controls
elif time_to_fade <= 5500:
self.frame_fade.setStyleSheet(
f"background: {Config.COLOUR_WARNING_TIMER}"
)
self.enable_play_next_controls()
else:
self.frame_silent.setStyleSheet("")
self.frame_fade.setStyleSheet("")
# Elapsed time self.label_silent_timer.setText(
self.label_elapsed_timer.setText(helpers.ms_to_mmss(playtime)) helpers.ms_to_mmss(time_to_silence)
# Time to fade
self.label_fade_timer.setText(helpers.ms_to_mmss(time_to_fade))
# If silent in the next 5 seconds, put warning colour on
# time to silence box and enable play controls
if time_to_silence <= 5500:
self.frame_silent.setStyleSheet(
f"background: {Config.COLOUR_ENDING_TIMER}"
) )
self.enable_play_next_controls()
# Set warning colour on time to silence box when fade starts # Time to end
elif time_to_fade <= 500: self.label_end_timer.setText(helpers.ms_to_mmss(time_to_end))
self.frame_silent.setStyleSheet(
f"background: {Config.COLOUR_WARNING_TIMER}" # Autoplay next track
) # if time_to_silence <= 1500:
# Five seconds before fade starts, set warning colour on # self.play_next()
# time to silence box and enable play controls
elif time_to_fade <= 5500:
self.frame_fade.setStyleSheet(
f"background: {Config.COLOUR_WARNING_TIMER}"
)
self.enable_play_next_controls()
else: else:
self.frame_silent.setStyleSheet("") if self.playing:
self.frame_fade.setStyleSheet("") self.stop_playing()
self.label_silent_timer.setText(
helpers.ms_to_mmss(time_to_silence)
)
# Time to end
self.label_end_timer.setText(helpers.ms_to_mmss(time_to_end))
# Autoplay next track
# if time_to_silence <= 1500:
# self.play_next()
else:
if self.playing:
self.stop_playing()
def update_headers(self) -> None: def update_headers(self) -> None:
""" """