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.
This commit is contained in:
@@ -63,7 +63,7 @@ class TestSync:
|
||||
assert b.synced and shelf.sync_buttons["B"].text() == "Synced"
|
||||
shelf.speed["B"].setValue(0) # B moved by hand: unsynced
|
||||
assert not b.synced
|
||||
assert shelf.sync_buttons["B"].text() == "Sync to other track"
|
||||
assert shelf.sync_buttons["B"].text() == "Sync" # Round 97: shorter
|
||||
|
||||
def test_only_one_deck_follows(self, shelf):
|
||||
a, b = self._pair(shelf)
|
||||
@@ -96,7 +96,7 @@ def test_the_bundled_horn_recording_loads(qapp):
|
||||
from lintunes.gui.dj_shelf import _load_horn
|
||||
horn = Horn()
|
||||
_load_horn(horn)
|
||||
assert horn._held is not None and len(horn._held) > RATE
|
||||
assert horn._src is not None and len(horn._src) > RATE
|
||||
|
||||
|
||||
def test_the_waveform_zooms_out_while_paused(shelf):
|
||||
@@ -104,11 +104,11 @@ def test_the_waveform_zooms_out_while_paused(shelf):
|
||||
_loaded(shelf, a, shelf.tracks[0], _clicks(124, 0.1, 10), 124.0, 0.1)
|
||||
lanes = shelf.lanes
|
||||
lanes.resize(600, 120)
|
||||
for _ in range(80):
|
||||
for _ in range(200):
|
||||
lanes.grab() # paused: eases out
|
||||
assert lanes._window["A"] == pytest.approx(16.0)
|
||||
assert lanes._window["A"] == pytest.approx(8.0 * 1.35, abs=0.05) # Round 97: gentler
|
||||
a.deck.playing = True
|
||||
for _ in range(80):
|
||||
for _ in range(200):
|
||||
lanes.grab()
|
||||
assert lanes._window["A"] == pytest.approx(8.0)
|
||||
|
||||
|
||||
+2
-45
@@ -48,7 +48,7 @@ class TestLoops:
|
||||
deck.render(1024)
|
||||
assert RATE <= deck.position < RATE + 11025 + 1024
|
||||
|
||||
def test_starts_on_the_next_beat_and_shows_its_size(self, shelf):
|
||||
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)
|
||||
@@ -56,7 +56,7 @@ class TestLoops:
|
||||
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 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"
|
||||
@@ -87,49 +87,6 @@ def test_the_overview_jumps(shelf):
|
||||
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
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
"""Round 97: the air horn done properly (a click trails off; a hold
|
||||
sustains one natural cycle, levelled, never a repeating beat; taps stay
|
||||
separate), djay-style loops (the nearest beat; resizing keeps looping),
|
||||
a gentler zoom-out when grabbing a waveform."""
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from lintunes.dj.audio import RATE, Horn
|
||||
from lintunes.dj.loader import decode
|
||||
from tests.test_round93 import _clicks, _loaded, shelf # noqa: F401 — the fixture
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def recording():
|
||||
from importlib import resources
|
||||
with resources.as_file(resources.files("lintunes") / "sounds" / "airhorn.mp3") as path:
|
||||
return decode(str(path))
|
||||
|
||||
|
||||
def _play(sample, script):
|
||||
horn = Horn(sample)
|
||||
out = []
|
||||
for action, seconds in script:
|
||||
if action == "press":
|
||||
horn.press()
|
||||
elif action == "release":
|
||||
horn.release()
|
||||
n = int(seconds * RATE)
|
||||
while n > 0:
|
||||
block = horn.render(min(512, n))
|
||||
out.append(block if block is not None else np.zeros((min(512, n), 2), np.float32))
|
||||
n -= 512
|
||||
while True:
|
||||
block = horn.render(512)
|
||||
if block is None:
|
||||
break
|
||||
out.append(block)
|
||||
return np.concatenate(out).mean(axis=1), horn
|
||||
|
||||
|
||||
def _envelope(mono, seconds=0.015):
|
||||
win = int(seconds * RATE)
|
||||
return np.sqrt(np.convolve(mono * mono, np.ones(win) / win, mode="same"))
|
||||
|
||||
|
||||
class TestHorn:
|
||||
def test_a_click_is_a_short_blast_that_trails_off(self, recording):
|
||||
x, _ = _play(recording, [("press", 0.01), ("release", 0.0)])
|
||||
assert 0.3 < len(x) / RATE < 0.45
|
||||
env = _envelope(x)
|
||||
assert env[-int(0.02 * RATE):].max() < 0.05 * env.max() # fades to nothing
|
||||
# …gradually: the last 120 ms fall, they don't drop off a cliff
|
||||
tail = env[-int(0.12 * RATE):]
|
||||
assert tail[0] > 4 * tail[-1]
|
||||
|
||||
def test_a_hold_sustains_without_clicks_or_a_beat(self, recording):
|
||||
x, _ = _play(recording, [("press", 3.0), ("release", 0.0)])
|
||||
source = recording.astype(np.float32).mean(axis=1) / 32768
|
||||
own_step = np.abs(np.diff(source[:int(0.6 * RATE)])).max()
|
||||
assert np.abs(np.diff(x)).max() <= own_step + 1e-3 # no seam clicks
|
||||
held = _envelope(x)[int(0.6 * RATE):int(2.6 * RATE)]
|
||||
assert held.min() / held.max() > 0.7 # steady, no pulse
|
||||
assert len(x) / RATE < 3.0 + 0.45 # stops on release
|
||||
|
||||
def test_taps_stay_separate_then_a_hold_carries(self, recording):
|
||||
x, horn = _play(recording, [("press", 0.06), ("release", 0.12)] * 6
|
||||
+ [("press", 2.5), ("release", 0.0)])
|
||||
held = _envelope(x)[int(1.6 * RATE):int(3.2 * RATE)]
|
||||
assert held.min() / held.max() > 0.7
|
||||
assert not horn._voices
|
||||
|
||||
def test_a_retrigger_cuts_the_old_blast_quickly(self, recording):
|
||||
horn = Horn(recording)
|
||||
horn.press()
|
||||
horn.render(4410)
|
||||
horn.press()
|
||||
states = [v["state"] for v in horn._voices]
|
||||
assert states == ["cut", "held"]
|
||||
horn.render(int(0.03 * RATE))
|
||||
assert [v["state"] for v in horn._voices] == ["held"]
|
||||
|
||||
|
||||
class TestLoops:
|
||||
def _deck(self, shelf):
|
||||
a, _ = shelf.views
|
||||
_loaded(shelf, a, shelf.tracks[0], _clicks(120, 0.0, 20), 120.0, 0.0)
|
||||
return a
|
||||
|
||||
def test_the_nearest_beat_may_be_behind(self, shelf):
|
||||
a = self._deck(shelf)
|
||||
a.deck.position = RATE * 2.1 # beats every 0.5 s: 2.0 is nearest
|
||||
shelf.set_loop(a, True)
|
||||
assert a.deck.loop[0] / RATE == pytest.approx(2.0, abs=1e-3)
|
||||
a.deck.position = RATE * 2.4 # 2.5 is nearest
|
||||
shelf.set_loop(a, True)
|
||||
assert a.deck.loop[0] / RATE == pytest.approx(2.5, abs=1e-3)
|
||||
|
||||
def test_a_short_loop_snaps_to_its_own_grid(self, shelf):
|
||||
a = self._deck(shelf)
|
||||
shelf.step_loop(a, -4) # 4 → 1/4 beat
|
||||
a.deck.position = RATE * 2.06 # quarter beats every 0.125 s
|
||||
shelf.set_loop(a, True)
|
||||
assert a.deck.loop[0] / RATE == pytest.approx(2.0, abs=1e-3)
|
||||
|
||||
def test_shrinking_a_running_loop_keeps_looping(self, shelf):
|
||||
a = self._deck(shelf)
|
||||
a.deck.position = RATE * 2.0
|
||||
shelf.set_loop(a, True) # 4 beats: 2.0 – 4.0
|
||||
a.deck.playing = True
|
||||
a.deck.seek(RATE * 3.6) # late in the loop
|
||||
shelf.step_loop(a, -2) # → 1 beat: 2.0 – 2.5
|
||||
start, end = a.deck.loop
|
||||
assert (start, end) == (RATE * 2, RATE * 2 + RATE // 2)
|
||||
assert start <= a.deck.position < end # folded back inside
|
||||
for _ in range(60):
|
||||
a.deck.render(1024)
|
||||
assert start <= a.deck.position < end + 1024
|
||||
shelf.step_loop(a, 2) # back to 4 beats: same start
|
||||
assert a.deck.loop == (RATE * 2, RATE * 4)
|
||||
Reference in New Issue
Block a user