v0.83.0: Preferences › DJ shows the space saved vocal splits use and says what they are; README gets a DJ mode section

This commit is contained in:
2026-10-27 08:59:52 -07:00
parent cd4edcf81f
commit 5150a1d145
5 changed files with 152 additions and 20 deletions
+16
View File
@@ -129,6 +129,22 @@ _(written by LLM and cleaned up a bit by me)_
- Theming: highlight color, UI scale, and custom colors
- A soft emboss on every button that follows your custom colors.
**DJ mode** (View ▸ DJ Mode, or the turntable button)
- Two decks open above your library: drag a song onto a record to load it.
Each deck has play/pause, back-to-start, a tempo fader, volume, loops (1/32 to 8 beats), a
½×/1×/2× switch and **Keep pitch** (change tempo without changing key).
- **Sync** matches one deck's tempo and beat to the other's. BPM is worked
out when a song loads (and saved to the song).
- Grab a record to **scratch**; drag the waveforms to scrub. A crossfader
mixes the two, and there's an **air horn**.
- **Vocals slider**: each song is split into vocals and instrumental so you
can fade either out. *Instant* (Spleeter, seconds a song) or *High quality*
(Demucs, minutes a song); both are optional downloads, set up in
Preferences ▸ DJ. Splits are saved so a song is only split once (the limit
is in Preferences ▸ DJ), and **Prepare for DJ** on a playlist's right-click
menu splits everything ahead of time.
- If a song is playing when you open DJ mode, it carries on from Deck A.
**Sending music elsewhere**
- **Chromecast**
- **Export a playlist** (File ▸ Export Playlist…) — either a folder of
+1 -1
View File
@@ -1,3 +1,3 @@
"""LinTunes — iTunes-style music library manager and player for Linux."""
__version__ = "0.82.0"
__version__ = "0.83.0"
+6
View File
@@ -307,6 +307,12 @@ def _size(folder: Path) -> int:
return total
def cache_size() -> int:
"""Bytes the whole split cache takes on disk now (both engines)."""
root = cache_root()
return _size(root) if root.is_dir() else 0
def prune(limit_gb: float | None = None, keep: str | None = None) -> int:
"""Delete the songs used longest ago until the cache is under
``limit_gb`` (config.json's when None). ``keep`` (a key) is never
+56 -19
View File
@@ -9,7 +9,7 @@ from PyQt6.QtWidgets import (
QColorDialog, QMenu, QDoubleSpinBox, QComboBox, QInputDialog,
QMessageBox, QApplication, QSizePolicy,
)
from PyQt6.QtCore import Qt, QTimer
from PyQt6.QtCore import Qt, QTimer, pyqtSignal
from PyQt6.QtGui import QDoubleValidator, QFont, QColor, QFontInfo
from lintunes import loudness, theme
@@ -114,6 +114,9 @@ class PreferencesDialog(QDialog):
omitted the music-folder row is simply left out.
"""
# The split cache's size in bytes, measured on a worker thread.
_stem_cache_measured = pyqtSignal(int)
def __init__(self, prefs, lastfm, parent=None, *,
music_folder=None, on_music_folder_change=None):
super().__init__(parent)
@@ -143,7 +146,8 @@ class PreferencesDialog(QDialog):
("Appearance", [self._build_general_group(),
self._build_colors_group()]),
("Visualizer", [self._build_visualizer_group()]),
("DJ", [self._build_dj_engine_group(), self._build_dj_group()]),
("DJ", [self._build_dj_engine_group(), self._build_dj_group(),
self._build_dj_cache_group()]),
("Integrations", [self._build_lastfm_group(),
self._build_acoustid_group(),
self._build_web_server_group()])):
@@ -413,24 +417,10 @@ class PreferencesDialog(QDialog):
gentle.setChecked(stems.gentle_choice(self._prefs))
gentle.toggled.connect(lambda on: self._prefs.set("dj_stem_gentle", on))
form.addRow("", gentle)
cache = QLineEdit(f"{stems.cache_limit_gb():g}")
cache.setValidator(QDoubleValidator(0.0, 10000.0, 2, cache))
cache.setMaximumWidth(80)
cache.setToolTip("Separated songs are kept up to this much disk space "
"on this computer; past it, the songs used longest "
"ago are deleted (they're split again if needed).")
cache.editingFinished.connect(self._save_stem_cache_limit)
cache_row = QHBoxLayout()
cache_row.addWidget(cache)
cache_row.addWidget(QLabel("GB"))
cache_row.addStretch(1)
form.addRow("Keep up to:", cache_row)
self._dj_cache_edit = cache
if stems.available():
note = QLabel("Demucs is set up. Songs are split when they load onto "
"a deck, or ahead of time with a playlist's or "
"song's “Prepare for DJ”. Splits are kept, up to "
"the size above.")
"song's “Prepare for DJ”.")
else:
note = QLabel("Demucs isn't set up on this computer (a one-time ~1 GB "
"download). In a terminal:\n" + stems.setup_command())
@@ -441,6 +431,54 @@ class PreferencesDialog(QDialog):
self._dj_gentle_check = gentle
return group
def _build_dj_cache_group(self) -> QGroupBox:
"""How much disk the saved vocal splits (both engines) may take,
and how much they take now."""
from lintunes.dj import stems
group = QGroupBox("Saved vocal splits")
form = QFormLayout(group)
form.addRow(self._note(
"Each song split into vocals and instrumental is saved on this "
"computer, so the vocals slider works at once the next time it's "
"on a deck. Past the limit, the songs used longest ago are "
"deleted; they're split again if you load them later."))
cache = QLineEdit(f"{stems.cache_limit_gb():g}")
cache.setValidator(QDoubleValidator(0.0, 10000.0, 2, cache))
cache.setMaximumWidth(80)
cache.editingFinished.connect(self._save_stem_cache_limit)
cache_row = QHBoxLayout()
cache_row.addWidget(cache)
cache_row.addWidget(QLabel("GB"))
cache_row.addStretch(1)
form.addRow("Keep up to:", cache_row)
self._dj_cache_edit = cache
self._dj_cache_used = QLabel("Measuring…")
form.addRow("Using now:", self._dj_cache_used)
self._stem_cache_measured.connect(self._show_stem_cache_used)
self._measure_stem_cache()
return group
def _measure_stem_cache(self, prune_to: float | None = None):
"""Walk the cache off the GUI thread (pruning first, when given a
new limit) and report its size back through a signal."""
from lintunes.dj import stems
def work():
if prune_to is not None:
stems.prune(prune_to)
try:
self._stem_cache_measured.emit(stems.cache_size())
except RuntimeError:
pass # the dialog was closed meanwhile
threading.Thread(target=work, daemon=True,
name="lintunes-stems-measure").start()
def _show_stem_cache_used(self, size: int):
gb = size / 1024 ** 3
text = f"{gb:.2f} GB" if gb >= 0.1 else f"{size / 1024 ** 2:.0f} MB"
self._dj_cache_used.setText(text)
def _save_stem_cache_limit(self):
"""config.json, not preferences: how much disk to give the splits
is this machine's business. A lower limit applies at once."""
@@ -455,8 +493,7 @@ class PreferencesDialog(QDialog):
return
config[stems.CACHE_LIMIT_KEY] = value
save_config(config)
threading.Thread(target=stems.prune, args=(value,), daemon=True,
name="lintunes-stems-prune").start()
self._measure_stem_cache(prune_to=value)
# ---- Wrapped ----
+73
View File
@@ -0,0 +1,73 @@
"""Round 115: Preferences › DJ shows how much disk the saved vocal splits
take, in a group of their own that says what they are."""
import pytest
from PyQt6.QtWidgets import QGroupBox
from lintunes.dj import stems
@pytest.fixture
def cache(tmp_path, monkeypatch):
monkeypatch.setenv("XDG_CACHE_HOME", str(tmp_path / "cache"))
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path / "config"))
return tmp_path
def _split(name, size):
folder = stems.cache_root() / name / "htdemucs"
folder.mkdir(parents=True)
(folder / "vocals.opus").write_bytes(b"x" * size)
def _dialog(cache):
from lintunes.gui.preferences_dialog import PreferencesDialog
from lintunes.preferences import Preferences
from tests.test_round40 import _FakeLastFm
return PreferencesDialog(Preferences(cache), _FakeLastFm())
def _wait_for(qapp, condition):
import time
for _ in range(200):
qapp.processEvents()
if condition():
return
time.sleep(0.01)
raise AssertionError("timed out")
def test_cache_size_counts_every_split_and_an_empty_cache_is_zero(cache):
assert stems.cache_size() == 0
_split("a", 1000)
_split("b", 500)
assert stems.cache_size() == 1500
def test_the_dialog_shows_the_space_used(qapp, cache):
_split("a", 3 * 1024 ** 2)
dialog = _dialog(cache)
_wait_for(qapp, lambda: dialog._dj_cache_used.text() == "3 MB")
dialog.deleteLater()
def test_lowering_the_limit_prunes_then_remeasures(qapp, cache):
_split("a", 2 * 1024 ** 2)
dialog = _dialog(cache)
_wait_for(qapp, lambda: dialog._dj_cache_used.text() == "2 MB")
dialog._dj_cache_edit.setText("0")
dialog._save_stem_cache_limit()
_wait_for(qapp, lambda: dialog._dj_cache_used.text() == "0 MB")
dialog.deleteLater()
def test_the_limit_lives_in_its_own_explained_group(qapp, cache):
dialog = _dialog(cache)
from PyQt6.QtWidgets import QLabel
group = dialog._dj_cache_edit.parentWidget()
while not isinstance(group, QGroupBox):
group = group.parentWidget()
column = group.parentWidget().layout()
heading = column.itemAt(column.indexOf(group) - 1).widget()
assert isinstance(heading, QLabel)
assert heading.text() == "Saved vocal splits"
dialog.deleteLater()