Næster version
This commit is contained in:
@@ -76,6 +76,9 @@ class MainWindow(QMainWindow):
|
||||
|
||||
self._dark_theme = True
|
||||
self._player = Player(self)
|
||||
# Preview-afspiller til bibliotek (høretelefoner)
|
||||
from player.player import PreviewPlayer
|
||||
self._preview_player = PreviewPlayer(self)
|
||||
self._current_idx = -1
|
||||
self._song_ended = False
|
||||
self._demo_active = False
|
||||
@@ -349,6 +352,15 @@ class MainWindow(QMainWindow):
|
||||
self._sync_debounce.timeout.connect(self._auto_sync)
|
||||
|
||||
self._library_panel = LibraryPanel()
|
||||
self._library_panel.set_preview_player(self._preview_player)
|
||||
|
||||
# Sæt audio devices fra indstillinger
|
||||
main_device = self._settings.get("audio_device_main", "")
|
||||
preview_device = self._settings.get("audio_device_preview", "")
|
||||
if main_device:
|
||||
self._player.set_audio_device(main_device)
|
||||
if preview_device:
|
||||
self._preview_player.set_audio_device(preview_device)
|
||||
self._library_panel.song_selected.connect(self._on_library_song_selected)
|
||||
self._library_panel.add_to_playlist.connect(self._add_song_to_playlist)
|
||||
self._library_panel.scan_requested.connect(self.start_scan)
|
||||
@@ -628,6 +640,13 @@ class MainWindow(QMainWindow):
|
||||
if dur > 0:
|
||||
self._progress.set_demo_marker(min(self._demo_seconds / dur, 1.0), min((self._demo_seconds + self._demo_fade_seconds) / dur, 1.0))
|
||||
self._set_status("Indstillinger gemt", 2000)
|
||||
# Anvend lydenheder med det samme
|
||||
main_device = self._settings.get("audio_device_main", "")
|
||||
preview_device = self._settings.get("audio_device_preview", "")
|
||||
if main_device:
|
||||
self._player.set_audio_device(main_device)
|
||||
if preview_device:
|
||||
self._preview_player.set_audio_device(preview_device)
|
||||
|
||||
def _auto_login(self):
|
||||
"""Forsøg automatisk login med gemte oplysninger."""
|
||||
@@ -970,6 +989,10 @@ class MainWindow(QMainWindow):
|
||||
dur = song.get("duration_sec", 0)
|
||||
self._player.load(song.get("local_path", ""), dur)
|
||||
|
||||
# Stop preview hvis den kører
|
||||
if hasattr(self, "_preview_player") and self._preview_player.is_playing():
|
||||
self._library_panel._stop_preview()
|
||||
|
||||
self._lbl_title.setText(song.get("title", "—"))
|
||||
bpm = song.get("bpm", 0)
|
||||
fmt_dur = f"{dur//60}:{dur%60:02d}"
|
||||
@@ -1006,6 +1029,7 @@ class MainWindow(QMainWindow):
|
||||
self._btn_demo.setChecked(False)
|
||||
self._btn_play.setText("▶")
|
||||
return
|
||||
self._waiting_for_auto = False # annuller evt. auto-timer
|
||||
if self._player.is_playing():
|
||||
self._player.pause()
|
||||
else:
|
||||
@@ -1014,6 +1038,13 @@ class MainWindow(QMainWindow):
|
||||
self._btn_play.setText("⏸")
|
||||
|
||||
def _stop(self):
|
||||
# Annuller evt. igangværende countdown
|
||||
if getattr(self, "_waiting_for_auto", False):
|
||||
self._waiting_for_auto = False
|
||||
if hasattr(self, "_countdown_timer"):
|
||||
self._countdown_timer.stop()
|
||||
self._set_status("Auto-afspilning annulleret", 3000)
|
||||
return
|
||||
self._player.stop()
|
||||
self._song_ended = False
|
||||
self._demo_active = False
|
||||
@@ -1104,7 +1135,27 @@ class MainWindow(QMainWindow):
|
||||
self._current_idx = ni
|
||||
self._playlist_panel.set_next_ready(ni)
|
||||
self._load_song(next_song)
|
||||
self._set_status(f"Klar: {next_song.get('title','')} — tryk ▶ for at starte")
|
||||
|
||||
mode = self._settings.get("after_song_mode", "manual")
|
||||
delay = self._settings.get("after_song_delay", 2)
|
||||
|
||||
if mode == "manual":
|
||||
self._waiting_for_auto = False
|
||||
self._set_status(f"Klar: {next_song.get('title','')} — tryk ▶ for at starte")
|
||||
|
||||
elif mode in ("auto_demo", "auto_play"):
|
||||
self._waiting_for_auto = True
|
||||
self._countdown_secs = delay
|
||||
self._countdown_mode = mode
|
||||
self._countdown_title = next_song.get("title", "")
|
||||
label = "Auto-demo" if mode == "auto_demo" else "Auto-play"
|
||||
self._set_status(f"{label} om {delay}s — {self._countdown_title}")
|
||||
|
||||
if not hasattr(self, "_countdown_timer"):
|
||||
self._countdown_timer = QTimer(self)
|
||||
self._countdown_timer.setInterval(1000)
|
||||
self._countdown_timer.timeout.connect(self._countdown_tick)
|
||||
self._countdown_timer.start()
|
||||
else:
|
||||
self._current_idx = -1
|
||||
self._playlist_panel._current_idx = -1
|
||||
@@ -1116,6 +1167,44 @@ class MainWindow(QMainWindow):
|
||||
self._lbl_dances.setText("")
|
||||
self._set_status("Danselisten er afsluttet")
|
||||
|
||||
def _countdown_tick(self):
|
||||
"""Tæller ned og starter auto-afspilning når den når 0."""
|
||||
if not getattr(self, "_waiting_for_auto", False):
|
||||
self._countdown_timer.stop()
|
||||
return
|
||||
self._countdown_secs -= 1
|
||||
label = "Auto-demo" if self._countdown_mode == "auto_demo" else "Auto-play"
|
||||
if self._countdown_secs > 0:
|
||||
self._set_status(f"{label} om {self._countdown_secs}s — {self._countdown_title}")
|
||||
else:
|
||||
self._countdown_timer.stop()
|
||||
if self._countdown_mode == "auto_demo":
|
||||
self._auto_demo_next()
|
||||
else:
|
||||
self._auto_play_next()
|
||||
|
||||
def _auto_demo_next(self):
|
||||
"""Afspil demo af den næste klargjorte sang automatisk."""
|
||||
if not getattr(self, "_waiting_for_auto", False):
|
||||
return # Brugeren har allerede trykket ▶ manuelt
|
||||
self._waiting_for_auto = False
|
||||
self._playlist_panel.set_current(self._current_idx)
|
||||
self._player.play_demo(self._demo_seconds, self._demo_fade_seconds)
|
||||
self._demo_active = True
|
||||
self._btn_demo.setChecked(True)
|
||||
self._btn_play.setText("⏸")
|
||||
self._song_ended = False
|
||||
|
||||
def _auto_play_next(self):
|
||||
"""Start næste sang automatisk."""
|
||||
if not getattr(self, "_waiting_for_auto", False):
|
||||
return # Brugeren har allerede trykket ▶ manuelt
|
||||
self._waiting_for_auto = False
|
||||
self._playlist_panel.set_current(self._current_idx)
|
||||
self._player.play()
|
||||
self._btn_play.setText("⏸")
|
||||
self._song_ended = False
|
||||
|
||||
def _sync_event_status_to_playlist(self):
|
||||
"""Gem event-fremgang (afspillet/sprunget over) til den navngivne liste."""
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user