fix: make audio editor playback local
This commit is contained in:
@@ -994,6 +994,102 @@ def test_editor_play_stop_safe(win, tmp_path):
|
||||
assert dlg._btn_play.text() == "▶ Play"
|
||||
|
||||
|
||||
def test_editor_stop_play_unchecks_button(win, tmp_path):
|
||||
import main as m
|
||||
src = tmp_path / "v0.wav"; src.write_bytes(b"")
|
||||
dlg = m.AudioEditorDialog(str(src), parent=win)
|
||||
dlg._btn_play.setChecked(True)
|
||||
dlg._stop_play()
|
||||
assert not dlg._btn_play.isChecked()
|
||||
|
||||
|
||||
def test_editor_play_button_auditions_selection(win, tmp_path, monkeypatch):
|
||||
import main as m
|
||||
src = tmp_path / "v0.wav"; src.write_bytes(b"")
|
||||
dlg = m.AudioEditorDialog(str(src), parent=win)
|
||||
dlg._clip_dur = 5.0
|
||||
dlg._wave.set_view(0.0, 5.0)
|
||||
dlg._wave.set_selection(1.25, 2.75)
|
||||
seen = {}
|
||||
monkeypatch.setattr(
|
||||
dlg, "_play_current",
|
||||
lambda start=None, end=None: seen.update(start=start, end=end))
|
||||
dlg._on_play(True)
|
||||
assert seen == {"start": 1.25, "end": 2.75}
|
||||
|
||||
|
||||
def test_editor_has_local_speed_controls(win, tmp_path):
|
||||
import main as m
|
||||
from PyQt6.QtWidgets import QPushButton
|
||||
src = tmp_path / "v0.wav"; src.write_bytes(b"")
|
||||
dlg = m.AudioEditorDialog(str(src), parent=win)
|
||||
assert isinstance(dlg._btn_speed2, QPushButton)
|
||||
assert isinstance(dlg._btn_speed4, QPushButton)
|
||||
dlg._btn_speed2.setChecked(True)
|
||||
dlg._set_playback_speed(2.0)
|
||||
assert dlg._play_speed == 2.0
|
||||
dlg._btn_speed4.setChecked(True)
|
||||
dlg._set_playback_speed(4.0)
|
||||
assert dlg._play_speed == 4.0
|
||||
assert not dlg._btn_speed2.isChecked()
|
||||
|
||||
|
||||
def test_editor_has_local_playback_shortcuts(win, tmp_path):
|
||||
import main as m
|
||||
from PyQt6.QtGui import QShortcut
|
||||
src = tmp_path / "v0.wav"; src.write_bytes(b"")
|
||||
dlg = m.AudioEditorDialog(str(src), parent=win)
|
||||
keys = {sc.key().toString() for sc in dlg.findChildren(QShortcut)}
|
||||
assert {"Space", "P", "K"} <= keys
|
||||
|
||||
|
||||
def test_editor_play_args_include_selection_and_speed(win, tmp_path):
|
||||
import main as m
|
||||
src = tmp_path / "v0.wav"; src.write_bytes(b"")
|
||||
dlg = m.AudioEditorDialog(str(src), parent=win)
|
||||
dlg._play_speed = 2.0
|
||||
args = dlg._play_args(start=1.0, end=3.5)
|
||||
assert args[:3] == ["-autoexit", "-nodisp", "-loglevel"]
|
||||
assert "-ss" in args and args[args.index("-ss") + 1] == "1.0"
|
||||
assert "-t" in args and args[args.index("-t") + 1] == "2.5"
|
||||
assert "-af" in args and args[args.index("-af") + 1] == "atempo=2.0"
|
||||
assert args[-1] == str(src)
|
||||
|
||||
|
||||
def test_editor_playhead_tracks_editor_range_and_speed(win, tmp_path):
|
||||
import main as m
|
||||
src = tmp_path / "v0.wav"; src.write_bytes(b"")
|
||||
dlg = m.AudioEditorDialog(str(src), parent=win)
|
||||
class FakeElapsed:
|
||||
def elapsed(self):
|
||||
return 1500
|
||||
dlg._play_start = 2.0
|
||||
dlg._play_end = 6.0
|
||||
dlg._play_speed = 2.0
|
||||
dlg._play_elapsed = FakeElapsed()
|
||||
dlg._tick_playhead()
|
||||
assert dlg._wave._playhead == 5.0
|
||||
|
||||
|
||||
def test_editor_reload_uses_dense_waveform_buckets(win, tmp_path, monkeypatch):
|
||||
import main as m
|
||||
import core.waveform as wf
|
||||
import numpy as np
|
||||
src = tmp_path / "v0.wav"; src.write_bytes(b"")
|
||||
calls = {}
|
||||
monkeypatch.setattr(m, "probe_duration", lambda _p: 4.0)
|
||||
monkeypatch.setattr(
|
||||
wf, "load_region_samples",
|
||||
lambda path, start, dur: np.ones(32000, dtype="float32"))
|
||||
def fake_peaks(samples, buckets=128):
|
||||
calls["buckets"] = buckets
|
||||
return [0.1] * buckets
|
||||
monkeypatch.setattr(wf, "peaks", fake_peaks)
|
||||
dlg = m.AudioEditorDialog(str(src), parent=win)
|
||||
assert calls["buckets"] >= 1000
|
||||
assert len(dlg._wave._peaks) == calls["buckets"]
|
||||
|
||||
|
||||
def test_editor_loop_join_plays_preview_range(win, tmp_path, monkeypatch):
|
||||
import main as m
|
||||
src = tmp_path / "v0.wav"
|
||||
|
||||
Reference in New Issue
Block a user