Introducing a new way to review your PRs.

Read the announcement

crmne / spotifast

Spotify, native and fast. One lightweight Rust app for your whole library, local playback, and Spotify Connect on Linux, macOS, and Windows.

View on GitHub

19 documents · Updated Nov 18, 2026

docs / milkdrop-visualization-runtime

Milkdrop visualization runtime

MilkDrop is the music visualizer runtime powered by projectM. It turns the player's delayed stereo audio into animated frames and can show those frames in an independent window, a skin pane, or behind full-screen lyrics. The runtime keeps graphics work outside the main app process and uses shared memory when a skin needs the picture inside the app. For the wider visualizer model, see Skins and visualizations and Skin engine and Winamp compatibility.

Runtime architecture

Engine boundary

The MilkDrop engine is the projectM service that reads .milk presets and renders OpenGL pictures. It receives audio and preset changes from the player, then returns a visual frame without owning playback state. The runtime keeps this engine separate from the app's main UI so a slow preset or graphics call does not block the interface (src/milkdrop.rs• L1-10, src/…/engine.rs• L1-6).

References: src/milkdrop.rs• L1-10 src/…/engine.rs• L17-24

Process roles

The host is the app-side coordinator. It starts the same program as a MilkDrop child, provides the preset folder and display settings, sends live control messages, and receives window events. The child owns the projectM engine and its graphics context. This split also lets the child end without taking down the player (src/…/host.rs• L1-5, src/…/child.rs• L1-6).

The child has two output roles:

  • A window child presents frames directly in its own window.
  • An offscreen child renders frames for a skin pane or another app surface.

The app selects one visible role at a time. This avoids running two engines for the same picture while the user moves between a skin, lyrics, and the plain MilkDrop window (src/app.rs• L4910-4919).

References: src/…/host.rs• L44-73 src/…/child.rs• L34-63 src/app.rs• L4910-4924

Audio and preset flow

Audio feed

The player writes recent stereo samples to an audio ring. The child reads new samples with the same lag as the analyzer, so the picture follows the sound the user hears rather than the newest audio sample. A torn audio sample is safe for a visualizer and does not require the audio thread to wait (src/…/shm.rs• L1-8, src/…/shm.rs• L79-116).

Preset selection

The preset manager turns the preset folder into a playable sequence. It supports random order, folder order, previous and next history, locking the current preset, and timed changes with a cross-fade. It lists large preset packs away from the UI thread and can fetch the supported preset packs without freezing the player (src/milkdrop.rs• L134-153, src/milkdrop.rs• L178-210).

Before each rendered frame, the child updates the preset state, applies pending selection requests, and passes delayed audio to projectM. This keeps preset timing in the player-facing runtime rather than depending only on projectM's internal timer (src/…/child.rs• L958-980).

References: src/…/shm.rs• L17-24 src/…/shm.rs• L100-116 src/milkdrop.rs• L240-255 src/…/child.rs• L958-980

Frame transport

Shared frame buffer

The offscreen child and the app share a memory-mapped frame buffer. It has a small control area and three pixel slots. The child writes a complete frame to a free slot and publishes it. The app takes the newest complete slot on its next paint. Neither side waits for the other, so a late child cannot stall the UI (src/…/frames.rs• L1-13).

The slots use sequence checks to reject a copy that overlaps a write. If the child publishes several frames before the app paints, the app skips older frames and keeps the current picture until a valid newer frame arrives. This favors a fresh image over a growing queue (src/…/frames.rs• L226-294).

Frame requests

The app writes its needs into the same shared header. It requests a physical size, reports that the picture is being shown, sends preset steps, changes the frame pace, and can freeze the picture. These signals avoid pipe traffic on the UI paint path and let the child stop work when no surface watches it (src/…/frames.rs• L164-224).

The frame size keeps the picture's shape and uses even dimensions for projectM's render passes. Pane frames are limited to a smaller transfer size than full-screen lyric backgrounds because each pane frame crosses the process and graphics boundaries (src/…/frames.rs• L23-31, src/…/frames.rs• L78-88).

This diagram shows how audio and frame control cross into the child, then how a finished picture returns to the app.

flowchart LR
    Player[Player audio] --> AudioRing[Shared audio ring]
    App[App and skin pane] --> FrameHeader[Shared frame header]
    AudioRing --> Child[MilkDrop child]
    FrameHeader --> Child
    Child --> ProjectM[projectM engine]
    ProjectM --> Slots[Three shared frame slots]
    Slots --> App
    App --> Surface[Skin pane or lyric background]

References: src/…/frames.rs• L41-65 src/…/frames.rs• L226-294 src/…/frames.rs• L164-224

Rendering surfaces

Window rendering

The window child owns a window, an OpenGL context, and an event loop. It draws projectM into the window, then draws overlays over the picture before it presents the result. The host receives close, resize, position, full-screen, screen-rate, and key-command events through tagged child output (src/…/child.rs• L355-390, src/…/host.rs• L284-325).

The window pauses its render loop when it is hidden, minimized, or covered where the platform reports that state. It schedules frames at the selected rate or runs without a cap when requested. This limits wasted graphics work without changing the preset or audio state (src/…/child.rs• L267-313, src/…/child.rs• L452-459).

References: src/…/child.rs• L267-313 src/…/child.rs• L355-390 src/…/host.rs• L215-275

Offscreen rendering

The offscreen child uses a graphics context without a visible window. On Linux it can draw directly through a graphics device without a display server. On other supported systems it keeps a hidden window only as the context owner. ProjectM renders into an offscreen target, and the child publishes the pixels to the shared frame buffer (src/…/offscreen.rs• L1-11, src/…/offscreen.rs• L155-177).

The child watches the app's show signal. It leaves when input closes or when no surface has shown a frame for a short period. This makes a pane child a short-lived resource rather than a permanent background renderer (src/…/offscreen.rs• L24-34, src/…/offscreen.rs• L69-79).

References: src/…/child.rs• L65-77 src/…/offscreen.rs• L1-11 src/…/offscreen.rs• L129-177

OpenGL frame copy

The projectM engine draws at the requested inner size and copies the result into the target surface. A scale setting lets the engine render fewer pixels and stretch the picture back up when the graphics device is slow. The same engine can copy to a visible window or read pixels for offscreen publication (src/…/engine.rs• L170-257, src/…/engine.rs• L260-301).

References: src/…/engine.rs• L170-257 src/…/engine.rs• L260-301

Overlays and panes

Text overlays

Overlays add user-facing text without changing the preset. The runtime uses them for the help screen, song information, preset names, and frame-rate status. A text block can sit in the center or in a corner, with either a shadow or a dark backing so it stays readable over a moving picture (src/…/overlay.rs• L1-6, src/…/overlay.rs• L50-87).

The child keeps the song notice separate from persistent corner status. Song text can appear on change, remain in a corner, or stay hidden. The help block fades out, while status corners remain until the user turns them off (src/…/child.rs• L908-943, src/…/overlay.rs• L510-584).

References: src/…/overlay.rs• L17-35 src/…/overlay.rs• L380-390 src/…/child.rs• L908-943

Pane lifecycle

The pane stream is the app-side view of an offscreen child. A skin asks for a picture during paint. The stream requests a matching frame size, copies a new shared frame into an app texture, and returns one of three states: a frame, a waiting state, or the skin's normal bars (src/…/pane.rs• L41-56, src/…/pane.rs• L132-185).

The stream starts the child only while a surface needs the picture. It stops the child after the picture is no longer shown, or after a child dies or stops publishing. It also backs off before retrying repeated failures. A frozen lyric background keeps the last picture without asking the child to render new frames (src/…/pane.rs• L213-245, src/…/pane.rs• L247-307).

The same pane picture can fill a classic Winamp MilkDrop panel, a Windows Media Player skin visualization area, or the background behind full-screen lyrics. The host chooses the frame limit and freeze state from the surface that is active (src/app.rs• L4926-4979, src/…/milkdrop.rs• L117-133).

References: src/…/pane.rs• L82-104 src/…/pane.rs• L132-185 src/…/pane.rs• L213-245 src/app.rs• L4926-4979

Frame tests

Transport guarantees

The frame tests check the contract between the child and the app rather than the visual style of individual presets. They verify that the newest frame is taken once, frame sizes reach the child, a concurrent copy never produces a torn picture, and control signals cross the shared header (src/…/frames.rs• L334-407).

Child process guarantees

The end-to-end frame tests start the real child without a display server. They verify that it renders into shared memory, follows a pane resize, publishes opaque pixels, and exits when its input closes. They also verify that it leaves when the app stops watching instead of rendering forever. A machine without a usable graphics device is treated as an environment limitation rather than a rendering failure (tests/milkdrop_frames.rs• L23-60, tests/milkdrop_frames.rs• L63-118).

Pane recovery guarantees

Pane tests cover the user-visible fallback path. They check that a missing preset folder is not treated as a crash, that a dead or silent child returns the surface to the skin bars, that retries slow after repeated failures, and that a published frame accepts preset commands. They also cover a frozen picture and the larger full-screen frame limit (src/…/pane.rs• L448-627).

References: src/…/frames.rs• L334-407 tests/milkdrop_frames.rs• L63-118 src/…/pane.rs• L448-627

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the audio-ring lag and frame timing aligned with the visualizer timing contract.
  • Keep the shared frame header layout and slot rules compatible between the app and child builds.
  • Keep pane frame limits consistent with the texture path and full-screen lyric path.
  • Keep child exit codes and pane retry behavior consistent so missing graphics does not look like a crash.
  • Keep host control fields and child event fields synchronized when adding window or overlay controls.
  • Keep the single-visible-child rule intact when changing skin, lyric, or plain-window transitions.

Important failure modes

TriggerConsequenceGuard
No .milk preset is availableThe pane stays with the skin bars and retries laterPreset discovery refuses the child without counting it as a child failure
The graphics context cannot support projectMThe child exits and the pane returns to the barsThe offscreen path uses a distinct no-graphics exit result
A child stays alive but publishes no frameThe pane would wait forever without recoveryThe stream treats a long silent period as a hung child
The app stops showing the paneThe child could waste graphics time in the backgroundThe frame heartbeat and child watch timeout stop the renderer
The app reads a slot while the child writes itA partial image could reach the textureSequence checks discard the copy and keep the prior picture
A saved window size is invalidThe MilkDrop window could reopen off-screen or too largeThe host rejects unsafe saved geometry before starting the child

Key files

FileWhy to read it
src/milkdrop.rsDefines the MilkDrop runtime boundary, preset policy, timing, and shared public settings.
src/…/host.rsShows the host's child lifecycle and window control contract.
src/…/child.rsShows the child frame loop, window role, event reporting, and overlay use.
src/…/engine.rsShows the projectM rendering boundary for window and offscreen targets.
src/…/shm.rsDefines the audio path between the player and child.
src/…/frames.rsDefines pane frame publication, control signals, and size limits.
src/…/offscreen.rsShows how a hidden child renders only while a pane watches it.
src/…/pane.rsShows pane startup, texture updates, fallback, and retry behavior.
src/…/overlay.rsDefines the text layer over the visualizer picture.
src/app.rsConnects active app surfaces to the pane child and its pace or freeze state.
tests/milkdrop_frames.rsVerifies the real offscreen child and shared frame path end to end.