Files
lintunes/tests/test_round135.py
T

90 lines
3.6 KiB
Python

"""Round 135: the DJ vocals slider's middle is a small line, and holding its
mic or note shows just that stem's waveform — without moving the slider."""
import numpy as np
from PyQt6.QtCore import QPoint, Qt
from PyQt6.QtGui import QColor
from PyQt6.QtTest import QTest
from lintunes.dj import analysis, stems
from tests.test_round93 import RATE, _clicks, _loaded, shelf # noqa: F401 — fixture
def _slider(qapp):
from lintunes.gui.dj_shelf import VocalSlider
slider = VocalSlider(QColor("#5a9be0"))
slider.resize(220, slider.height())
return slider
def test_holding_an_icon_previews_and_leaves_the_value(qapp):
slider = _slider(qapp)
seen = []
slider.preview.connect(seen.append)
for kind in ("vocals", "instrumental"):
at = slider._icon_rect(kind).center().toPoint()
QTest.mousePress(slider, Qt.MouseButton.LeftButton, pos=at)
assert slider.held == kind
QTest.mouseRelease(slider, Qt.MouseButton.LeftButton, pos=at)
assert slider.held is None
assert slider.value() == 0 # the sound never changes
assert seen == ["vocals", None, "instrumental", None]
def test_the_middle_is_not_a_preview_and_the_track_still_slides(qapp):
slider = _slider(qapp)
seen = []
slider.preview.connect(seen.append)
mid = QPoint(int(slider._pos_of(0)), 4)
QTest.mousePress(slider, Qt.MouseButton.LeftButton, pos=mid)
QTest.mouseRelease(slider, Qt.MouseButton.LeftButton, pos=mid)
assert seen == []
lo, _ = slider._span()
end = QPoint(int(lo), slider.height() - 6) # on the track, not the icons
QTest.mousePress(slider, Qt.MouseButton.LeftButton, pos=end)
QTest.mouseRelease(slider, Qt.MouseButton.LeftButton, pos=end)
assert slider.value() == -100
def test_the_waveforms_show_the_held_stem(shelf):
a, _ = shelf.views
_loaded(shelf, a, shelf.tracks[0], _clicks(124, 0.1, 5), 124.0, 0.1)
n = a.deck.source.frames
vocals = np.zeros((n, 2), np.int16)
vocals[: n // 2] = 8000
instrumental = np.full((n, 2), 4000, np.int16)
shelf._apply_stems("/x.mp3", (vocals, instrumental, "htdemucs"))
full = a.peaks
assert a.shown_peaks is full
shelf.vocal_sliders["A"].preview.emit("vocals")
np.testing.assert_allclose(a.shown_peaks, analysis.peaks(vocals, RATE))
shelf.vocal_sliders["A"].preview.emit("instrumental")
np.testing.assert_allclose(a.shown_peaks, analysis.peaks(instrumental, RATE))
shelf.vocal_sliders["A"].preview.emit(None)
assert a.shown_peaks is full
assert a.deck.vocal_mix == 0 # what plays is untouched
shelf.overviews["A"].grab() # paints with the stem's peaks
def test_the_zoomed_lanes_never_preview(shelf, monkeypatch):
from lintunes.gui import dj_shelf
a, _ = shelf.views
_loaded(shelf, a, shelf.tracks[0], _clicks(124, 0.1, 5), 124.0, 0.1)
n = a.deck.source.frames
shelf._apply_stems("/x.mp3", (np.zeros((n, 2), np.int16),
np.zeros((n, 2), np.int16), "htdemucs"))
shelf.set_preview(a, "vocals")
drawn = []
real = dj_shelf._pixel_max
monkeypatch.setattr(dj_shelf, "_pixel_max",
lambda peaks, *rest, **k: drawn.append(peaks) or real(peaks, *rest, **k))
shelf.lanes.grab()
assert any(d is a.peaks for d in drawn)
assert not any(d is a.stem_peaks["vocals"] for d in drawn)
def test_no_split_yet_shows_the_whole_song(shelf):
a, _ = shelf.views
_loaded(shelf, a, shelf.tracks[0], _clicks(124, 0.1, 5), 124.0, 0.1)
shelf.set_preview(a, "vocals")
assert a.shown_peaks is a.peaks