v0.71.0: a tiny ✕ cancels a deck's vocals split
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
"""Round 102: the ✕ that cancels a deck's vocals split."""
|
||||
import threading
|
||||
import time
|
||||
|
||||
from PyQt6.QtWidgets import QApplication
|
||||
|
||||
from lintunes.dj import stems
|
||||
from tests.test_round93 import _clicks, _loaded, shelf # noqa: F401 — fixture
|
||||
|
||||
|
||||
def _wait(predicate, seconds=3.0):
|
||||
end = time.monotonic() + seconds
|
||||
while time.monotonic() < end:
|
||||
QApplication.processEvents()
|
||||
if predicate():
|
||||
return True
|
||||
time.sleep(0.01)
|
||||
return False
|
||||
|
||||
|
||||
def test_cancelling_the_running_split_stops_demucs(qapp, monkeypatch):
|
||||
started = threading.Event()
|
||||
|
||||
def fake_split(path, model, gentle, progress=None, cancel=None):
|
||||
started.set()
|
||||
while not cancel.wait(0.01):
|
||||
pass
|
||||
raise stems.Cancelled()
|
||||
|
||||
monkeypatch.setattr(stems, "cached", lambda path, model=None: None)
|
||||
monkeypatch.setattr(stems, "split", fake_split)
|
||||
splitter = stems.StemSplitter()
|
||||
called_off, done = [], []
|
||||
splitter.cancelled.connect(called_off.append)
|
||||
splitter.finished.connect(lambda p, f: done.append(p))
|
||||
splitter.request("/a.mp3")
|
||||
assert started.wait(2)
|
||||
splitter.cancel("/a.mp3")
|
||||
assert _wait(lambda: called_off == ["/a.mp3"])
|
||||
assert done == []
|
||||
|
||||
|
||||
def test_cancelling_a_queued_song_takes_it_out(qapp, monkeypatch):
|
||||
release = threading.Event()
|
||||
ran = []
|
||||
|
||||
def fake_split(path, model, gentle, progress=None, cancel=None):
|
||||
ran.append(path)
|
||||
release.wait(2)
|
||||
return {}
|
||||
|
||||
monkeypatch.setattr(stems, "cached", lambda path, model=None: None)
|
||||
monkeypatch.setattr(stems, "split", fake_split)
|
||||
splitter = stems.StemSplitter()
|
||||
called_off = []
|
||||
splitter.cancelled.connect(called_off.append)
|
||||
splitter.request("/a.mp3")
|
||||
assert _wait(lambda: ran == ["/a.mp3"])
|
||||
splitter.request("/b.mp3")
|
||||
assert _wait(lambda: "/b.mp3" in splitter._queue)
|
||||
splitter.cancel("/b.mp3")
|
||||
assert called_off == ["/b.mp3"] and "/b.mp3" not in splitter._queue
|
||||
release.set()
|
||||
time.sleep(0.1)
|
||||
assert ran == ["/a.mp3"]
|
||||
|
||||
|
||||
def test_the_x_shows_while_splitting_and_the_slider_retries(shelf, monkeypatch):
|
||||
from tests.test_round93 import RATE # noqa: F401
|
||||
asked, cancelled = [], []
|
||||
monkeypatch.setattr(stems, "available", lambda: True)
|
||||
monkeypatch.setattr(shelf._splitter, "request", asked.append)
|
||||
monkeypatch.setattr(shelf._splitter, "cancel", cancelled.append)
|
||||
a, _ = shelf.views
|
||||
_loaded(shelf, a, shelf.tracks[0], _clicks(124, 0.1, 5), 124.0, 0.1)
|
||||
x = shelf.stem_cancel["A"]
|
||||
assert asked == ["/x.mp3"]
|
||||
assert not x.isHidden() and x.toolTip() == "cancel vocals split"
|
||||
assert not shelf.vocal_sliders["A"].isEnabled()
|
||||
x.click()
|
||||
assert cancelled == ["/x.mp3"]
|
||||
shelf._on_stem_cancelled("/x.mp3") # what the splitter answers
|
||||
assert x.isHidden()
|
||||
assert "cancelled" in shelf.stem_labels["A"].text()
|
||||
slider = shelf.vocal_sliders["A"]
|
||||
assert slider.isEnabled()
|
||||
slider.sliderPressed.emit()
|
||||
assert asked == ["/x.mp3", "/x.mp3"]
|
||||
assert not x.isHidden()
|
||||
slider.sliderPressed.emit() # already splitting: no second ask
|
||||
assert asked == ["/x.mp3", "/x.mp3"]
|
||||
Reference in New Issue
Block a user