v0.77.0: the laser visualizer is the Oscilloscope — screen sliders and rig diagram gone, a graticule dot size, and a sync delay per style

This commit is contained in:
2026-10-23 00:21:32 -07:00
parent 5413263587
commit 5f41460cb6
13 changed files with 357 additions and 478 deletions
+123
View File
@@ -0,0 +1,123 @@
"""Round 108: the laser style is called what it is — an Oscilloscope.
The screen's distance/pitch/yaw/roll only stretched or spun the same
tangle of loops, so they and the live rig diagram are gone (a still scope
drawing stands in); the graticule's dots get a size; and the sync delay is
one per style, since each style lags in its own way.
"""
import numpy as np
from PyQt6.QtCore import QRectF
from PyQt6.QtGui import QColor, QImage, QPainter
from lintunes.gui import visualizer_styles as vs
from lintunes.gui import visualizer_presets as presets
from lintunes.preferences import Preferences, DEFAULTS
from test_round78 import RATE, _PositionedPlayer, _marked, _config
from test_round84 import _LastFm
def _dialog(prefs):
from lintunes.gui.preferences_dialog import PreferencesDialog
return PreferencesDialog(prefs, _LastFm())
class TestNaming:
def test_the_style_reads_oscilloscope(self):
assert vs.STYLE_NAMES[vs.STYLE_LASER] == "Oscilloscope"
def test_the_screen_settings_are_gone(self):
for key in ("distance", "pitch", "yaw", "roll"):
assert f"visualizer_laser_{key}" not in vs.LIMITS
assert f"visualizer_laser_{key}" not in DEFAULTS
assert f"visualizer_laser_{key}" not in presets.STYLE_KEYS["laser"]
def test_the_dialog_has_a_still_drawing_and_no_screen_sliders(
self, qapp, tmp_path):
from lintunes.gui.scope_drawing import ScopeDrawing
dialog = _dialog(Preferences(tmp_path))
page = dialog._viz_pages.widget(list(vs.STYLES).index("laser"))
assert len(page.findChildren(ScopeDrawing)) == 1
assert not hasattr(dialog, "_angle_sliders")
assert not hasattr(dialog, "_distance_slider")
def test_the_drawing_paints(self, qapp):
from lintunes.gui.scope_drawing import ScopeDrawing
drawing = ScopeDrawing()
drawing.resize(170, 128)
assert not drawing.grab().isNull()
class TestGraticuleDots:
def _ink(self, grid_dot):
r = vs.LaserRenderer(_config(laser_grid=True, laser_grid_dot=grid_dot))
image = QImage(400, 300, QImage.Format.Format_ARGB32)
image.fill(QColor("black"))
painter = QPainter(image)
r.paint_grid(painter, QRectF(0, 0, 400, 300), QColor("white"))
painter.end()
bits = image.constBits()
bits.setsize(image.sizeInBytes())
return np.frombuffer(bits, np.uint8).reshape(300, 400, 4)[..., 0].sum()
def test_the_size_scales_the_dots(self, qapp):
assert self._ink(2.0) > 2 * self._ink(1.0) > 2 * self._ink(0.5) > 0
def test_the_slider_writes_a_share(self, qapp, tmp_path):
prefs = Preferences(tmp_path)
dialog = _dialog(prefs)
dialog._grid_dot_slider.setValue(150)
assert prefs.get("visualizer_laser_grid_dot") == 1.5
assert "visualizer_laser_grid_dot" in presets.STYLE_KEYS["laser"]
class TestSyncPerStyle:
def test_each_style_has_its_own(self):
config = {"visualizer_sync_delays": {"bars": 40, "laser": 120}}
assert vs.sync_delay_ms(config, "bars") == 40
assert vs.sync_delay_ms(config, "laser") == 120
def test_an_unset_style_starts_from_the_old_shared_value(self):
config = {"visualizer_sync_delay_ms": 90,
"visualizer_sync_delays": {"bars": 40}}
assert vs.sync_delay_ms(config, "radial") == 90
assert vs.sync_delay_ms({}, "radial") == 0
assert vs.sync_delay_ms({"visualizer_sync_delays": {"bars": 9999}},
"bars") == vs.SYNC_DELAY_LIMITS[1]
def test_every_page_has_one_right_under_the_preset(self, qapp, tmp_path):
from PyQt6.QtWidgets import QFormLayout
dialog = _dialog(Preferences(tmp_path))
assert set(dialog._sync_sliders) == set(vs.STYLES)
for i, style in enumerate(vs.STYLES):
form = dialog._viz_pages.widget(i).layout()
row = 1 if style in dialog._preset_combos else 0
item = form.itemAt(row, QFormLayout.ItemRole.FieldRole)
sliders = [item.layout().itemAt(j).widget()
for j in range(item.layout().count())]
assert dialog._sync_sliders[style] in sliders
def test_saving_keeps_them_apart(self, qapp, tmp_path, monkeypatch):
from lintunes.config import load_config
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path / "cfg"))
dialog = _dialog(Preferences(tmp_path))
dialog._sync_sliders["bars"].setValue(30)
dialog._sync_sliders["kaleidostrobe"].setValue(-20)
dialog._save_sync_delay()
saved = load_config()["visualizer_sync_delays"]
assert saved["bars"] == 30 and saved["kaleidostrobe"] == -20
assert saved["radial"] == 0
def test_the_widget_uses_the_shown_styles(self, qapp, tmp_path,
monkeypatch):
from lintunes.config import save_config
from lintunes.gui.visualizer import VisualizerWidget
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path / "cfg"))
save_config({"visualizer_sync_delays": {"bars": 0, "radial": 200}})
prefs = Preferences(tmp_path)
player = _PositionedPlayer()
vis = VisualizerWidget(player, prefs)
vis._feed(_marked(1000), RATE, start_ms=0)
player.position = 600
assert abs(vis._frame(0.016).samples[-1] - 600) < 2
prefs.set("visualizer_style", "radial")
assert abs(vis._frame(0.016).samples[-1] - 400) < 2
+19 -49
View File
@@ -104,10 +104,10 @@ class TestStylePreference:
def test_settings_are_clamped(self, qapp, tmp_path):
prefs = Preferences(tmp_path)
prefs.set("visualizer_radial_spokes", 100000) # hand-edited
prefs.set("visualizer_laser_pitch", "sideways")
prefs.set("visualizer_laser_width", "wide")
config = vs.settings(prefs)
assert config["visualizer_radial_spokes"] == 360
assert config["visualizer_laser_pitch"] == 0
assert config["visualizer_laser_width"] == 1.5
def test_every_style_paints_without_error(self, qapp):
for style in vs.STYLES:
@@ -301,39 +301,11 @@ class TestLaser:
s = np.linalg.svd(tilt, compute_uv=False)
assert s[1] / s[0] > 0.4
def test_farther_screen_bigger_figure(self):
audio = _sine(vs.MODES[1][0], 1.0)
near = _run(vs.LaserRenderer(_config(laser_distance=1.0)), audio)
far = _run(vs.LaserRenderer(_config(laser_distance=4.0)), audio)
ratio = np.abs(far.paths[0][0]).max() / np.abs(near.paths[0][0]).max()
assert 3.5 < ratio < 4.5
def test_pitch_stretches_vertically_and_roll_spins(self):
audio = _sine((vs.MODES[1][0] + vs.MODES[2][0]) / 2, 1.0)
def spread(**angles):
path = _run(vs.LaserRenderer(_config(**angles)), audio).paths[0][0]
return np.ptp(path[:, 0]), np.ptp(path[:, 1])
square_x, square_y = spread()
tipped_x, tipped_y = spread(laser_pitch=50)
assert tipped_y / square_y > 1.3 * tipped_x / square_x
turned_x, turned_y = spread(laser_yaw=50)
assert turned_x / square_x > 1.3 * turned_y / square_y
spun = _run(vs.LaserRenderer(_config(laser_roll=90)), audio).paths[0][0]
flat = _run(vs.LaserRenderer(_config()), audio).paths[0][0]
# A quarter turn: x becomes y (up to sign).
assert np.allclose(np.abs(spun[:, 0]), np.abs(flat[:, 1]), atol=1e-9)
@pytest.mark.parametrize("angles", [
{}, {"laser_pitch": 60, "laser_yaw": -60},
{"laser_pitch": -60, "laser_yaw": 60, "laser_roll": 45},
{"laser_distance": 1.0, "laser_pitch": 60}])
def test_every_setting_stays_on_screen_and_visible(self, angles):
def test_the_figure_stays_on_screen_and_visible(self):
rng = np.random.default_rng(0)
audio = _sine(90, 2, 0.9) * (1 + rng.standard_normal(2 * RATE) * 0.3)
audio = audio + _sine(150, 2, 0.5)
r = vs.LaserRenderer(_config(**angles))
r = vs.LaserRenderer(_config())
rect = QRectF(0, 0, 140, 62)
half_w, half_h = 70 - vs.INSET, 31 - vs.INSET
biggest = 0.0
@@ -632,17 +604,12 @@ class TestPreferencesPage:
dialog._head.setChecked(False)
dialog._width_box.setValue(dialog._width_box.minimum())
dialog._dot_slider.setValue(12)
dialog._distance_slider.setValue(15)
dialog._angle_sliders["visualizer_laser_pitch"].setValue(30)
dialog._grid_dot_slider.setValue(200)
assert prefs.get("visualizer_laser_glow") is False
assert prefs.get("visualizer_laser_head") is False
assert prefs.get("visualizer_laser_width") == 1 # one pixel
assert prefs.get("visualizer_laser_dot") == 6
assert prefs.get("visualizer_laser_distance") == 1.5
assert prefs.get("visualizer_laser_pitch") == 30
lo, hi = vs.LIMITS["visualizer_laser_roll"]
slider = dialog._angle_sliders["visualizer_laser_roll"]
assert (slider.minimum(), slider.maximum()) == (lo, hi)
assert prefs.get("visualizer_laser_grid_dot") == 2
def test_sync_delay_saves_to_config_not_prefs(self, qapp, tmp_path,
monkeypatch):
@@ -650,10 +617,10 @@ class TestPreferencesPage:
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path / "cfg"))
prefs = Preferences(tmp_path)
dialog = self._dialog(prefs)
dialog._sync_slider.setValue(150)
dialog._sync_sliders["laser"].setValue(150)
dialog._save_sync_delay()
assert load_config()["visualizer_sync_delay_ms"] == 150
assert prefs.get("visualizer_sync_delay_ms") is None
assert load_config()["visualizer_sync_delays"]["laser"] == 150
assert prefs.get("visualizer_sync_delays") is None
def test_a_swatch_repaints_its_slot(self, qapp, tmp_path):
from lintunes import theme
@@ -792,7 +759,7 @@ class TestPhosphor:
def test_a_setting_change_starts_it_afresh(self, qapp):
r = _run(vs.LaserRenderer(_config(laser_afterimage=0.5)), _sine(150, 0.2))
_paint(r, 300, 200)
r.configure(_config(laser_afterimage=0.5, laser_pitch=30))
r.configure(_config(laser_afterimage=0.5, laser_width=3))
assert r._phosphor == {}
@@ -902,7 +869,7 @@ class TestPresets:
def test_save_and_apply(self, qapp, tmp_path):
prefs = Preferences(tmp_path)
dialog = self._dialog(prefs)
dialog._angle_sliders["visualizer_laser_pitch"].setValue(40)
dialog._grid_dot_slider.setValue(40)
dialog._grid.setChecked(True)
dialog._speaker.setValues(150, 300)
dialog._width_box.setValue(3.5)
@@ -913,17 +880,17 @@ class TestPresets:
# Back to Default: every control (and setting) follows.
dialog._on_preset_chosen("laser", combo.findData("Default"))
assert prefs.get("visualizer_laser_pitch") == 0
assert prefs.get("visualizer_laser_grid_dot") == 1
assert prefs.get("visualizer_laser_grid") is False
assert prefs.get("visualizer_laser_width") == 1.5
assert dialog._speaker.values() == (0, 300)
assert combo.currentText() == "Default"
dialog._on_preset_chosen("laser", combo.findData("Big Tilt"))
assert prefs.get("visualizer_laser_pitch") == 40
assert prefs.get("visualizer_laser_grid_dot") == 0.4
assert prefs.get("visualizer_laser_grid") is True
assert prefs.get("visualizer_laser_width") == 3.5
assert dialog._angle_sliders["visualizer_laser_pitch"].value() == 40
assert dialog._grid_dot_slider.value() == 40
assert dialog._speaker.values() == (150, 300)
assert combo.currentText() == "Big Tilt"
@@ -966,13 +933,16 @@ class TestPresets:
assert set(presets.presets(prefs, "bars")["x"]) == {"visualizer_bars_fade",
"visualizer_bars_count"}
assert "visualizer_sync_delay_ms" not in presets.STYLE_KEYS["laser"]
assert "visualizer_sync_delays" not in presets.STYLE_KEYS["laser"]
def test_an_old_preset_takes_new_settings_defaults(self, qapp, tmp_path):
prefs = Preferences(tmp_path)
prefs.set(presets.PRESETS_KEY,
{"laser": {"Old": {"visualizer_laser_pitch": 20}}})
{"laser": {"Old": {"visualizer_laser_width": 4,
"visualizer_laser_pitch": 20}}})
values = presets.values_of(prefs, "laser", "Old")
assert values["visualizer_laser_pitch"] == 20
assert values["visualizer_laser_width"] == 4
assert "visualizer_laser_pitch" not in values # retired
assert values["visualizer_laser_glow"] is True # default
def test_every_style_key_has_a_control(self, qapp, tmp_path):
-49
View File
@@ -180,55 +180,6 @@ class TestHeadings:
assert not dialog._glow.font().bold()
class TestLaserDiagram:
def test_the_dialog_has_one_and_it_follows_the_settings(self, qapp, tmp_path):
prefs = Preferences(tmp_path)
dialog = _prefs_dialog(prefs)
dialog._angle_sliders["visualizer_laser_pitch"].setValue(-25)
dialog._distance_slider.setValue(16)
config = dialog._diagram._config
assert config["visualizer_laser_pitch"] == -25
assert config["visualizer_laser_distance"] == 1.6
def test_labelled_sliders_lost_their_numbers(self, qapp, tmp_path):
dialog = _prefs_dialog(Preferences(tmp_path))
page = dialog._viz_pages.widget(2)
dialog._viz_pages.setCurrentIndex(2)
dialog.show()
visible = {label.text() for label in page.findChildren(QLabel)
if label.isVisible()}
assert "3.5 m" not in visible and "0°" not in visible
assert "3 px" not in visible
dialog.close()
def test_paints_at_any_setting(self, qapp):
from lintunes.gui import visualizer_styles as vs
from lintunes.gui.laser_diagram import LaserDiagram
for overrides in ({}, {"visualizer_laser_pitch": 60,
"visualizer_laser_yaw": -60,
"visualizer_laser_roll": 180,
"visualizer_laser_distance": 1.0,
"visualizer_laser_dot": 16}):
config = vs.settings(None)
config.update(overrides)
diagram = LaserDiagram(config)
diagram.resize(420, 160)
assert not diagram.grab().isNull()
def test_the_screen_turns_with_the_angles(self, qapp):
from PyQt6.QtCore import QPointF
from lintunes.gui import visualizer_styles as vs
from lintunes.gui.laser_diagram import LaserDiagram
diagram = LaserDiagram(vs.settings(None))
square = diagram.screen_corners(QPointF(0, 0), 30)
pitched = diagram.screen_corners(QPointF(0, 0), 30, pitch=40,
yaw=0, roll=0)
# Tipping the top away moves the top edge along the beam.
assert pitched[2].x() != pytest.approx(square[2].x())
# A square screen's vertical edges are vertical.
assert square[1].x() == pytest.approx(square[2].x())
# --------------------------------------------------------------------------
# 5. Copying songs gives other apps a song list
# --------------------------------------------------------------------------
+4 -3
View File
@@ -54,14 +54,15 @@ class TestBetweenFrames:
class TestSyncSooner:
def test_negative_delay_is_kept(self):
assert vs.sync_delay_ms({"visualizer_sync_delay_ms": -30}) == -30
assert vs.sync_delay_ms({"visualizer_sync_delay_ms": -999}) == vs.SYNC_DELAY_LIMITS[0]
assert vs.sync_delay_ms({"visualizer_sync_delay_ms": -30}, "bars") == -30
assert vs.sync_delay_ms({"visualizer_sync_delay_ms": -999},
"bars") == vs.SYNC_DELAY_LIMITS[0]
def test_slider_reads_sooner_and_later(self, qapp, tmp_path, monkeypatch):
from lintunes.gui import preferences_dialog as pd
monkeypatch.setattr(pd, "load_config", lambda: {})
dialog = pd.PreferencesDialog(Preferences(tmp_path), _LastFm())
assert dialog._sync_slider.minimum() < 0
assert dialog._sync_sliders["kaleidostrobe"].minimum() < 0
assert pd._sync_text(-20) == "20 ms sooner"
assert pd._sync_text(40) == "40 ms later"