v0.55.0: Kaleidostrobe smooth again; visualizer tile hover controls

The cones move only on the plugin's own 25 fps frames again: driving them
from fresh audio every refresh made bass-heavy songs twitch (a jump on 84%
of refreshes against 41%). The continuous turn, texture crossfade and the
GPU big window stay.

The tile: a click opens it big (and it stays blank while big); hovering
shows a colour wheel (colour / gray / off) and up/down arrows (previous /
next visualizer). No more double-click or click-to-cycle. The big album
art closes on a click or Esc, like the big visualizer.
This commit is contained in:
2026-10-14 12:51:38 -07:00
parent 7ae55e757a
commit 00aa5e7f2e
14 changed files with 414 additions and 95 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
"""LinTunes — iTunes-style music library manager and player for Linux."""
__version__ = "0.54.0"
__version__ = "0.55.0"
+17 -1
View File
@@ -30,13 +30,16 @@ def _aspect(pixmap: QPixmap | None) -> float | None:
class ArtWindow(QWidget):
"""Non-modal window showing the current track's album art as large as
possible. Just an album art window — closing it has no side effects."""
possible. Just an album art window — closing it has no side effects.
A click anywhere on the art (or Esc) closes it, like the big
visualizer."""
def __init__(self, parent=None):
super().__init__(parent, Qt.WindowType.Window)
self._pixmap: QPixmap | None = None
self.setMinimumSize(120, 120)
self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose, False)
self.setToolTip("Click to close")
def show_artwork(self, pixmap: QPixmap | None, title: str, screen=None):
"""Open (or re-raise) the window, sized to the art on ``screen``."""
@@ -86,3 +89,16 @@ class ArtWindow(QWidget):
x = area.x() + (area.width() - scaled.width()) // 2
y = area.y() + (area.height() - scaled.height()) // 2
painter.drawPixmap(x, y, scaled)
def mouseReleaseEvent(self, event):
if (event.button() == Qt.MouseButton.LeftButton
and self.contentsRect().contains(event.position().toPoint())):
self.close()
return
super().mouseReleaseEvent(event)
def keyPressEvent(self, event):
if event.key() == Qt.Key.Key_Escape:
self.close()
return
super().keyPressEvent(event)
+1 -6
View File
@@ -75,12 +75,7 @@ def _fade_text(seconds: float) -> str:
# visualizer_styles' style keys, as the radios name them.
_VISUALIZER_STYLES = {
"bars": "Bars",
"radial": "Radial dots",
"laser": "Laser",
"kaleidostrobe": "Kaleidostrobe",
}
_VISUALIZER_STYLES = visualizer_styles.STYLE_NAMES
def _sync_text(ms: int) -> str:
+154 -27
View File
@@ -11,8 +11,8 @@ import time
import numpy as np
from PyQt6.QtWidgets import QWidget
from PyQt6.QtCore import Qt, QTimer, QRectF, pyqtSignal
from PyQt6.QtGui import QPainter, QColor
from PyQt6.QtCore import Qt, QTimer, QRectF, QPointF, pyqtSignal
from PyQt6.QtGui import QPainter, QColor, QConicalGradient, QPen, QPolygonF
from PyQt6.QtMultimedia import QAudioFormat
from lintunes import theme
@@ -20,7 +20,7 @@ from lintunes.config import load_config
from lintunes.gui.icons import transport_icon
from lintunes.gui import visualizer_styles as styles
from lintunes.gui.visualizer_styles import (
BANDS, HISTORY, STYLES, STYLE_BARS, Frame, make_renderer)
BANDS, HISTORY, STYLES, STYLE_BARS, STYLE_NAMES, Frame, make_renderer)
FRAME_MS = 16 # ~60 fps
@@ -30,13 +30,16 @@ HISTORY_S = 1.5 # decoded audio kept, so a frame can pick what's *heard*
PENDING_S = 0.25 # the laser catches up at most this much at once
GAP_MS = 50 # a buffer this far from the last one's end is a seek
# Visualizer click cycles through these brightness modes in order.
# The colour-wheel button cycles through these modes in order.
MODE_ON = "on"
MODE_DIM = "dim"
MODE_OFF = "off"
_MODE_CYCLE = (MODE_ON, MODE_DIM, MODE_OFF)
_MODE_NAMES = {MODE_ON: "colour", MODE_DIM: "gray", MODE_OFF: "off"}
_TOOLTIP = "Click to cycle: on / dim / off — double-click to enlarge"
_TOOLTIP = "Click to see it big"
BUTTON = 24 # the hover buttons: colour wheel left, ▲/▼ right
BUTTON_MARGIN = 4
_SAMPLE_DTYPES = {
QAudioFormat.SampleFormat.UInt8: (np.uint8, 127.5, 127.5),
@@ -52,11 +55,13 @@ def _style(prefs) -> str:
class VisualizerWidget(QWidget):
"""Animated visualizer; click to cycle brightness: on / dim / off, and
double-click to open it big (``VisualizerWindow``).
"""Animated visualizer. Hovering shows two controls over it — a colour
wheel (left) that cycles colour / gray / off, and ▲/▼ (right) that step
through the styles; a click anywhere else opens it big
(``VisualizerWindow``), and while it is big the panel stays blank.
On = highlight-colored; dim = light gray just darker than the panel;
off = blank (the big window, if open, keeps going in color).
Colour = highlight-colored; gray = light gray just darker than the panel;
off = blank (the big window, if open, keeps going).
While casting there is no local PCM to analyze, so the panel doubles as the
cast indicator: it shows the device glyph and a click stops casting.
@@ -70,7 +75,6 @@ class VisualizerWidget(QWidget):
self._prefs = prefs
saved = prefs.get("visualizer_mode") if prefs is not None else None
self._mode = saved if saved in _MODE_CYCLE else MODE_ON
self._mode_before_press = self._mode
self._renderer = make_renderer(_style(prefs), styles.settings(prefs))
# Decoded audio, newest last, and the stream time its end belongs
# to. Decoding runs ahead of the speakers — normally by a buffer or
@@ -93,6 +97,9 @@ class VisualizerWidget(QWidget):
self.setFixedWidth(140)
self.setMinimumHeight(36)
self.setToolTip(_TOOLTIP)
self.setMouseTracking(True) # which hover button is under the mouse
self._hovering = False
self._hot = None # "mode" / "prev" / "next" / None
self._timer = QTimer(self)
self._timer.setInterval(FRAME_MS)
@@ -270,29 +277,143 @@ class VisualizerWidget(QWidget):
if self._mode == MODE_OFF and not self._big_visible():
self._clear() # off = blank, not the last frame held in place
self._sync_timer()
self._update_tooltip()
self.update()
def mousePressEvent(self, event):
if self._no_pcm:
# While casting the panel is the cast indicator, not a spectrum:
# cycling its brightness would be meaningless, so a click stops
# casting instead.
self.cast_stop_requested.emit()
return
# Cycle on -> dim -> off -> on.
self._mode_before_press = self._mode
def cycle_mode(self):
"""The colour wheel: colour → gray → off → colour."""
idx = _MODE_CYCLE.index(self._mode)
self._set_mode(_MODE_CYCLE[(idx + 1) % len(_MODE_CYCLE)])
def mouseDoubleClickEvent(self, event):
"""Qt sends press, release, *double-click*: the first press already
cycled the brightness, so put it back before opening big. A brief
flicker, in exchange for a single click that never waits to see
whether a second one is coming."""
def step_style(self, step: int):
"""▲/▼: the previous or next style, wrapping around."""
current = _style(self._prefs) if self._prefs is not None else self._renderer.name
idx = STYLES.index(current) if current in STYLES else 0
style = STYLES[(idx + step) % len(STYLES)]
if self._prefs is not None:
self._prefs.set("visualizer_style", style) # swaps the renderer
else:
self._renderer = make_renderer(style, styles.settings(None))
self._update_tooltip()
self.update()
# ---- the hover controls ----
def _button_rects(self) -> dict:
w, h = self.width(), self.height()
m = BUTTON_MARGIN
arrow_h = min(BUTTON, (h - 3 * m) / 2)
right = w - m - BUTTON
return {
"mode": QRectF(m, (h - BUTTON) / 2, BUTTON, BUTTON),
"prev": QRectF(right, h / 2 - m / 2 - arrow_h, BUTTON, arrow_h),
"next": QRectF(right, h / 2 + m / 2, BUTTON, arrow_h),
}
def _hit(self, pos):
if self._no_pcm:
return # the first click already stopped casting
self._set_mode(self._mode_before_press)
self.open_big()
return None
for name, rect in self._button_rects().items():
if rect.contains(QPointF(pos)):
return name
return None
def _update_tooltip(self):
if self._no_pcm:
return
current = _style(self._prefs) if self._prefs is not None else self._renderer.name
idx = STYLES.index(current) if current in STYLES else 0
tips = {
"mode": f"Colour / gray / off — now {_MODE_NAMES[self._mode]}",
"prev": f"Previous visualizer: {STYLE_NAMES[STYLES[idx - 1]]}",
"next": f"Next visualizer: {STYLE_NAMES[STYLES[(idx + 1) % len(STYLES)]]}",
}
self.setToolTip(tips.get(self._hot, _TOOLTIP))
def enterEvent(self, event):
self._hovering = True
self.update()
super().enterEvent(event)
def leaveEvent(self, event):
self._hovering = False
self._hot = None
self.update()
super().leaveEvent(event)
def mouseMoveEvent(self, event):
hot = self._hit(event.position())
if hot != self._hot:
self._hot = hot
self._update_tooltip()
self.update()
super().mouseMoveEvent(event)
def mousePressEvent(self, event):
if self._no_pcm:
# While casting the panel is the cast indicator, not a picture:
# a click stops casting instead.
self.cast_stop_requested.emit()
return
event.accept() # acted on at release, like a button
def mouseReleaseEvent(self, event):
if self._no_pcm or event.button() != Qt.MouseButton.LeftButton:
return
if not self.rect().contains(event.position().toPoint()):
return # dragged off: no click
hit = self._hit(event.position())
if hit == "mode":
self.cycle_mode()
elif hit == "prev":
self.step_style(-1)
elif hit == "next":
self.step_style(1)
else:
self.open_big()
def _paint_controls(self, painter):
"""The hover buttons, over whatever is showing."""
pal = self.palette()
face = QColor(pal.window().color())
ink = QColor(pal.windowText().color())
painter.save()
painter.setRenderHint(QPainter.RenderHint.Antialiasing, True)
for name, rect in self._button_rects().items():
fill = QColor(face)
fill.setAlphaF(0.92 if name == self._hot else 0.72)
painter.setPen(QPen(QColor(ink.red(), ink.green(), ink.blue(),
110 if name == self._hot else 50), 1))
painter.setBrush(fill)
painter.drawRoundedRect(rect.adjusted(0.5, 0.5, -0.5, -0.5), 5, 5)
# colour wheel: a hue ring (colour), a gray one (gray), an outline (off)
wheel = self._button_rects()["mode"].adjusted(5, 5, -5, -5)
center = wheel.center()
if self._mode == MODE_OFF:
painter.setBrush(Qt.BrushStyle.NoBrush)
painter.setPen(QPen(ink, 1.5))
else:
grad = QConicalGradient(center, 90)
for k in range(7):
c = QColor.fromHsvF((k / 6) % 1.0, 0.85, 0.95)
if self._mode == MODE_DIM: # a gray sweep, light to dark
v = int(225 - 150 * abs(k - 3) / 3)
c = QColor(v, v, v)
grad.setColorAt(k / 6, c)
painter.setBrush(grad)
painter.setPen(QPen(QColor(0, 0, 0, 90), 1))
painter.drawEllipse(wheel)
# ▲ / ▼
painter.setPen(Qt.PenStyle.NoPen)
painter.setBrush(ink)
for name, up in (("prev", True), ("next", False)):
r = self._button_rects()[name]
cx, cy, s = r.center().x(), r.center().y(), min(r.width(), r.height()) * 0.22
tip = -s if up else s
painter.drawPolygon(QPolygonF([QPointF(cx - s * 1.2, cy - tip * 0.6),
QPointF(cx + s * 1.2, cy - tip * 0.6),
QPointF(cx, cy + tip * 0.9)]))
painter.restore()
def open_big(self):
from lintunes.gui.visualizer_window import VisualizerWindow
@@ -300,11 +421,13 @@ class VisualizerWidget(QWidget):
self._big = VisualizerWindow(self)
self._big.open(self.screen())
self._sync_timer()
self.update() # the panel goes blank while it is big
def big_window_closed(self):
if self._mode == MODE_OFF:
self._clear()
self._sync_timer()
self.update()
# ---- frame computation ----
@@ -348,6 +471,8 @@ class VisualizerWidget(QWidget):
regardless (in color), since opening it is asking to see it."""
if self._no_pcm or (self._mode == MODE_OFF and not big):
return
if not big and self._big_visible():
return # it's showing big; once is enough
self._tell_mode()
self._renderer.paint(painter, rect, self._bar_color(), self._grid_gray())
@@ -388,3 +513,5 @@ class VisualizerWidget(QWidget):
painter.end()
return
self.paint_renderer(painter, QRectF(self.rect()))
if self._hovering:
self._paint_controls(painter)
+8 -8
View File
@@ -10,10 +10,11 @@ way its OpenGL did.
- **The screen's clock.** Between those frames the picture is still drawn
at 60 fps (``advance`` → ``_compose``): the turn continues smoothly (the
rotation is a frame count, so a fraction of a frame is well defined), the
textures crossfade from the last frame to the newest, and the cones'
height and depth come from the plugin's own analysis run on the newest
audio (``engine.preview``) — so a beat pumps the cone on the next screen
refresh rather than at the next 40 ms tick.
textures crossfade from the last frame to the newest. The cones' height
and depth stay the plugin's own, changing only on its frames: driving
them from the newest audio at every refresh (Round 85) made the picture
twitch on bass-heavy songs — on 84% of refreshes against 41% — which is
the jitter the 25 fps cap had been hiding all along.
- **Input.** iTunes handed plugins 512 spectrum bins per channel as bytes;
how it scaled them was never documented, so ``itunes_spectrum`` is a
calibrated stand-in (``SPECTRUM_GAIN``).
@@ -162,20 +163,19 @@ class KaleidostrobeRenderer:
self._frame = self._engine.step(spectrum, self._ticks())
if self._frame is None:
return False
self._compose(spectrum)
self._compose()
return True
def _ticks(self, ahead=0.0):
return 1000 + int((self._clock + ahead) * ks.TICKS_PER_S)
def _compose(self, spectrum):
def _compose(self):
"""This screen refresh's picture, a fraction ``t`` of the way from
the plugin's last frame to its next one."""
e = self._engine
t = self._behind / STEP_S
mid, signal = e.preview(spectrum, self._ticks(self._behind))
drawn = (e.rotation - 1) % ks.ROTATION_STEPS # the last frame's turn
layers = e.layers(mid, signal, drawn + t)
layers = e.layers(e.mid, e.avg_signal, drawn + t)
cur = self._frame.textures
prev = self._prev_textures if self._prev_textures is not None else cur
if t > 0.0 and prev is not cur:
+6
View File
@@ -33,6 +33,12 @@ STYLE_RADIAL = "radial"
STYLE_LASER = "laser"
STYLE_KALEIDOSTROBE = "kaleidostrobe"
STYLES = (STYLE_BARS, STYLE_RADIAL, STYLE_LASER, STYLE_KALEIDOSTROBE)
STYLE_NAMES = {
STYLE_BARS: "Bars",
STYLE_RADIAL: "Radial dots",
STYLE_LASER: "Laser",
STYLE_KALEIDOSTROBE: "Kaleidostrobe",
}
BANDS = 20
STEPS = 20 # vertical granularity per bar
-15
View File
@@ -11,7 +11,6 @@ original handed OpenGL: two 128×128 RGBA textures and, per layer, the
triangles to draw (object-space vertices, texture coordinates, and the
modelview that places them). ``visualizer_kaleido`` paints that.
"""
import copy
import math
import struct
from dataclasses import dataclass, field
@@ -611,20 +610,6 @@ class Kaleidostrobe:
self.top_object, height, f32(depth * 5.0)))
return [bottom, top]
def preview(self, spectrum, ticks):
"""What the plugin's analysis would say if it rendered now: (mid,
avg_signal) from a throwaway copy, so nothing here is changed. The
renderer draws between the plugin's 25 fps frames with these, so a
beat moves the cone on the next screen refresh instead of up to
40 ms later; at the next real frame the numbers are the same."""
ghost = copy.copy(self)
ghost.band_peak = [list(row) for row in self.band_peak]
ghost.lp = {k: list(v) for k, v in self.lp.items()}
ghost.beat_periods = list(self.beat_periods)
ghost.frame_count += 1
ghost._process(spectrum, ticks)
return ghost.mid, ghost.avg_signal
def _object(self, k, h, z):
if k == 0:
return self._draw8(h, z)