v0.66.0: DJ mode's djay layout, loops, a sync that sets once, a real horn, a smooth slide
- Records in the top corners, each deck's controls beside them facing the middle, the zoomed A-over-B waveforms in the centre, and a whole-song overview per deck below (click to jump, drag to move) with the crossfader between them. - Loops per deck: Loop plus a 1/32 to 8 beat stepper; a loop starts on the next beat and shows on both waveforms. - Sync sets this deck to the other's tempo once, and stays lit only while that still holds. - The air horn plays like a real one: every press a fresh blast, held it carries the note, let go it stops. - Opening and closing DJ mode slides a picture over the final layout instead of re-laying-out the window every frame (the flicker). - Tests: garbage is collected on the main thread after each test, which stops a rare segfault in the full run.
This commit is contained in:
@@ -155,3 +155,15 @@ def syncthing_pair(tmp_path):
|
||||
yield instances
|
||||
finally:
|
||||
pair.stop(out)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _collect_on_the_main_thread():
|
||||
"""Python's garbage collector runs on whichever thread happens to
|
||||
trigger it — a worker's included — and a Qt object left over from a
|
||||
test, destroyed off the GUI thread, segfaults later (the rare crash in
|
||||
test_round72's maximized window, Rounds 94–96). Collecting here, after
|
||||
every test, on this thread, leaves workers nothing Qt to collect."""
|
||||
yield
|
||||
import gc
|
||||
gc.collect(1) # the young generations: what a test just left
|
||||
|
||||
@@ -266,7 +266,7 @@ def test_height_bounds():
|
||||
low, high = height_bounds(1000, 22)
|
||||
assert (low, high) == (1000 - 28 * 22, 1000 - 5 * 22)
|
||||
assert default_height(1000, 22) == 1000 - 15 * 22
|
||||
assert default_height(400, 22) == 320 # the full layout at least
|
||||
assert default_height(400, 22) == 380 # the full layout at least (Round 96)
|
||||
|
||||
|
||||
# ---- the window ----
|
||||
|
||||
+8
-37
@@ -57,13 +57,10 @@ class TestSync:
|
||||
_loaded(shelf, b, shelf.tracks[1], _clicks(118, 0.05, 20), 118.0, 0.05)
|
||||
return a, b
|
||||
|
||||
def test_sync_sticks_glows_and_follows(self, shelf):
|
||||
def test_sync_glows_while_it_holds(self, shelf):
|
||||
a, b = self._pair(shelf)
|
||||
shelf.sync(b)
|
||||
assert b.synced and shelf.sync_buttons["B"].text() == "Synced"
|
||||
shelf.speed["A"].setValue(200) # A +2 %: B follows
|
||||
shelf._tick()
|
||||
assert b.deck.speed == pytest.approx(124 * 1.02 / 118)
|
||||
shelf.speed["B"].setValue(0) # B moved by hand: unsynced
|
||||
assert not b.synced
|
||||
assert shelf.sync_buttons["B"].text() == "Sync to other track"
|
||||
@@ -93,39 +90,13 @@ class TestSync:
|
||||
assert a.deck.position == 0 and not a.deck.ended
|
||||
|
||||
|
||||
class TestHorn:
|
||||
def _horn(self):
|
||||
x = (np.sin(np.arange(RATE * 2) / RATE * 2 * np.pi * 400) * 20000).astype(np.int16)
|
||||
return Horn(np.stack([x, x], axis=1))
|
||||
|
||||
def _drain(self, horn):
|
||||
total = 0
|
||||
while True:
|
||||
block = horn.render(4096)
|
||||
if block is None:
|
||||
return total / RATE
|
||||
total += len(block)
|
||||
|
||||
def test_a_tap_plays_the_whole_recording(self):
|
||||
horn = self._horn()
|
||||
horn.press()
|
||||
horn.render(441)
|
||||
horn.release()
|
||||
assert 0.01 + self._drain(horn) == pytest.approx(2.0, abs=0.1)
|
||||
|
||||
def test_holding_stretches_it(self):
|
||||
horn = self._horn()
|
||||
horn.press()
|
||||
held = sum(len(horn.render(4096)) for _ in range(int(4 * RATE / 4096))) / RATE
|
||||
horn.release()
|
||||
assert held > 3.9
|
||||
assert self._drain(horn) <= 2.0 # then the rest plays out
|
||||
|
||||
def test_the_bundled_recording_loads(self, qapp):
|
||||
from lintunes.gui.dj_shelf import _load_horn
|
||||
horn = Horn()
|
||||
_load_horn(horn)
|
||||
assert horn._src is not None and len(horn._src) > RATE
|
||||
def test_the_bundled_horn_recording_loads(qapp):
|
||||
# (Round 96 replaced "a tap plays the whole phrase" with the way a DJ
|
||||
# horn really plays — see test_round96.TestHorn.)
|
||||
from lintunes.gui.dj_shelf import _load_horn
|
||||
horn = Horn()
|
||||
_load_horn(horn)
|
||||
assert horn._held is not None and len(horn._held) > RATE
|
||||
|
||||
|
||||
def test_the_waveform_zooms_out_while_paused(shelf):
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
"""Round 96: the DJ shelf's new layout (records in the corners, controls
|
||||
facing the middle, whole-song overviews below the zoomed pair), loops, a
|
||||
sync that sets once, the air horn as a real one plays, and the open/close
|
||||
slide."""
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from lintunes.dj.audio import RATE, Deck, Horn, Source
|
||||
from tests.test_round93 import _clicks, _loaded, shelf # noqa: F401 — the fixture
|
||||
|
||||
|
||||
def _pair(shelf):
|
||||
a, b = shelf.views
|
||||
_loaded(shelf, a, shelf.tracks[0], _clicks(124, 0.15, 20), 124.0, 0.15)
|
||||
_loaded(shelf, b, shelf.tracks[1], _clicks(118, 0.05, 20), 118.0, 0.05)
|
||||
return a, b
|
||||
|
||||
|
||||
class TestSyncSetsOnce:
|
||||
def test_the_other_deck_moving_leaves_this_tempo(self, shelf):
|
||||
a, b = _pair(shelf)
|
||||
shelf.sync(b)
|
||||
speed = b.deck.speed
|
||||
shelf.speed["A"].setValue(200) # A +2 %
|
||||
shelf._tick()
|
||||
assert b.deck.speed == pytest.approx(speed) # B stays where it was set
|
||||
assert not b.synced # …and is no longer lit
|
||||
|
||||
def test_a_new_song_on_the_other_deck_unlights_it(self, shelf):
|
||||
a, b = _pair(shelf)
|
||||
shelf.sync(b)
|
||||
_loaded(shelf, a, shelf.tracks[1], _clicks(118, 0.05, 20), 118.0, 0.05)
|
||||
shelf._tick()
|
||||
assert not b.synced and b.deck.speed == pytest.approx(124 / 118)
|
||||
|
||||
|
||||
class TestLoops:
|
||||
def test_engine_wraps_at_the_loop_end(self):
|
||||
x = np.arange(RATE * 10)
|
||||
tone = np.stack([(np.sin(x / RATE * 2 * np.pi * 200) * 10000).astype(np.int16)] * 2, 1)
|
||||
deck = Deck("A")
|
||||
deck.load(Source(tone))
|
||||
deck.playing = True
|
||||
deck.position = RATE * 1.0
|
||||
deck.loop = (RATE, RATE + 11025)
|
||||
for _ in range(100):
|
||||
deck.render(1024)
|
||||
assert RATE <= deck.position < RATE + 11025 + 1024
|
||||
|
||||
def test_starts_on_the_next_beat_and_shows_its_size(self, shelf):
|
||||
a, _ = _pair(shelf)
|
||||
a.deck.position = RATE * 3.0
|
||||
shelf.set_loop(a, True)
|
||||
start, end = a.deck.loop
|
||||
beat = 60 / 124
|
||||
k = (start / RATE - 0.15) / beat
|
||||
assert k == pytest.approx(round(k), abs=1e-3) # on a beat
|
||||
assert start / RATE >= 3.0 - 1e-3 # the next one
|
||||
assert (end - start) / RATE == pytest.approx(4 * beat, abs=1e-3)
|
||||
shelf.step_loop(a, -2) # 4 → 1 beat
|
||||
assert shelf.loop_sizes["A"].text() == "1"
|
||||
assert (a.deck.loop[1] - a.deck.loop[0]) / RATE == pytest.approx(beat, abs=1e-3)
|
||||
shelf.step_loop(a, -5) # → 1/32
|
||||
assert shelf.loop_sizes["A"].text() == "1/32"
|
||||
shelf.set_loop(a, False)
|
||||
assert a.deck.loop is None
|
||||
|
||||
def test_loading_a_song_drops_the_loop(self, shelf):
|
||||
a, _ = _pair(shelf)
|
||||
shelf.set_loop(a, True)
|
||||
_loaded(shelf, a, shelf.tracks[1], _clicks(118, 0.05, 20), 118.0, 0.05)
|
||||
assert a.deck.loop is None and not shelf.loop_buttons["A"].isChecked()
|
||||
|
||||
|
||||
def test_the_overview_jumps(shelf):
|
||||
from PyQt6.QtCore import QEvent, QPointF, Qt
|
||||
from PyQt6.QtGui import QMouseEvent
|
||||
a, _ = _pair(shelf)
|
||||
ov = shelf.overviews["A"]
|
||||
ov.resize(400, 64)
|
||||
event = QMouseEvent(QEvent.Type.MouseButtonPress, QPointF(200, 30), QPointF(200, 30),
|
||||
Qt.MouseButton.LeftButton, Qt.MouseButton.LeftButton,
|
||||
Qt.KeyboardModifier.NoModifier)
|
||||
ov.mousePressEvent(event)
|
||||
assert a.deck.position / RATE == pytest.approx(a.deck.source.seconds / 2, abs=0.1)
|
||||
ov.grab() # paints without trouble
|
||||
|
||||
|
||||
class TestHorn:
|
||||
def _horn(self):
|
||||
x = (np.sin(np.arange(RATE * 2) / RATE * 2 * np.pi * 400) * 20000).astype(np.int16)
|
||||
return Horn(np.stack([x, x], axis=1))
|
||||
|
||||
def _drain(self, horn):
|
||||
total = 0
|
||||
while True:
|
||||
block = horn.render(1024)
|
||||
if block is None:
|
||||
return total / RATE
|
||||
total += len(block)
|
||||
|
||||
def test_a_tap_is_short(self):
|
||||
horn = self._horn()
|
||||
horn.press()
|
||||
horn.render(2205)
|
||||
horn.release()
|
||||
assert self._drain(horn) < 0.15
|
||||
|
||||
def test_holding_carries_the_note_even_after_taps(self):
|
||||
horn = self._horn()
|
||||
for _ in range(6):
|
||||
horn.press()
|
||||
horn.render(1024)
|
||||
horn.release()
|
||||
horn.render(1024)
|
||||
horn.press()
|
||||
for _ in range(int(3 * RATE / 1024)):
|
||||
block = horn.render(1024)
|
||||
assert np.abs(block).max() > 0.1 # still blaring at 3 s
|
||||
horn.release()
|
||||
assert self._drain(horn) < 0.15
|
||||
|
||||
def test_a_press_while_ringing_starts_a_new_blast(self):
|
||||
horn = self._horn()
|
||||
horn.press()
|
||||
horn.render(4410)
|
||||
horn.press()
|
||||
assert len(horn._voices) == 2 and horn._voices[0]["fading"]
|
||||
assert horn._voices[-1]["pos"] == 0
|
||||
|
||||
|
||||
def test_dj_mode_slides(qapp, tmp_path, monkeypatch):
|
||||
from lintunes.gui.main_window import MainWindow
|
||||
from lintunes.library_manager import LibraryManager
|
||||
from lintunes.models.library import Library
|
||||
from lintunes.preferences import Preferences
|
||||
monkeypatch.setattr("lintunes.gui.main_window.load_config", lambda: {})
|
||||
monkeypatch.setattr("lintunes.gui.main_window.save_config", lambda c: None)
|
||||
window = MainWindow(LibraryManager(Library(), tmp_path), Preferences(tmp_path))
|
||||
try:
|
||||
window.resize(1100, 760)
|
||||
window.show()
|
||||
qapp.processEvents()
|
||||
window.set_dj_mode(True)
|
||||
overlay = window._dj_overlay
|
||||
assert overlay is not None and overlay.opening
|
||||
# the real window is already in its final layout under the picture
|
||||
assert window._dj.height() == window._dj.layout_height() > 0
|
||||
window._dj_anim.stop()
|
||||
window.set_dj_mode(False)
|
||||
assert not window._dj.isVisible() # final layout at once
|
||||
assert window._dj_overlay is not None and not window._dj_overlay.opening
|
||||
window._dj_anim.stop()
|
||||
finally:
|
||||
window.close()
|
||||
Reference in New Issue
Block a user