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
MILLISECOND_SIGFIGS = 0
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"
OBS_HOST = "localhost"
OBS_PASSWORD = "auster"

View File

@ -91,6 +91,14 @@ class Music:
fader = FadeTrack(p)
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]:
"""Return current position"""

View File

@ -357,7 +357,6 @@ class Window(QMainWindow, Ui_MainWindow):
mixer.init()
self.widgetFadeVolume.hideAxis('bottom')
self.widgetFadeVolume.hideAxis('left')
self.widgetFadeVolume.setDefaultPadding(0)
self.widgetFadeVolume.setBackground(Config.FADE_CURVE_BACKGROUND)
FadeCurve.GraphWidget = self.widgetFadeVolume
@ -916,24 +915,6 @@ class Window(QMainWindow, Ui_MainWindow):
else:
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):
"""Toggle hide played tracks"""
@ -1690,25 +1671,29 @@ class Window(QMainWindow, Ui_MainWindow):
def tick(self) -> None:
"""
Called every Config.TIMER_MS milliseconds. Call periodic functions
as required.
"""
Carry out clock tick actions.
# Get current number of milliseconds
self.clock_counter += Config.TIMER_MS
self.clock_counter %= 1000
self.clock_counter is incrememted at each tick (100ms), and this
value is used to determine the actions to take.
# 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()
The Fade Volume graph is updated every 10ms.
def tick_10ms(self) -> None:
"""
Called every 10ms
The Time of Day clock and any cart progress bars are updated
every 500ms.
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
@ -1722,24 +1707,14 @@ class Window(QMainWindow, Ui_MainWindow):
).total_seconds() * 1000
self.current_track.fade_graph.tick(play_time)
def tick_500ms(self) -> None:
"""
Called every 500ms
"""
if self.clock_counter % 20 == 0:
# Update TOD clock
self.lblTOD.setText(datetime.now().strftime(
Config.TOD_TIME_FORMAT))
# Update carts
self.cart_tick()
def tick_1000ms(self) -> None:
"""
Called every 1000ms
"""
# Only update play clocks once a second so that their updates
# are synchronised (otherwise it looks odd)
if self.clock_counter % 50 == 0:
if not self.playing:
return
@ -1752,7 +1727,7 @@ class Window(QMainWindow, Ui_MainWindow):
self.music.player.is_playing() or
(datetime.now() - self.current_track.start_time)
< timedelta(microseconds=Config.PLAY_SETTLE)):
playtime = self.get_playtime()
playtime = self.music.get_playtime()
time_to_fade = (self.current_track.fade_at - playtime)
time_to_silence = (
self.current_track.silence_at - playtime)