Files
lintunes/tests/test_round96.py
T
trav 0f535a4ca3 v0.67.0: the air horn done properly; djay-style loops; a gentler grab zoom
Air horn: the recording's first blast wobbles on a ~0.15 s cycle, so the
old 0.30 s loop jumped every lap (the repeating beat). Held, it now loops
exactly one cycle (found by self-similarity), levelled and crossfaded;
a release crossfades into the recording's own ending, so a click is a
short blast that trails off; each press cuts a still-sounding blast in
25 ms, so taps stay separate. Exact at any block size.

Loops start on the nearest beat (djay's Quantize), and resizing a running
loop keeps its start and keeps looping. Grabbing a waveform zooms out
only a little, gently, and drags at the zoom it was grabbed at. The sync
button just says Sync.
2026-10-17 22:44:45 -07:00

114 lines
4.7 KiB
Python

"""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_nearest_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 abs(start / RATE - 3.0) <= beat / 2 + 1e-3 # the nearest one (Round 97)
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
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()