v0.63.1: nothing starts the main player in DJ mode; sync always clickable

Return or a double-click on a song started the regular player behind the
decks, with its controls greyed out and no way to stop it. DJ mode now
suspends the player. Sync to other track was only re-enabled when its own
deck changed, so loading the other deck afterwards left it grey; it's now
enabled whenever its deck has a song and explains what it can't do.
This commit is contained in:
2026-10-17 02:19:02 -07:00
parent 57cc5d5289
commit 8298450814
6 changed files with 91 additions and 12 deletions
+5 -1
View File
@@ -353,7 +353,11 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal
record darkens and gets the deck's rim; replacing a deck that's playing record darkens and gets the deck's rim; replacing a deck that's playing
above 50 % gain asks first), and a song that ends just stops — no queue, above 50 % gain asks first), and a song that ends just stops — no queue,
so the main transport, seek bar, space and arrows are greyed/ignored, and so the main transport, seek bar, space and arrows are greyed/ignored, and
the main player pauses when DJ mode opens. Deck A is blue and Deck B the main player is **suspended** while DJ mode is open
(`Player.set_suspended`: paused, and nothing — double-click, Return, a
media key — can start it; it played behind the decks, unstoppable, in
v0.63.0). "Sync to other track" is enabled whenever its own deck has a
song; what it can't do yet it says in the status bar. Deck A is blue and Deck B
orange, every control included; loaded songs get a DECK A/B tag in every orange, every control included; loaded songs get a DECK A/B tag in every
track list (`track_table.deck_tag`). **Its own engine**, because Qt's track list (`track_table.deck_tag`). **Its own engine**, because Qt's
player can't change tempo without pitch or play backwards: `dj/loader.py` player can't change tempo without pitch or play backwards: `dj/loader.py`
+1 -1
View File
@@ -1,3 +1,3 @@
"""LinTunes — iTunes-style music library manager and player for Linux.""" """LinTunes — iTunes-style music library manager and player for Linux."""
__version__ = "0.63.0" __version__ = "0.63.1"
+18 -7
View File
@@ -513,8 +513,10 @@ class DjShelf(QWidget):
slider.setToolTip(f"Deck {v.name} speed (double-click: back to 0)") slider.setToolTip(f"Deck {v.name} speed (double-click: back to 0)")
slider.valueChanged.connect(lambda value, v=v: self._on_speed(v, value)) slider.valueChanged.connect(lambda value, v=v: self._on_speed(v, value))
slider.mouseDoubleClickEvent = lambda e, s=slider: s.setValue(0) slider.mouseDoubleClickEvent = lambda e, s=slider: s.setValue(0)
label = QLabel("0.0%") label = QLabel("+0.0%")
label.setStyleSheet(f"color: {v.color.name()};") label.setStyleSheet(f"color: {v.color.name()}; font-size: 11px;")
label.setAlignment(Qt.AlignmentFlag.AlignCenter)
label.setMinimumWidth(60)
for w in (top, bottom): for w in (top, bottom):
w.setStyleSheet(f"color: {DIM}; font-size: 10px;") w.setStyleSheet(f"color: {DIM}; font-size: 10px;")
for w in (top, slider, bottom, label): for w in (top, slider, bottom, label):
@@ -522,7 +524,7 @@ class DjShelf(QWidget):
col.setStretch(1, 1) col.setStretch(1, 1)
holder = QWidget() holder = QWidget()
holder.setLayout(col) holder.setLayout(col)
holder.setFixedWidth(58) holder.setFixedWidth(64)
self.speed[v.name] = slider self.speed[v.name] = slider
self.speed_label[v.name] = label self.speed_label[v.name] = label
self._compact_hidden.append(holder) self._compact_hidden.append(holder)
@@ -555,6 +557,7 @@ class DjShelf(QWidget):
sync.clicked.connect(lambda _=False, v=v: self.sync(v)) sync.clicked.connect(lambda _=False, v=v: self.sync(v))
for w in (play, sync): for w in (play, sync):
w.setStyleSheet(_deck_button_qss(v.name)) w.setStyleSheet(_deck_button_qss(v.name))
w.setFocusPolicy(Qt.FocusPolicy.NoFocus) # Space/Return mean nothing here
buttons.addWidget(play) buttons.addWidget(play)
buttons.addWidget(sync, stretch=1) buttons.addWidget(sync, stretch=1)
self.play_buttons[v.name] = play self.play_buttons[v.name] = play
@@ -616,6 +619,7 @@ class DjShelf(QWidget):
line.addLayout(nums) line.addLayout(nums)
pitch = QCheckBox("Keep pitch") pitch = QCheckBox("Keep pitch")
pitch.setChecked(True) pitch.setChecked(True)
pitch.setFocusPolicy(Qt.FocusPolicy.NoFocus)
pitch.setStyleSheet(_deck_button_qss(v.name)) pitch.setStyleSheet(_deck_button_qss(v.name))
pitch.setToolTip("On: a faster song stays in its key. Off: pitch " pitch.setToolTip("On: a faster song stays in its key. Off: pitch "
"follows speed, like a turntable") "follows speed, like a turntable")
@@ -857,11 +861,16 @@ class DjShelf(QWidget):
def sync(self, view: DeckView): def sync(self, view: DeckView):
"""Tempo to the other deck's; while both play, the beats too.""" """Tempo to the other deck's; while both play, the beats too."""
other = self.other(view) other = self.other(view)
if view.deck.source is None or other.deck.source is None: if view.deck.source is None:
self.message.emit("Sync needs a song on both decks.") return
if other.deck.source is None:
self.message.emit(f"Load a song on Deck {other.name} to sync to it."
if other.track is None else
f"Deck {other.name} is still loading.")
return return
if not view.bpm or not other.bpm: if not view.bpm or not other.bpm:
self.message.emit("Sync needs both songs' tempo, and one has no beat to find.") missing = view if not view.bpm else other
self.message.emit(f"Can't sync: no beat was found in “{missing.track.name}”.")
return return
target = other.bpm * other.deck.speed target = other.bpm * other.deck.speed
view.deck.speed = analysis.sync_ratio(view.bpm, target) view.deck.speed = analysis.sync_ratio(view.bpm, target)
@@ -928,7 +937,9 @@ class DjShelf(QWidget):
self.play_buttons[view.name].setIcon(QIcon(_play_icon(deck.playing))) self.play_buttons[view.name].setIcon(QIcon(_play_icon(deck.playing)))
loaded = deck.source is not None loaded = deck.source is not None
self.play_buttons[view.name].setEnabled(loaded) self.play_buttons[view.name].setEnabled(loaded)
self.sync_buttons[view.name].setEnabled(loaded and self.other(view).deck.source is not None) # Always clickable once this deck has a song: whatever sync can't do
# yet (an empty other deck, a tempo still being worked out) it says.
self.sync_buttons[view.name].setEnabled(loaded)
self._refresh_note(view) self._refresh_note(view)
def _tick(self): def _tick(self):
+2 -2
View File
@@ -2315,8 +2315,7 @@ class MainWindow(QMainWindow):
from lintunes.gui import track_table from lintunes.gui import track_table
if on: if on:
shelf = self._ensure_dj() shelf = self._ensure_dj()
if self.player.is_playing(): self.player.set_suspended(True) # pauses it, and keeps it so
self.player.pause()
target = self._dj_target_height() target = self._dj_target_height()
self._transport.set_dj_mode(True, self._dj_titles()) self._transport.set_dj_mode(True, self._dj_titles())
track_table.deck_tag = self._deck_tag track_table.deck_tag = self._deck_tag
@@ -2397,6 +2396,7 @@ class MainWindow(QMainWindow):
return # reopened mid-close return # reopened mid-close
self._dj.stop() self._dj.stop()
self._dj.hide() self._dj.hide()
self.player.set_suspended(False)
self._transport.set_dj_mode(False) self._transport.set_dj_mode(False)
def _on_dj_resize(self, dy: int): def _on_dj_resize(self, dy: int):
+17 -1
View File
@@ -586,7 +586,19 @@ class Player(QObject):
# ---- queue ---- # ---- queue ----
# DJ mode (Round 93) has its own decks; while it's open nothing may
# start this player — a double-click, Return or a media key would play
# behind the decks with the main transport greyed out, unstoppable.
suspended = False
def set_suspended(self, on: bool):
self.suspended = bool(on)
if on:
self.pause()
def play_queue(self, track_ids: list[int], start_index: int): def play_queue(self, track_ids: list[int], start_index: int):
if self.suspended:
return
self._queue = list(track_ids) self._queue = list(track_ids)
self._index = start_index self._index = start_index
self._reshuffle() self._reshuffle()
@@ -801,6 +813,8 @@ class Player(QObject):
# ---- transport ---- # ---- transport ----
def toggle_play(self): def toggle_play(self):
if self.suspended and not self.is_playing():
return
log_control("player", "toggle_play", log_control("player", "toggle_play",
f"playing={self.is_playing()} pos={self.position_ms()}ms " f"playing={self.is_playing()} pos={self.position_ms()}ms "
f"track={self._current_track.name if self._current_track else None!r}") f"track={self._current_track.name if self._current_track else None!r}")
@@ -833,12 +847,14 @@ class Player(QObject):
self.track_changed.emit(None) self.track_changed.emit(None)
def next(self): def next(self):
if self.suspended:
return
# When paused/stopped, skipping only cues the new track; audio # When paused/stopped, skipping only cues the new track; audio
# starts only if we were already playing. # starts only if we were already playing.
self._advance(autoplay=self.is_playing()) self._advance(autoplay=self.is_playing())
def previous(self): def previous(self):
if not self._queue: if not self._queue or self.suspended:
return return
prev_index = self._step_index(-1) prev_index = self._step_index(-1)
if self.position_ms() > RESTART_THRESHOLD_MS or prev_index is None: if self.position_ms() > RESTART_THRESHOLD_MS or prev_index is None:
+48
View File
@@ -295,3 +295,51 @@ def test_dj_mode_greys_the_transport_and_ignores_space(qapp, tmp_path, monkeypat
assert track_table.deck_tag is None assert track_table.deck_tag is None
finally: finally:
window.close() window.close()
# ---- Round 93 fixes: nothing starts the main player; sync always clickable ----
def test_a_suspended_player_cannot_be_started(qapp, tmp_path):
from tests.test_round29 import _FakeSink, _local_track, _player
tracks = [_local_track(tmp_path, i) for i in range(1, 4)]
player = _player(qapp, tracks)
sink = _FakeSink()
player.set_sink(sink)
player.set_suspended(True)
player.play_queue([1, 2, 3], 0)
player.toggle_play()
player.next()
assert player.current_track is None and not sink.loads
player.set_suspended(False)
player.play_queue([1, 2, 3], 0)
assert player.current_track.track_id == 1
def test_return_on_a_song_does_nothing_in_dj_mode(qapp, tmp_path, monkeypatch):
from lintunes.gui.main_window import MainWindow
from lintunes.library_manager import LibraryManager
from lintunes.models.library import Library
from lintunes.preferences import Preferences
monkeypatch.setattr("lintunes.gui.main_window.load_config", lambda: {})
monkeypatch.setattr("lintunes.gui.main_window.save_config", lambda c: None)
window = MainWindow(LibraryManager(Library(), tmp_path), Preferences(tmp_path))
try:
window.set_dj_mode(True)
assert window.player.suspended
window.set_dj_mode(False)
window._dj_anim.stop()
window._dj_closed()
assert not window.player.suspended
finally:
window.close()
def test_sync_is_clickable_with_one_deck_and_says_why(shelf):
a, _ = shelf.views
_loaded(shelf, a, shelf.tracks[0], _clicks(124, 0.1, 5), 124.0, 0.1)
assert shelf.sync_buttons["A"].isEnabled()
said = []
shelf.message.connect(said.append)
shelf.sync(a)
assert said and "Deck B" in said[0]
assert a.deck.speed == 1.0