fix: separate editor playhead from selection

This commit is contained in:
2026-07-04 21:13:20 +02:00
parent ccad721c98
commit d36c61a6d5
2 changed files with 177 additions and 25 deletions
+74 -4
View File
@@ -646,6 +646,31 @@ def test_waveform_view_and_selection(win):
assert w.selection() is None
def test_waveform_click_sets_playhead_without_changing_selection(win):
from PyQt6.QtCore import QEvent, QPointF, Qt
from PyQt6.QtGui import QMouseEvent
w = win._wave
w.resize(400, 96)
w.set_view(0.0, 10.0)
w.set_selection(2.0, 4.0)
got = []
w.playhead_changed.connect(lambda t: got.append(t))
x = w._t_to_px(7.0)
press = QMouseEvent(
QEvent.Type.MouseButtonPress, QPointF(x, 20),
Qt.MouseButton.LeftButton, Qt.MouseButton.LeftButton,
Qt.KeyboardModifier.NoModifier)
release = QMouseEvent(
QEvent.Type.MouseButtonRelease, QPointF(x, 20),
Qt.MouseButton.LeftButton, Qt.MouseButton.NoButton,
Qt.KeyboardModifier.NoModifier)
w.mousePressEvent(press)
w.mouseReleaseEvent(release)
assert w.selection() == (2.0, 4.0)
assert got and abs(got[-1] - 7.0) < 0.05
assert abs((w.playhead() or 0.0) - 7.0) < 0.05
def test_waveform_drag_emits_selection(win):
w = win._wave
w.resize(400, 96)
@@ -1003,19 +1028,52 @@ def test_editor_stop_play_unchecks_button(win, tmp_path):
assert not dlg._btn_play.isChecked()
def test_editor_play_button_auditions_selection(win, tmp_path, monkeypatch):
def test_editor_reload_starts_with_playhead_and_no_selection(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"")
monkeypatch.setattr(m, "probe_duration", lambda _p: 4.0)
monkeypatch.setattr(
wf, "load_region_samples",
lambda path, start, dur: np.ones(32000, dtype="float32"))
dlg = m.AudioEditorDialog(str(src), parent=win)
assert dlg._wave.selection() is None
assert dlg._wave.playhead() == 0.0
def test_editor_play_button_starts_from_playhead_outside_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)
dlg._wave.set_playhead(4.0)
seen = {}
monkeypatch.setattr(
dlg, "_play_current",
lambda start=None, end=None: seen.update(start=start, end=end))
lambda start=None, end=None, loop=False:
seen.update(start=start, end=end, loop=loop))
dlg._on_play(True)
assert seen == {"start": 1.25, "end": 2.75}
assert seen == {"start": 4.0, "end": 5.0, "loop": False}
def test_editor_play_button_loops_selection_when_playhead_inside(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)
dlg._wave.set_playhead(2.0)
seen = {}
monkeypatch.setattr(
dlg, "_play_current",
lambda start=None, end=None, loop=False:
seen.update(start=start, end=end, loop=loop))
dlg._on_play(True)
assert seen == {"start": 1.25, "end": 2.75, "loop": True}
def test_editor_has_local_speed_controls(win, tmp_path):
@@ -1048,8 +1106,9 @@ def test_editor_play_args_include_selection_and_speed(win, tmp_path):
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)
args = dlg._play_args(start=1.0, end=3.5, loop=True)
assert args[:3] == ["-autoexit", "-nodisp", "-loglevel"]
assert "-loop" in args and args[args.index("-loop") + 1] == "0"
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"
@@ -1104,6 +1163,17 @@ def test_editor_loop_join_plays_preview_range(win, tmp_path, monkeypatch):
assert seen == {"start": 1.0, "end": 3.0}
def test_editor_heal_cut_marks_healed_seam(win, tmp_path):
import main as m
src = tmp_path / "v0.wav"
src.write_bytes(b"")
dlg = m.AudioEditorDialog(str(src), parent=win)
dlg._prepare_join_preview(2.0)
assert dlg._join_preview == (1.0, 3.0)
assert dlg._wave._markers == [2.0]
assert "2.00s" in dlg._status.text()
def test_editor_save_to_library_adds_current_version(win, tmp_path, monkeypatch):
import main as m
src = tmp_path / "v0.wav"