forked from trav/lintunes
v0.88.1: Lint Oontz is one ball — it sits when nothing plays and falls asleep later; the wheel's modes for it are colour, gray, black
The visualizer keeps its clock with nothing playing for a style that idles (fed silence), so the ball can sit, blink and fall asleep while paused.
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
"""LinTunes — iTunes-style music library manager and player for Linux."""
|
||||
|
||||
__version__ = "0.88.0"
|
||||
__version__ = "0.88.1"
|
||||
|
||||
@@ -875,9 +875,10 @@ class PreferencesDialog(QDialog):
|
||||
form = self._viz_form(lint)
|
||||
self._sync_delay_slider(form, "lint")
|
||||
about = QLabel(
|
||||
"Three balls of lint in headphones: they bob to the bass, dance "
|
||||
"when the music is fast and full, and fall asleep when it goes "
|
||||
"quiet. No settings yet.")
|
||||
"A ball of lint in headphones: it bobs to the bass, dances when "
|
||||
"the music is fast and full, sits down when it goes quiet and "
|
||||
"falls asleep after a while. The colour wheel adds black for it. "
|
||||
"No settings yet.")
|
||||
about.setWordWrap(True)
|
||||
about.setEnabled(False)
|
||||
form.addRow(about)
|
||||
|
||||
@@ -34,8 +34,11 @@ GAP_MS = 50 # a buffer this far from the last one's end is a seek
|
||||
MODE_ON = "on"
|
||||
MODE_DIM = "dim"
|
||||
MODE_OFF = "off"
|
||||
MODE_BLACK = "black" # only a style with ``black_mode`` (Lint Oontz) offers it
|
||||
_MODE_CYCLE = (MODE_ON, MODE_DIM, MODE_OFF)
|
||||
_MODE_NAMES = {MODE_ON: "colour", MODE_DIM: "gray", MODE_OFF: "off"}
|
||||
_BLACK_CYCLE = (MODE_ON, MODE_DIM, MODE_BLACK, MODE_OFF)
|
||||
_MODE_NAMES = {MODE_ON: "colour", MODE_DIM: "gray", MODE_BLACK: "black",
|
||||
MODE_OFF: "off"}
|
||||
|
||||
_TOOLTIP = "Click to see it big"
|
||||
BUTTON = 24 # the hover buttons: colour wheel left, ▲/▼ right
|
||||
@@ -74,7 +77,7 @@ class VisualizerWidget(QWidget):
|
||||
self._player = player
|
||||
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 = saved if saved in _BLACK_CYCLE else MODE_ON
|
||||
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
|
||||
@@ -115,6 +118,7 @@ class VisualizerWidget(QWidget):
|
||||
player.sink_changed.connect(self._on_sink_changed)
|
||||
if prefs is not None:
|
||||
prefs.changed.connect(self._on_prefs_changed)
|
||||
self._sync_timer() # an idling style moves before anything plays
|
||||
|
||||
# The bars' state, under the names the widget always had for it.
|
||||
@property
|
||||
@@ -135,6 +139,7 @@ class VisualizerWidget(QWidget):
|
||||
config = styles.settings(self._prefs)
|
||||
if style != self._renderer.name:
|
||||
self._renderer = make_renderer(style, config)
|
||||
self._sync_timer() # a style that idles keeps its clock
|
||||
else:
|
||||
self._renderer.configure(config)
|
||||
self._repaint()
|
||||
@@ -259,9 +264,15 @@ class VisualizerWidget(QWidget):
|
||||
def _big_visible(self):
|
||||
return self._big is not None and self._big.isVisible()
|
||||
|
||||
def _idles(self) -> bool:
|
||||
"""A style that still moves with nothing playing (Lint Oontz sits,
|
||||
then falls asleep) keeps the timer, fed silence."""
|
||||
return getattr(self._renderer, "idles", False)
|
||||
|
||||
def _sync_timer(self):
|
||||
"""Animate while playing, unless nothing would show it."""
|
||||
run = (not self._no_pcm and self._player.is_playing()
|
||||
"""Animate while playing (or idling), unless nothing would show it."""
|
||||
run = (not self._no_pcm
|
||||
and (self._player.is_playing() or self._idles())
|
||||
and (self._mode != MODE_OFF or self._big_visible()))
|
||||
if run:
|
||||
if not self._timer.isActive():
|
||||
@@ -282,6 +293,7 @@ class VisualizerWidget(QWidget):
|
||||
if track is None:
|
||||
self._timer.stop()
|
||||
self._clear()
|
||||
self._sync_timer()
|
||||
|
||||
def _clear(self):
|
||||
self._renderer.clear()
|
||||
@@ -302,10 +314,17 @@ class VisualizerWidget(QWidget):
|
||||
self._update_tooltip()
|
||||
self.update()
|
||||
|
||||
def _cycle(self):
|
||||
return (_BLACK_CYCLE if getattr(self._renderer, "black_mode", False)
|
||||
else _MODE_CYCLE)
|
||||
|
||||
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)])
|
||||
"""The colour wheel: colour → gray → off → colour (→ black before
|
||||
off, for a style that has it)."""
|
||||
cycle = self._cycle()
|
||||
mode = self._mode if self._mode in cycle else MODE_DIM
|
||||
idx = cycle.index(mode)
|
||||
self._set_mode(cycle[(idx + 1) % len(cycle)])
|
||||
|
||||
def step_style(self, step: int):
|
||||
"""▲/▼: the previous or next style, wrapping around."""
|
||||
@@ -346,7 +365,8 @@ class VisualizerWidget(QWidget):
|
||||
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]}",
|
||||
"mode": (" / ".join(_MODE_NAMES[m] for m in self._cycle()).capitalize()
|
||||
+ f" — 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)]]}",
|
||||
}
|
||||
@@ -421,6 +441,9 @@ class VisualizerWidget(QWidget):
|
||||
if self._mode == MODE_OFF:
|
||||
painter.setBrush(Qt.BrushStyle.NoBrush)
|
||||
painter.setPen(QPen(ink, 1.5))
|
||||
elif self._mode == MODE_BLACK and self._cycle() is _BLACK_CYCLE:
|
||||
painter.setBrush(QColor(0, 0, 0))
|
||||
painter.setPen(QPen(QColor(0, 0, 0, 90), 1))
|
||||
else:
|
||||
grad = QConicalGradient(center, 90)
|
||||
for k in range(7):
|
||||
@@ -461,7 +484,13 @@ class VisualizerWidget(QWidget):
|
||||
# ---- frame computation ----
|
||||
|
||||
def _advance_frame(self):
|
||||
if self._renderer.advance(self._frame(FRAME_MS / 1000)):
|
||||
dt = FRAME_MS / 1000
|
||||
if self._player.is_playing():
|
||||
frame = self._frame(dt)
|
||||
else: # idling: silence, never the last song's tail
|
||||
frame = Frame(np.zeros(HISTORY, np.float32), self._sample_rate,
|
||||
np.zeros(0, np.float32), dt)
|
||||
if self._renderer.advance(frame):
|
||||
self._repaint()
|
||||
|
||||
# ---- painting ----
|
||||
@@ -469,6 +498,8 @@ class VisualizerWidget(QWidget):
|
||||
def _bar_color(self):
|
||||
if self._mode == MODE_DIM:
|
||||
return self._gray()
|
||||
if self._mode == MODE_BLACK and self._cycle() is _BLACK_CYCLE:
|
||||
return QColor(0, 0, 0)
|
||||
return QColor(self.palette().highlight().color())
|
||||
|
||||
def _grid_gray(self):
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
"""Lint Oontz: three balls of lint in headphones, dancing (Round 122).
|
||||
"""Lint Oontz: a ball of lint in headphones, dancing (Round 122).
|
||||
|
||||
A very rough line drawing, animated like stop motion: the renderer steps at
|
||||
``FPS`` (8) on its own clock and each step is a new pose with every line
|
||||
re-wobbled, never an in-between — no tweening. Each step costs one repaint;
|
||||
the widget's 60 Hz timer only feeds it audio.
|
||||
the widget's 60 Hz timer only feeds it audio (silence while nothing plays:
|
||||
``idles``, so it keeps its clock and can fall asleep).
|
||||
|
||||
What the music does to them:
|
||||
What the music does to it:
|
||||
|
||||
- **bass** → the head bob. A bass onset (energy well over its own recent
|
||||
average) dips the ball and bends the knees; between beats it springs back.
|
||||
@@ -13,14 +14,12 @@ What the music does to them:
|
||||
counted from the onsets themselves) *and* the spectrum is full
|
||||
(``BUSY_FULLNESS``), every beat throws a new arm pose and the feet step.
|
||||
Otherwise the arms hang and only the head bobs.
|
||||
- **quiet** for ``SLEEP_AFTER_S`` → they lie down and sleep (closed eyes,
|
||||
rising z's) until the music comes back. Stopped/paused (``clear``) is
|
||||
asleep too.
|
||||
- **quiet** (or nothing playing) → it sits down after ``SIT_AFTER_S``, and
|
||||
after ``SLEEP_AFTER_S`` lies down to sleep (closed eyes, rising z's),
|
||||
until the music comes back.
|
||||
|
||||
Three of them, on the panel's gray: one in gray lines, one in the highlight
|
||||
colour (the colour the wheel picks — in gray mode that is the gray too) and
|
||||
one in black. Each has its own fuzz and is a beat out of step with the
|
||||
others' arm poses, so they don't move as one.
|
||||
The lines are the colour the wheel picks — highlight, gray or black
|
||||
(``black_mode``: this style adds black to the wheel) — on the panel's gray.
|
||||
"""
|
||||
import math
|
||||
|
||||
@@ -46,7 +45,8 @@ BUSY_FULLNESS = 0.28 # mean band level (0..1) of a "full" spectrum:
|
||||
# mix of a few tones 0.12-0.14
|
||||
CALM_AFTER_S = 2.0 # busy has to be gone this long to stop dancing
|
||||
QUIET_DB = -48.0 # RMS under this is quiet
|
||||
SLEEP_AFTER_S = 4.0
|
||||
SIT_AFTER_S = 1.5
|
||||
SLEEP_AFTER_S = 20.0
|
||||
WAKE_AFTER_S = 0.3
|
||||
FULLNESS_BANDS = 16
|
||||
|
||||
@@ -54,6 +54,10 @@ FULLNESS_BANDS = 16
|
||||
# outward positive, plus each elbow's extra bend.
|
||||
HANG = ((18, 8), (18, 8))
|
||||
LYING = ((4, 0), (4, 0)) # asleep: arms along the body
|
||||
SITTING = ((48, -20), (48, -20)) # hands down on the floor beside it
|
||||
BLINK_EVERY = 29 # steps; one closed-eye drawing each time
|
||||
|
||||
STAND, SIT, SLEEP = "stand", "sit", "sleep"
|
||||
DANCE = (
|
||||
((150, -30), (30, 20)), # left up
|
||||
((140, -20), (140, -20)), # both up
|
||||
@@ -76,14 +80,16 @@ class _Figure:
|
||||
|
||||
class LintRenderer:
|
||||
name = STYLE
|
||||
dimmed = False # set by the widget: gray mode
|
||||
black_mode = True # the wheel offers black for this style
|
||||
idles = True # keep the clock running with nothing playing
|
||||
dimmed = False # set by the widget (unused: colour is given)
|
||||
panel = QColor(200, 200, 200) # set by the widget: the background
|
||||
|
||||
def __init__(self, config=None):
|
||||
self._figures = [_Figure(i) for i in range(3)]
|
||||
self._fig = _Figure(0)
|
||||
self._behind = 0.0
|
||||
self._clock = 0.0
|
||||
self.step = 0
|
||||
self.step = 1 # 0 would be a blink
|
||||
self._bass_avg = 0.0
|
||||
self._last_beat = -1.0
|
||||
self._beats = []
|
||||
@@ -92,9 +98,9 @@ class LintRenderer:
|
||||
self.fullness = 0.0
|
||||
self.busy = False
|
||||
self._calm_for = 0.0
|
||||
self.asleep = True
|
||||
self._quiet_for = SLEEP_AFTER_S
|
||||
self._quiet_for = SIT_AFTER_S # nothing has played yet: sitting
|
||||
self._loud_for = 0.0
|
||||
self.posture = SIT
|
||||
self.feet = 0
|
||||
|
||||
# ---- the renderer contract ----
|
||||
@@ -102,11 +108,16 @@ class LintRenderer:
|
||||
def configure(self, config):
|
||||
pass # no settings yet
|
||||
|
||||
@property
|
||||
def asleep(self) -> bool:
|
||||
return self.posture == SLEEP
|
||||
|
||||
def clear(self):
|
||||
"""Stopped or paused: they lie down."""
|
||||
self.asleep = True
|
||||
self._quiet_for = SLEEP_AFTER_S
|
||||
"""Stopped or paused: it sits down (and sleeps, given time)."""
|
||||
self._quiet_for = max(self._quiet_for, SIT_AFTER_S)
|
||||
self._loud_for = 0.0
|
||||
if self.posture == STAND:
|
||||
self.posture = SIT
|
||||
self.busy = False
|
||||
self.bob = 0.0
|
||||
self._beats.clear()
|
||||
@@ -143,10 +154,12 @@ class LintRenderer:
|
||||
else:
|
||||
self._loud_for += dt
|
||||
self._quiet_for = 0.0
|
||||
if self.asleep and self._loud_for >= WAKE_AFTER_S:
|
||||
self.asleep = False
|
||||
elif not self.asleep and self._quiet_for >= SLEEP_AFTER_S:
|
||||
self.asleep = True
|
||||
if self.posture != STAND and self._loud_for >= WAKE_AFTER_S:
|
||||
self.posture = STAND
|
||||
elif self._quiet_for >= SLEEP_AFTER_S:
|
||||
self.posture = SLEEP
|
||||
elif self.posture == STAND and self._quiet_for >= SIT_AFTER_S:
|
||||
self.posture = SIT
|
||||
|
||||
from lintunes.gui.visualizer_styles import (
|
||||
band_edges, band_levels, spectrum_of)
|
||||
@@ -180,47 +193,35 @@ class LintRenderer:
|
||||
|
||||
def _pose(self):
|
||||
self.step += 1
|
||||
if self.asleep:
|
||||
if self.posture != STAND:
|
||||
self.bob = 0.0
|
||||
self._beat_pending = False
|
||||
return
|
||||
if self._beat_pending:
|
||||
self._beat_pending = False
|
||||
self.bob = 1.0
|
||||
if self.busy:
|
||||
self.feet ^= 1
|
||||
for f in self._figures:
|
||||
f.pose = (f.pose + 1) % len(DANCE)
|
||||
self._fig.pose = (self._fig.pose + 1) % len(DANCE)
|
||||
else:
|
||||
self.bob = 0.35 if self.bob >= 1.0 else 0.0
|
||||
|
||||
# ---- drawing ----
|
||||
|
||||
def colors(self, color: QColor):
|
||||
panel = QColor(self.panel)
|
||||
gray = panel.darker(165)
|
||||
black = QColor(0, 0, 0)
|
||||
if self.dimmed:
|
||||
return [panel.darker(135), QColor(color), panel.darker(230)]
|
||||
return [gray, QColor(color), black]
|
||||
|
||||
def paint(self, painter, rect, color: QColor, gray: QColor = None):
|
||||
area = QRectF(rect).adjusted(INSET, INSET, -INSET, -INSET)
|
||||
if area.width() < 6 or area.height() < 6:
|
||||
return
|
||||
cell_w = area.width() / 3
|
||||
painter.save()
|
||||
painter.setRenderHint(painter.RenderHint.Antialiasing)
|
||||
for fig, ink in zip(self._figures, self.colors(color)):
|
||||
cell = QRectF(area.x() + fig.index * cell_w, area.y(),
|
||||
cell_w, area.height())
|
||||
self._paint_figure(painter, cell, fig, ink)
|
||||
self._paint_figure(painter, area, self._fig, QColor(color))
|
||||
painter.restore()
|
||||
|
||||
def _paint_figure(self, painter, cell, fig, ink):
|
||||
# The ball's radius: room for headphones either side and legs below,
|
||||
# or (asleep) lying full length.
|
||||
r = min(cell.width() / 3.9, cell.height() / 4.2)
|
||||
if self.asleep:
|
||||
if self.posture == SLEEP:
|
||||
r = min(r, cell.width() / 4.6, cell.height() / 2.8)
|
||||
rng = np.random.default_rng(self.step * 31 + fig.index)
|
||||
wob = max(0.4, r * 0.06)
|
||||
@@ -237,24 +238,31 @@ class LintRenderer:
|
||||
ground = cell.bottom() - pen.widthF()
|
||||
cx = cell.center().x()
|
||||
painter.save()
|
||||
if self.asleep:
|
||||
if self.posture == SLEEP:
|
||||
# Lying on its back, feet to the right: the standing drawing
|
||||
# turned a quarter (rotate(-90) sends "down" to "right").
|
||||
head = cx - r * 0.75
|
||||
painter.translate(head, ground - r * 1.4)
|
||||
painter.rotate(-90)
|
||||
self._body(painter, fig, r, 0.0, j, asleep=True)
|
||||
self._body(painter, fig, r, 0.0, j, SLEEP)
|
||||
painter.restore()
|
||||
self._zzz(painter, head + r * 0.5, ground - r * 3.0, r, fig, j)
|
||||
return
|
||||
if self.posture == SIT:
|
||||
painter.translate(cx, ground - r * 1.1) # the ball on the floor
|
||||
self._body(painter, fig, r, 0.0, j, SIT)
|
||||
painter.restore()
|
||||
return
|
||||
legs = r * 1.25
|
||||
dip = self.bob * r * 0.22
|
||||
painter.translate(cx, ground - legs - r + dip)
|
||||
self._body(painter, fig, r, dip, j, asleep=False)
|
||||
self._body(painter, fig, r, dip, j, STAND)
|
||||
painter.restore()
|
||||
|
||||
def _body(self, painter, fig, r, dip, j, asleep):
|
||||
def _body(self, painter, fig, r, dip, j, posture):
|
||||
"""The figure drawn around its ball's centre (0, 0), feet at +y."""
|
||||
asleep = posture == SLEEP
|
||||
blink = posture == SIT and self.step % BLINK_EVERY == 0
|
||||
# The fuzzy ball: a wobbly ring plus a few loose hairs.
|
||||
n = len(fig.radii)
|
||||
ring = QPainterPath()
|
||||
@@ -265,19 +273,26 @@ class LintRenderer:
|
||||
ring.moveTo(p) if i == 0 else ring.lineTo(p)
|
||||
painter.drawPath(ring)
|
||||
for a, length in zip(fig.hairs, fig.hair_len):
|
||||
if abs(math.cos(a)) > 0.8:
|
||||
continue # where the headphone cups sit
|
||||
if abs(math.cos(a)) > 0.8 or math.sin(a) > 0.5:
|
||||
continue # where the headphone cups and the legs are
|
||||
painter.drawLine(j(math.cos(a) * r, math.sin(a) * r),
|
||||
j(math.cos(a) * r * (1 + length),
|
||||
math.sin(a) * r * (1 + length)))
|
||||
|
||||
# Face.
|
||||
eye_y, eye_x = -r * 0.18, r * 0.32
|
||||
if asleep:
|
||||
if asleep or blink:
|
||||
for s in (-1, 1):
|
||||
painter.drawLine(j(s * eye_x - r * 0.13, eye_y),
|
||||
j(s * eye_x + r * 0.13, eye_y))
|
||||
if asleep:
|
||||
painter.drawLine(j(-r * 0.12, r * 0.32), j(r * 0.12, r * 0.32))
|
||||
elif posture == SIT:
|
||||
if not blink:
|
||||
dot = max(0.8, r * 0.07)
|
||||
for s in (-1, 1):
|
||||
painter.drawEllipse(j(s * eye_x, eye_y), dot, dot)
|
||||
painter.drawLine(j(-r * 0.18, r * 0.32), j(r * 0.18, r * 0.3))
|
||||
else:
|
||||
dot = max(0.8, r * 0.07)
|
||||
for s in (-1, 1):
|
||||
@@ -300,13 +315,15 @@ class LintRenderer:
|
||||
# Arms from the shoulders, two sticks each.
|
||||
if asleep:
|
||||
pose = LYING
|
||||
elif posture == SIT:
|
||||
pose = SITTING
|
||||
elif self.busy:
|
||||
pose = DANCE[(fig.pose + fig.index) % len(DANCE)]
|
||||
pose = DANCE[fig.pose]
|
||||
else:
|
||||
pose = HANG
|
||||
upper, lower = r * 0.75, r * 0.6
|
||||
for s, (shoulder, bend) in zip((-1, 1), pose):
|
||||
if not self.busy and not asleep:
|
||||
if posture == STAND and not self.busy:
|
||||
shoulder += 6 * self.bob # a hanging arm swings with the bob
|
||||
start = (s * r * 0.92, r * 0.3)
|
||||
a = math.radians(shoulder)
|
||||
@@ -317,6 +334,16 @@ class LintRenderer:
|
||||
elbow[1] + math.cos(b) * lower)
|
||||
painter.drawPolyline([j(*start), j(*elbow), j(*hand)])
|
||||
|
||||
if posture == SIT:
|
||||
# Splayed out along the floor, feet turned up.
|
||||
for s in (-1, 1):
|
||||
hip = (s * r * 0.45, r * 0.85)
|
||||
knee = (s * r * 1.0, r * 1.08)
|
||||
foot = (s * r * 1.6, r * 1.08)
|
||||
painter.drawPolyline([j(*hip), j(*knee), j(*foot),
|
||||
j(foot[0] + s * r * 0.05, r * 0.78)])
|
||||
return
|
||||
|
||||
# Legs: straight, or bent at the knee by the bob; the feet step
|
||||
# apart when dancing.
|
||||
legs = r * 1.25
|
||||
@@ -334,7 +361,7 @@ class LintRenderer:
|
||||
|
||||
def _zzz(self, painter, x, y, r, fig, j):
|
||||
"""Little z's rising, a new one every few frames."""
|
||||
phase = (self.step + fig.index * 3) % 12
|
||||
phase = self.step % 12
|
||||
for k in range(3):
|
||||
age = (phase / 4 + k) % 3 # 0..3, how far it has risen
|
||||
size = r * (0.18 + 0.08 * age)
|
||||
|
||||
Reference in New Issue
Block a user