WIP: fade graph working, slightly laggy
This commit is contained in:
parent
c5ca1469dc
commit
0361d25c7b
@ -2,23 +2,19 @@
|
||||
|
||||
# Standard library imports
|
||||
from os.path import basename
|
||||
from time import sleep
|
||||
from typing import cast, List, Optional
|
||||
from typing import List, Optional
|
||||
import argparse
|
||||
import datetime as dt
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
|
||||
# PyQt imports
|
||||
from PyQt6.QtCore import (
|
||||
pyqtSignal,
|
||||
QDate,
|
||||
QEvent,
|
||||
QObject,
|
||||
QSize,
|
||||
Qt,
|
||||
QThread,
|
||||
QTime,
|
||||
@ -27,10 +23,7 @@ from PyQt6.QtCore import (
|
||||
from PyQt6.QtGui import (
|
||||
QCloseEvent,
|
||||
QColor,
|
||||
QFont,
|
||||
QMouseEvent,
|
||||
QPalette,
|
||||
QResizeEvent,
|
||||
)
|
||||
from PyQt6.QtWidgets import (
|
||||
QApplication,
|
||||
@ -42,8 +35,6 @@ from PyQt6.QtWidgets import (
|
||||
QListWidgetItem,
|
||||
QMainWindow,
|
||||
QMessageBox,
|
||||
QProgressBar,
|
||||
QPushButton,
|
||||
)
|
||||
|
||||
# Third party imports
|
||||
@ -176,7 +167,6 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
self.widgetFadeVolume.hideAxis("left")
|
||||
self.widgetFadeVolume.setDefaultPadding(0)
|
||||
self.widgetFadeVolume.setBackground(Config.FADE_CURVE_BACKGROUND)
|
||||
FadeCurve.GraphWidget = self.widgetFadeVolume
|
||||
|
||||
self.active_tab = lambda: self.tabPlaylist.currentWidget()
|
||||
self.active_proxy_model = lambda: self.tabPlaylist.currentWidget().model()
|
||||
@ -999,7 +989,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
):
|
||||
return
|
||||
|
||||
log.info(f"play_next({position=})")
|
||||
log.debug(f"play_next({position=})")
|
||||
|
||||
# If there is no next track set, return.
|
||||
if track_sequence.next is None:
|
||||
@ -1035,6 +1025,13 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
# Play (new) current track
|
||||
track_sequence.current.play(position)
|
||||
|
||||
# Show closing volume graph
|
||||
if track_sequence.current.fade_graph:
|
||||
track_sequence.current.fade_graph.GraphWidget = self.widgetFadeVolume
|
||||
track_sequence.current.fade_graph.plot()
|
||||
else:
|
||||
log.error("No fade_graph")
|
||||
|
||||
# Disable play next controls
|
||||
self.catch_return_key = True
|
||||
self.show_status_message("Play controls: Disabled", 0)
|
||||
@ -1475,23 +1472,8 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
Called every 10ms
|
||||
"""
|
||||
|
||||
return
|
||||
# Update volume fade curve
|
||||
if (
|
||||
track_sequence.current.fade_graph_start_updates is None
|
||||
or track_sequence.current.fade_graph_start_updates > dt.datetime.now()
|
||||
):
|
||||
return
|
||||
|
||||
if (
|
||||
track_sequence.current.track_id
|
||||
and track_sequence.current.fade_graph
|
||||
and track_sequence.current.start_time
|
||||
):
|
||||
play_time = (
|
||||
dt.datetime.now() - track_sequence.current.start_time
|
||||
).total_seconds() * 1000
|
||||
track_sequence.current.fade_graph.tick(play_time)
|
||||
if track_sequence.current:
|
||||
track_sequence.current.update_fade_graph()
|
||||
|
||||
def tick_500ms(self) -> None:
|
||||
"""
|
||||
|
||||
@ -43,13 +43,13 @@ class _AddFadeCurve(QObject):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
track_player: _TrackManager,
|
||||
track_manager: _TrackManager,
|
||||
track_path: str,
|
||||
track_fade_at: int,
|
||||
track_silence_at: int,
|
||||
):
|
||||
super().__init__()
|
||||
self.track_player = track_player
|
||||
self.track_manager = track_manager
|
||||
self.track_path = track_path
|
||||
self.track_fade_at = track_fade_at
|
||||
self.track_silence_at = track_silence_at
|
||||
@ -63,7 +63,7 @@ class _AddFadeCurve(QObject):
|
||||
if not fc:
|
||||
log.error(f"Failed to create FadeCurve for {self.track_path=}")
|
||||
else:
|
||||
self.track_player.fade_graph = fc
|
||||
self.track_manager.fade_graph = fc
|
||||
self.finished.emit()
|
||||
|
||||
|
||||
@ -84,8 +84,10 @@ class _FadeCurve:
|
||||
|
||||
# Start point of curve is Config.FADE_CURVE_MS_BEFORE_FADE
|
||||
# milliseconds before fade starts to silence
|
||||
self.start_ms = max(0, track_fade_at - Config.FADE_CURVE_MS_BEFORE_FADE - 1)
|
||||
self.end_ms = track_silence_at
|
||||
self.start_ms: int = max(
|
||||
0, track_fade_at - Config.FADE_CURVE_MS_BEFORE_FADE - 1
|
||||
)
|
||||
self.end_ms: int = track_silence_at
|
||||
self.audio_segment = audio[self.start_ms : self.end_ms]
|
||||
self.graph_array = np.array(self.audio_segment.get_array_of_samples())
|
||||
|
||||
@ -423,6 +425,8 @@ class _TrackManager:
|
||||
|
||||
if not self.player.is_playing():
|
||||
self.start_time = None
|
||||
if self.fade_graph:
|
||||
self.fade_graph.clear()
|
||||
self.signals.track_ended_signal.emit()
|
||||
|
||||
def drop3db(self, enable: bool) -> None:
|
||||
@ -510,6 +514,25 @@ class _TrackManager:
|
||||
|
||||
return self.silence_at - self.time_playing()
|
||||
|
||||
def update_fade_graph(self) -> None:
|
||||
"""
|
||||
Update fade graph
|
||||
"""
|
||||
|
||||
if (
|
||||
not self.is_playing()
|
||||
or not self.fade_graph_start_updates
|
||||
or not self.fade_graph
|
||||
):
|
||||
return
|
||||
|
||||
now = dt.datetime.now()
|
||||
|
||||
if self.fade_graph_start_updates > now:
|
||||
return
|
||||
|
||||
self.fade_graph.tick(self.time_playing())
|
||||
|
||||
|
||||
class MainTrackManager(_TrackManager):
|
||||
"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user