v0.76.0: opening DJ mode with empty decks hands the playing song to Deck A without a gap, and closing goes back to it

This commit is contained in:
2026-10-22 12:43:34 -07:00
parent fc1cd80d35
commit 5413263587
6 changed files with 220 additions and 7 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
"""LinTunes — iTunes-style music library manager and player for Linux."""
__version__ = "0.75.0"
__version__ = "0.76.0"
+29 -1
View File
@@ -77,6 +77,7 @@ class DeckView:
self.synced = False # set to the other deck's tempo, and still is
self.synced_to = None # …the track it was set to
self.loop_beats = 4.0
self.handoff = None # called with this view (None: failed) once loaded
@property
def color(self) -> QColor:
@@ -1569,6 +1570,7 @@ class DjShelf(QWidget):
def stop(self):
"""DJ mode closed: both decks stop (kept loaded), the sink goes."""
for v in self.views:
v.handoff = None
v.deck.playing = False
v.deck.scratch_rate = None
if self._output is not None:
@@ -1641,9 +1643,12 @@ class DjShelf(QWidget):
return
self.load(view, track)
def load(self, view: DeckView, track):
def load(self, view: DeckView, track, handoff=None):
"""Load ``track`` on this deck; ``handoff(view)`` runs once it's
playable (``handoff(None)`` if it never will be)."""
view.deck.load(None)
view.track = track
view.handoff = handoff
view.peaks = None
view.bpm = None
view.offset = 0.0
@@ -1665,6 +1670,23 @@ class DjShelf(QWidget):
self._refresh_deck(view)
self._emit_decks()
def latency_ms(self) -> int:
"""How far behind what's rendered the speakers are."""
frames = self._output.latency_frames if self._output is not None else 0
return int(round(frames * 1000 / RATE))
def cue(self, view: DeckView, seconds: float, play: bool):
"""Put a loaded deck where ``seconds`` will be *heard* — a playing
deck renders a latency ahead of the speakers — playing or not."""
deck = view.deck
if deck.source is None:
return
ahead = self.latency_ms() / 1000 if play else 0.0
deck.seek((seconds + ahead) * RATE)
deck.ended = False
deck.playing = play
self._refresh_deck(view)
def _view(self, name: str) -> DeckView:
return self.views[0] if name == "A" else self.views[1]
@@ -1694,8 +1716,14 @@ class DjShelf(QWidget):
self.vocal_sliders[view.name].setToolTip(
"Set up Demucs to separate vocals:\n" + stems.setup_command())
self._refresh_deck(view)
handoff, view.handoff = view.handoff, None
if handoff is not None:
handoff(view)
def _on_load_failed(self, view: DeckView, why: str):
handoff, view.handoff = view.handoff, None
if handoff is not None:
handoff(None)
view.stem_note = ""
self.message.emit(f"Couldn't load “{view.track.name if view.track else ''}” on "
f"Deck {view.name}: {why}")
+56 -2
View File
@@ -164,6 +164,7 @@ class MainWindow(QMainWindow):
self._dj = None
self._dj_prep_worker = None
self._dj_on = False
self._dj_pin = None # (track id, ms, was playing) to go back to
self._dj_anim = None
self._dj_resize_from = None
self._transport.dj_toggled.connect(self.set_dj_mode)
@@ -2660,7 +2661,9 @@ class MainWindow(QMainWindow):
def set_dj_mode(self, on: bool):
"""Open or close the DJ shelf: the window parts under the row of
transport boxes and the shelf shows in the gap; closing plays the
same thing backwards. The main player pauses while it's open."""
same thing backwards. The main player pauses while it's open —
unless both decks are empty: then its song carries on and Deck A
takes it over without a gap, and closing goes back to it."""
on = bool(on)
if on == self._dj_on:
return
@@ -2672,7 +2675,10 @@ class MainWindow(QMainWindow):
from lintunes.gui import track_table
if on:
shelf = self._ensure_dj()
self.player.set_suspended(True) # pauses it, and keeps it so
handoff = (self.player.is_local and self.player.current_track is not None
and all(v.track is None for v in shelf.views))
# pauses it (but not the song Deck A is about to take), and keeps it so
self.player.set_suspended(True, pause=not handoff)
target = self._dj_target_height()
self._transport.set_dj_mode(True, self._dj_titles())
track_table.deck_tag = self._deck_tag
@@ -2683,6 +2689,8 @@ class MainWindow(QMainWindow):
shelf.show()
shelf.start()
shelf.set_visualizer(self._transport._visualizer)
if handoff:
self._hand_to_deck(shelf)
self._sidebar.art.hide() # room for the lists instead
self._slide(split, before, shift=target + self._row_gap(), opening=True)
else:
@@ -2695,6 +2703,50 @@ class MainWindow(QMainWindow):
self._slide(split, before, shift=shift, opening=False)
self._refresh_tables()
def _hand_to_deck(self, shelf):
"""Load the playing song on Deck A while the main player carries
on, then cross over: the deck starts where the song will be heard a
sink's latency from now and the main player pauses as that arrives.
Where it paused is the pin closing goes back to."""
track = self.player.current_track
view = shelf.views[0]
shelf.crossfader.setValue(0) # Deck A alone, at full level
def ready(loaded):
if not self._dj_on:
return
current = self.player.current_track
if loaded is None or current is None or current.track_id != track.track_id:
self.player.pause() # it failed, or the song moved on
return
position = self.player.position_ms()
if not self.player.is_playing():
shelf.cue(loaded, position / 1000, play=False)
self._dj_pin = (track.track_id, position, False)
return
shelf.cue(loaded, position / 1000, play=True)
QTimer.singleShot(shelf.latency_ms(), lambda: self._pin_main(track.track_id))
shelf.load(view, track, handoff=ready)
def _pin_main(self, track_id: int):
if not self._dj_on:
return # closed in the meantime: it never stopped
self.player.pause()
self._dj_pin = (track_id, self.player.position_ms(), True)
def _back_to_pin(self):
"""DJ mode closed: the main player goes back to where Deck A took
its song over, playing if it was."""
pin, self._dj_pin = self._dj_pin, None
current = self.player.current_track
if pin is None or current is None or current.track_id != pin[0]:
return
_, position, playing = pin
self.player.seek(position)
if playing:
self.player.play()
def _ensure_dj(self):
if self._dj is None:
from lintunes.gui.dj_shelf import DjShelf
@@ -2816,6 +2868,7 @@ class MainWindow(QMainWindow):
self._dj.hide()
self._sidebar.art.show()
self.player.set_suspended(False)
self._back_to_pin()
self._transport.set_dj_mode(False)
def _dj_closed(self):
@@ -2826,6 +2879,7 @@ class MainWindow(QMainWindow):
self._dj.hide()
self._sidebar.art.show()
self.player.set_suspended(False)
self._back_to_pin()
self._transport.set_dj_mode(False)
def _on_dj_resize(self, dy: int):
+4 -2
View File
@@ -591,9 +591,11 @@ class Player(QObject):
# behind the decks with the main transport greyed out, unstoppable.
suspended = False
def set_suspended(self, on: bool):
def set_suspended(self, on: bool, pause: bool = True):
"""``pause=False`` keeps the current song sounding (nothing new can
start) while DJ mode's Deck A loads it to take over (Round 107)."""
self.suspended = bool(on)
if on:
if on and pause:
self.pause()
def play_queue(self, track_ids: list[int], start_index: int):