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:
@@ -413,17 +413,20 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal
|
||||
and `test_round84` holds the port to it byte for byte.
|
||||
|
||||
- **`gui/visualizer_lint.py`** — Lint Oontz, the fifth style (Round 122,
|
||||
`lint`): three line-drawn lint balls in big headphones (gray, the wheel's
|
||||
colour, black) on the panel's gray. **Stop motion**: the renderer steps
|
||||
at 8 fps on its own clock and `advance` is True only on a step; every
|
||||
step re-rolls each line's wobble (seeded by step, so one step always
|
||||
draws the same) and nothing is ever tweened. A bass onset (energy
|
||||
`ONSET_RATIO` over its own average) dips the head and bends the knees;
|
||||
the arms dance only when the onset tempo is ≥ `BUSY_BPM` *and* the
|
||||
spectrum is full (`BUSY_FULLNESS`, calibrated on pink noise vs. sparse
|
||||
tones), otherwise they hang. `SLEEP_AFTER_S` of quiet (or `clear()`,
|
||||
i.e. stopped) lays them down with z's. No settings yet (no
|
||||
`STYLE_KEYS` entry), only its sync delay.
|
||||
`lint`): one line-drawn lint ball in big headphones on the panel's gray.
|
||||
**Stop motion**: the renderer steps at 8 fps on its own clock and
|
||||
`advance` is True only on a step; every step re-rolls each line's wobble
|
||||
(seeded by step, so one step always draws the same) and nothing is ever
|
||||
tweened. A bass onset (energy `ONSET_RATIO` over its own average) dips
|
||||
the head and bends the knees; the arms dance only when the onset tempo
|
||||
is ≥ `BUSY_BPM` *and* the spectrum is full (`BUSY_FULLNESS`, calibrated
|
||||
on pink noise vs. sparse tones), otherwise they hang. Quiet (or paused,
|
||||
`clear()`) → it **sits** after `SIT_AFTER_S` and **sleeps** after
|
||||
`SLEEP_AFTER_S`. Two renderer flags the widget reads: `idles` keeps the
|
||||
60 Hz timer running with nothing playing (fed silence, never the old
|
||||
song's tail) so it can fall asleep, and `black_mode` adds `MODE_BLACK`
|
||||
to the colour wheel (colour → gray → black → off) — for any other style
|
||||
a saved black reads as colour. No settings yet (no `STYLE_KEYS` entry).
|
||||
|
||||
- **`lintunes/dj/`** + **`gui/dj_shelf.py`** — DJ mode (Round 93; View ›
|
||||
DJ Mode or the turntable button under BPM). The window parts **under the
|
||||
|
||||
@@ -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)
|
||||
|
||||
+93
-43
@@ -1,10 +1,17 @@
|
||||
"""Round 122: Lint Oontz, the stop-motion lint-ball visualizer."""
|
||||
"""Round 122: Lint Oontz, the stop-motion lint-ball visualizer: one ball in
|
||||
headphones that dances, sits when nothing plays and falls asleep; its
|
||||
colour modes are highlight, gray and black."""
|
||||
import numpy as np
|
||||
from PyQt6.QtCore import QRectF
|
||||
from PyQt6.QtGui import QColor, QImage, QPainter
|
||||
|
||||
from lintunes.gui import visualizer_lint as vl
|
||||
from lintunes.gui import visualizer_styles as vs
|
||||
from lintunes.gui.visualizer_lint import FPS, LintRenderer
|
||||
from lintunes.gui.visualizer import (
|
||||
MODE_BLACK, MODE_DIM, MODE_OFF, MODE_ON)
|
||||
from lintunes.gui.visualizer_lint import FPS, LintRenderer, SIT, SLEEP, STAND
|
||||
|
||||
from test_round86 import _tile
|
||||
|
||||
RATE = 44100
|
||||
|
||||
@@ -31,6 +38,19 @@ def _play(r, audio):
|
||||
return steps
|
||||
|
||||
|
||||
def _silence(seconds):
|
||||
return np.zeros(int(RATE * seconds), np.float32)
|
||||
|
||||
|
||||
def _draw(r, w, h, color=QColor(40, 110, 220)):
|
||||
img = QImage(w, h, QImage.Format.Format_ARGB32)
|
||||
img.fill(QColor(205, 205, 205))
|
||||
p = QPainter(img)
|
||||
r.paint(p, QRectF(0, 0, w, h), color)
|
||||
p.end()
|
||||
return img
|
||||
|
||||
|
||||
def test_registered():
|
||||
assert vs.STYLE_LINT in vs.STYLES
|
||||
assert vs.STYLE_NAMES[vs.STYLE_LINT] == "Lint Oontz"
|
||||
@@ -46,69 +66,99 @@ def test_stop_motion_frame_rate():
|
||||
def test_fast_full_music_dances():
|
||||
r = LintRenderer()
|
||||
_play(r, _song(128, 6, True))
|
||||
assert not r.asleep and r.busy
|
||||
assert r.posture == STAND and r.busy
|
||||
assert 120 <= r.tempo <= 136
|
||||
|
||||
|
||||
def test_slow_sparse_music_only_bobs():
|
||||
r = LintRenderer()
|
||||
_play(r, _song(80, 6, False))
|
||||
assert not r.asleep and not r.busy
|
||||
assert r.posture == STAND and not r.busy
|
||||
assert 74 <= r.tempo <= 86
|
||||
|
||||
|
||||
def test_quiet_puts_them_to_sleep_and_music_wakes_them():
|
||||
def test_it_starts_sitting_then_falls_asleep():
|
||||
r = LintRenderer()
|
||||
assert r.posture == SIT
|
||||
_play(r, _silence(vl.SLEEP_AFTER_S - vl.SIT_AFTER_S - 1))
|
||||
assert r.posture == SIT
|
||||
_play(r, _silence(2))
|
||||
assert r.posture == SLEEP
|
||||
|
||||
|
||||
def test_quiet_sits_then_sleeps_and_music_wakes_it():
|
||||
r = LintRenderer()
|
||||
_play(r, _song(128, 3, True))
|
||||
assert not r.asleep
|
||||
_play(r, np.zeros(RATE * 2, np.float32))
|
||||
assert not r.asleep # a short break isn't sleep
|
||||
_play(r, np.zeros(RATE * 3, np.float32))
|
||||
assert r.asleep
|
||||
assert r.posture == STAND
|
||||
_play(r, _silence(vl.SIT_AFTER_S + 0.5))
|
||||
assert r.posture == SIT
|
||||
_play(r, _silence(vl.SLEEP_AFTER_S))
|
||||
assert r.posture == SLEEP
|
||||
_play(r, _song(128, 1, True))
|
||||
assert not r.asleep
|
||||
assert r.posture == STAND
|
||||
|
||||
|
||||
def test_cleared_is_asleep():
|
||||
def test_pausing_sits_it_down():
|
||||
r = LintRenderer()
|
||||
_play(r, _song(128, 2, True))
|
||||
r.clear()
|
||||
assert r.asleep
|
||||
assert r.posture == SIT
|
||||
|
||||
|
||||
def test_three_balls_gray_highlight_black(qapp):
|
||||
def test_one_ball_in_the_given_colour(qapp):
|
||||
r = LintRenderer()
|
||||
r.panel = QColor(205, 205, 205)
|
||||
gray, highlight, black = r.colors(QColor(40, 110, 220))
|
||||
assert highlight == QColor(40, 110, 220)
|
||||
assert black == QColor(0, 0, 0)
|
||||
assert gray.red() == gray.green() == gray.blue() < 205
|
||||
for asleep in (False, True):
|
||||
r.asleep = asleep
|
||||
for w, h in ((110, 44), (900, 450)):
|
||||
img = QImage(w, h, QImage.Format.Format_ARGB32)
|
||||
img.fill(r.panel)
|
||||
p = QPainter(img)
|
||||
r.paint(p, QRectF(0, 0, w, h), highlight)
|
||||
p.end()
|
||||
blue = sum(img.pixelColor(x, y).blue() - img.pixelColor(x, y).red() > 80
|
||||
for x in range(w) for y in range(0, h, 2))
|
||||
assert blue > 0
|
||||
for posture in (STAND, SIT, SLEEP):
|
||||
r.posture = posture
|
||||
for w, h in ((134, 38), (900, 450)):
|
||||
img = _draw(r, w, h)
|
||||
cols = [x for x in range(w)
|
||||
if any(img.pixelColor(x, y).blue() - img.pixelColor(x, y).red() > 80
|
||||
for y in range(0, h, 2))]
|
||||
assert cols
|
||||
# One figure, in the middle: nothing in the outer fifths.
|
||||
assert min(cols) > w * 0.2 and max(cols) < w * 0.8
|
||||
|
||||
|
||||
def test_every_frame_wobbles(qapp):
|
||||
r = LintRenderer()
|
||||
r.asleep = False
|
||||
|
||||
def draw():
|
||||
img = QImage(200, 100, QImage.Format.Format_ARGB32)
|
||||
img.fill(QColor(205, 205, 205))
|
||||
p = QPainter(img)
|
||||
r.paint(p, QRectF(0, 0, 200, 100), QColor(40, 110, 220))
|
||||
p.end()
|
||||
return img
|
||||
|
||||
first = draw()
|
||||
assert draw() == first # the same step draws the same
|
||||
r.posture = STAND
|
||||
first = _draw(r, 200, 100)
|
||||
assert _draw(r, 200, 100) == first # the same step draws the same
|
||||
r.step += 1
|
||||
assert draw() != first # the next one is re-wobbled
|
||||
assert _draw(r, 200, 100) != first # the next one is re-wobbled
|
||||
|
||||
|
||||
def test_the_wheel_adds_black_for_lint_only(qapp, tmp_path):
|
||||
prefs, vis = _tile(tmp_path, "lint")
|
||||
seen = []
|
||||
for _ in range(4):
|
||||
vis.cycle_mode()
|
||||
seen.append(vis._mode)
|
||||
assert seen == [MODE_DIM, MODE_BLACK, MODE_OFF, MODE_ON]
|
||||
vis.cycle_mode()
|
||||
vis.cycle_mode()
|
||||
assert vis._mode == MODE_BLACK
|
||||
assert vis.paint_color() == QColor(0, 0, 0)
|
||||
prefs.set("visualizer_style", "bars") # black means nothing there
|
||||
assert vis.paint_color() == vis.palette().highlight().color()
|
||||
vis.cycle_mode()
|
||||
assert vis._mode == MODE_OFF
|
||||
prefs2, bars = _tile(tmp_path / "b", "bars")
|
||||
seen = []
|
||||
for _ in range(3):
|
||||
bars.cycle_mode()
|
||||
seen.append(bars._mode)
|
||||
assert seen == [MODE_DIM, MODE_OFF, MODE_ON]
|
||||
|
||||
|
||||
def test_it_keeps_its_clock_with_nothing_playing(qapp, tmp_path):
|
||||
_, vis = _tile(tmp_path, "lint")
|
||||
assert vis._timer.isActive() # sits, and will fall asleep
|
||||
_, bars = _tile(tmp_path / "b", "bars")
|
||||
assert not bars._timer.isActive()
|
||||
vis._renderer.posture = STAND
|
||||
for _ in range(int(vl.SIT_AFTER_S * 60) + 30):
|
||||
vis._advance_frame() # fed silence, not the old song
|
||||
assert vis._renderer.posture == SIT
|
||||
vis.cycle_mode(); vis.cycle_mode(); vis.cycle_mode()
|
||||
assert vis._mode == MODE_OFF and not vis._timer.isActive()
|
||||
|
||||
Reference in New Issue
Block a user