v0.63.0: DJ mode — two decks, sync, keep-pitch speed, scratching, vocal stems

View > DJ Mode (or the turntable button under BPM) parts the window under
the transport boxes and opens a dark shelf: a record per deck (drag a song
on to load it; drag the record to scratch), play/pause and Sync to other
track beside it, a ±8% speed fader on each edge, Keep pitch, the two
waveforms stacked around one playhead, a vocals/instrumental slider and
the crossfader. Deck A is blue, Deck B orange; loaded songs are tagged in
the lists.

Its own engine (lintunes/dj): whole-song decode, tempo refined to 0.01
BPM plus the first beat (exact on synthetic kicks), WSOLA time-stretch or
varispeed, a QAudioSink on its own thread. Sync matches tempo and, while
both play, nudges the beats into line. A missing BPM is calculated and
saved. Vocals come from Demucs, run once per song in the background and
cached; Demucs lives in its own venv.
This commit is contained in:
2026-10-17 02:06:45 -07:00
parent 7ad51ab4dc
commit 57cc5d5289
14 changed files with 2428 additions and 3 deletions
+168
View File
@@ -158,6 +158,12 @@ class MainWindow(QMainWindow):
self._transport = TransportBar(self.player, manager, self._prefs,
cast=self._cast, airplay=self._airplay)
layout.addWidget(self._transport)
# DJ mode (Round 93): the shelf is made the first time it opens.
self._dj = None
self._dj_on = False
self._dj_anim = None
self._dj_resize_from = None
self._transport.dj_toggled.connect(self.set_dj_mode)
splitter = QSplitter(Qt.Orientation.Horizontal)
# The handle is the gap between the playlists and the songs: as wide
@@ -484,6 +490,11 @@ class MainWindow(QMainWindow):
view_menu = bar.addMenu("&View")
self._add_action(view_menu, "Toggle Column Browser", "Ctrl+B",
self._library_view.toggle_browser)
view_menu.addSeparator()
self._dj_action = QAction("DJ Mode", self)
self._dj_action.setCheckable(True)
self._dj_action.toggled.connect(self.set_dj_mode)
view_menu.addAction(self._dj_action)
track_menu = bar.addMenu("&Track")
self._add_action(track_menu, "Get Info", "Ctrl+I", self._info_for_current_view)
@@ -2272,6 +2283,8 @@ class MainWindow(QMainWindow):
def play_pause(self):
"""Play/pause like iTunes: with nothing cued, start the visible
view's tracks (from the selected row, else the top)."""
if getattr(self, "_dj_on", False):
return # each deck has its own play button
if self.player.current_track is not None:
self.player.toggle_play()
return
@@ -2283,6 +2296,157 @@ class MainWindow(QMainWindow):
start = selected[0].row() if selected else 0
self._play_from_view(view, ids, start)
# ---- DJ mode ----
ANIMATE_MS = 350
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."""
on = bool(on)
if on == self._dj_on:
return
self._dj_on = on
if self._dj_action.isChecked() != on:
self._dj_action.blockSignals(True)
self._dj_action.setChecked(on)
self._dj_action.blockSignals(False)
from lintunes.gui import track_table
if on:
shelf = self._ensure_dj()
if self.player.is_playing():
self.player.pause()
target = self._dj_target_height()
self._transport.set_dj_mode(True, self._dj_titles())
track_table.deck_tag = self._deck_tag
shelf.set_master(self._dj_master())
shelf.setFixedHeight(0)
shelf.show()
shelf.start()
self._animate_shelf(0, target)
else:
shelf = self._dj
track_table.deck_tag = None
self._animate_shelf(shelf.height(), 0, done=self._dj_closed)
self._refresh_tables()
def _ensure_dj(self):
if self._dj is None:
from lintunes.gui.dj_shelf import DjShelf
shelf = DjShelf(self._manager)
shelf.hide()
shelf.message.connect(lambda msg: self.statusBar().showMessage(msg, 8000))
shelf.decks_changed.connect(self._on_decks_changed)
shelf.resize_requested.connect(self._on_dj_resize)
shelf.resize_finished.connect(self._on_dj_resize_done)
shelf.resize_reset.connect(self._on_dj_resize_reset)
self._transport.volume_level_changed.connect(
lambda _level: shelf.set_master(self._dj_master()))
self._transport.insert_shelf(shelf)
self._dj = shelf
return self._dj
def _dj_master(self) -> float:
"""The volume slider as linear gain, through Qt's curve, so a
position is as loud in DJ mode as out of it."""
from PyQt6.QtMultimedia import QAudio
return QAudio.convertVolume(
self._transport.volume_level(),
QAudio.VolumeScale.LogarithmicVolumeScale,
QAudio.VolumeScale.LinearVolumeScale)
def _dj_geometry(self) -> tuple[int, int, int]:
"""(viewport with the shelf closed, row height, current shelf)."""
table = self._content.currentWidget().table
row = table.verticalHeader().defaultSectionSize()
current = self._dj.height() if self._dj is not None and self._dj.isVisible() else 0
return table.viewport().height() + current, row, current
def _dj_bounds(self) -> tuple[int, int]:
from lintunes.gui.dj_shelf import height_bounds
viewport, row, _ = self._dj_geometry()
return height_bounds(viewport, row)
def _dj_target_height(self) -> int:
from lintunes.gui.dj_shelf import default_height
viewport, row, _ = self._dj_geometry()
low, high = self._dj_bounds()
saved = load_config().get("dj_shelf_height")
target = int(saved) if isinstance(saved, (int, float)) else default_height(viewport, row)
return max(low, min(high, target))
def _animate_shelf(self, start: int, end: int, done=None):
from PyQt6.QtCore import QEasingCurve, QVariantAnimation
if self._dj_anim is not None:
self._dj_anim.stop()
anim = QVariantAnimation(self)
anim.setStartValue(int(start))
anim.setEndValue(int(end))
anim.setDuration(self.ANIMATE_MS)
anim.setEasingCurve(QEasingCurve.Type.OutCubic if end > start
else QEasingCurve.Type.InCubic)
anim.valueChanged.connect(lambda v: self._dj.setFixedHeight(int(v)))
if done is not None:
anim.finished.connect(done)
self._dj_anim = anim
anim.start()
def _dj_closed(self):
if self._dj_on:
return # reopened mid-close
self._dj.stop()
self._dj.hide()
self._transport.set_dj_mode(False)
def _on_dj_resize(self, dy: int):
if self._dj_anim is not None and self._dj_anim.state() == self._dj_anim.State.Running:
return
if self._dj_resize_from is None:
self._dj_resize_from = self._dj.height()
low, high = self._dj_bounds()
self._dj.setFixedHeight(max(low, min(high, self._dj_resize_from + dy)))
def _on_dj_resize_done(self):
self._dj_resize_from = None
config = load_config()
config["dj_shelf_height"] = self._dj.height()
save_config(config)
def _on_dj_resize_reset(self):
from lintunes.gui.dj_shelf import default_height
viewport, row, _ = self._dj_geometry()
low, high = self._dj_bounds()
config = load_config()
config.pop("dj_shelf_height", None)
save_config(config)
self._animate_shelf(self._dj.height(),
max(low, min(high, default_height(viewport, row))))
def _deck_tag(self, track_id: int):
if self._dj is None:
return None
name = self._dj.deck_of(track_id)
if name is None:
return None
from lintunes.gui.dj_shelf import COLORS
return name, COLORS[name].darker(115)
def _dj_titles(self) -> str:
if self._dj is None:
return ""
names = [v.track.name for v in self._dj.views if v.track is not None]
return " × ".join(names)
def _on_decks_changed(self, _decks: dict):
if self._dj_on:
self._transport.set_dj_titles(self._dj_titles())
self._refresh_tables()
def _refresh_tables(self):
for view in (self._library_view, self._playlist_view):
view.table.viewport().update()
def _play_from_view(self, view, ids, start):
"""Start playback, recording which view it came from so the now-playing
icon (and Go to Current Song) can find the right context."""
@@ -2352,6 +2516,8 @@ class MainWindow(QMainWindow):
self._log_key(event, "space")
self.play_pause()
return True
if key in (Qt.Key.Key_Right, Qt.Key.Key_Left) and getattr(self, "_dj_on", False):
return True # no queue to step through in DJ mode
if key == Qt.Key.Key_Right:
self._log_key(event, "right")
self.player.next()
@@ -2423,6 +2589,8 @@ class MainWindow(QMainWindow):
self._cassette.shutdown()
self._cast.shutdown()
self._airplay.shutdown()
if self._dj is not None:
self._dj.stop() # its audio thread must end before Qt does
self.player.shutdown()
self.player.loudness.save()
self._manager.flush()