fix: sync editor playhead with selection changes
This commit is contained in:
@@ -4365,6 +4365,7 @@ class AudioEditorDialog(QDialog):
|
||||
self._healed_seams: dict[str, list[float]] = {}
|
||||
|
||||
self._wave = AudioWaveform()
|
||||
self._wave.selection_changed.connect(self._on_wave_selection_changed)
|
||||
self._wave.playhead_changed.connect(self._on_wave_playhead_changed)
|
||||
self._btn_heal_cut = QPushButton("Heal Cut")
|
||||
self._btn_delete = QPushButton("Delete")
|
||||
@@ -4616,6 +4617,13 @@ class AudioEditorDialog(QDialog):
|
||||
return
|
||||
self._play_current(*self._join_preview)
|
||||
|
||||
def _on_wave_selection_changed(self, s: float, e: float) -> None:
|
||||
was_playing = self._play_proc is not None
|
||||
prior_playhead = self._playhead_secs()
|
||||
self._wave.set_playhead(s)
|
||||
if was_playing and (self._play_loop or s <= prior_playhead <= e):
|
||||
self._play_current(s, e, loop=True)
|
||||
|
||||
def _on_wave_playhead_changed(self, t: float) -> None:
|
||||
if self._play_proc is not None:
|
||||
self._play_from_playhead()
|
||||
|
||||
@@ -1158,6 +1158,37 @@ def test_editor_playhead_change_keeps_looping_when_inside_selection(win, tmp_pat
|
||||
assert stopped["n"] == 0
|
||||
|
||||
|
||||
def test_editor_selection_change_moves_playhead_to_area_start(win, tmp_path):
|
||||
import main as m
|
||||
src = tmp_path / "v0.wav"; src.write_bytes(b"")
|
||||
dlg = m.AudioEditorDialog(str(src), parent=win)
|
||||
dlg._clip_dur = 6.0
|
||||
dlg._wave.set_view(0.0, 6.0)
|
||||
dlg._wave.set_playhead(5.0)
|
||||
dlg._on_wave_selection_changed(1.5, 3.5)
|
||||
assert dlg._wave.playhead() == 1.5
|
||||
|
||||
|
||||
def test_editor_selection_change_updates_active_loop_bounds(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 = 6.0
|
||||
dlg._wave.set_view(0.0, 6.0)
|
||||
dlg._wave.set_selection(1.0, 3.0)
|
||||
dlg._wave.set_playhead(2.0)
|
||||
dlg._play_proc = object()
|
||||
dlg._play_loop = True
|
||||
seen = {}
|
||||
monkeypatch.setattr(
|
||||
dlg, "_play_current",
|
||||
lambda start=None, end=None, loop=False:
|
||||
seen.update(start=start, end=end, loop=loop))
|
||||
dlg._on_wave_selection_changed(1.0, 4.0)
|
||||
assert seen == {"start": 1.0, "end": 4.0, "loop": True}
|
||||
assert dlg._wave.playhead() == 1.0
|
||||
|
||||
|
||||
def test_editor_has_local_speed_controls(win, tmp_path):
|
||||
import main as m
|
||||
from PyQt6.QtWidgets import QPushButton
|
||||
|
||||
Reference in New Issue
Block a user