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
+43
View File
@@ -341,6 +341,49 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal
`tests/kaleidostrobe_golden.npz` was recorded from the emulated original
and `test_round84` holds the port to it byte for byte.
- **`lintunes/dj/`** + **`gui/dj_shelf.py`** — DJ mode (Round 93; View ›
DJ Mode or the turntable button under BPM). The window parts **under the
row of transport boxes** (`TransportBar.insert_shelf`: the Library button's
header row slides down with the lists) and a dark shelf shows in the gap,
animated open and closed (`MainWindow.set_dj_mode`). Default height leaves
~15 songs below (at least the full 320 px layout), the grip resizes it
between ~28 and ~5 songs below (`height_bounds`), saved as config.json's
`dj_shelf_height`; under 200 px it's one compact strip. **Manual, like DJ
software**: a deck loads only by dragging a song onto its record (the
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,
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
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
player can't change tempo without pitch or play backwards: `dj/loader.py`
decodes the whole song (ffmpeg CLI, int16 stereo 44.1 kHz, ~50 MB per 5
min) and analyses it — `bpm_detect`'s tempo, refined to 0.01 BPM by which
tempo folds the onsets sharpest (`analysis.beat_grid`; 0.1 BPM off smears
two minutes of beats by a fifth of a beat), and the first beat from a
~3 ms energy-rise onset (`onset_times`; bpm_detect's 1024-sample flux
smears *when* by tens of ms). Both measured exact on synthetic kicks. A
file with no BPM gets it saved (`set_tracks_bpm`). `dj/audio.py` is pure
numpy: keep pitch = WSOLA (1024/512, ±256 search), Keep pitch off =
varispeed, scratching = varispeed at the hand's angular rate (one turn =
1.8 s, a 33⅓ record; letting go is normal speed at once). The mixer is
constant-power crossfade × master (the volume slider through Qt's curve).
`dj/output.py` feeds a QAudioSink from **its own QThread** (100 ms
buffered), so GUI painting can't starve it; it must stop before Qt quits
(`aboutToQuit`, `closeEvent`), and **tests stub it** (conftest
`_no_dj_sound`) — the decks would otherwise play out loud. Sync ("Sync to
other track", per deck): tempo to the other deck's (the nearest octave);
if both are playing, then the shortest beat nudge (`phase_shift`, never
more than half a beat). The waveforms are drawn in *heard* time around one
shared playhead, so synced beats sit exactly above each other. **Vocals**:
Demucs (htdemucs, two stems) splits each loaded song once in the
background into `$XDG_CACHE_HOME/lintunes/stems/<key>/` (path+size+mtime);
the slider blends vocals/instrumental live. Demucs + CPU PyTorch (~1 GB)
live in their own venv, `$XDG_DATA_HOME/lintunes/demucs`
(`stems.setup_command()`; it needs numpy installed explicitly), never a
pip dependency of LinTunes — without it the slider is disabled with that
command in its tooltip.
- **`lintunes/importers/itunes_importer.py`** — parses the iTunes XML plist.
Remaps Mac `file:///Volumes/...` paths to the local `--music-root` with
case/Unicode-normalization fuzzy matching (macOS is case-insensitive + NFD vs