"""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