Add moonmix: pavucontrol-style PipeWire mixer in MoonBit (WirePlumber + GTK4) #1

Merged
nandi merged 11 commits from geordi/moonmix-v1 into main 2026-11-22 23:52:37 +00:00
Owner

Adds moonmix, a pavucontrol-style volume control for modern Linux audio (PipeWire + WirePlumber). It's written in MoonBit, built with the native backend, and uses a GTK4 GUI.

Why it's built this way

The requirement was to talk to the audio stack through its libraries and never shell out to wpctl, pactl, pw-cli or similar tools. moonmix links libwireplumber-0.5 and does what wpctl does internally:

  • a WpObjectManager over audio nodes, links and the default metadata;
  • the mixer-api plugin for volume and mute (for hardware sinks it goes through the device Route, which is where pavucontrol's numbers live);
  • the default-nodes-api plugin for the default sink and source;
  • target.object in the default metadata to move a stream, as pipewire-pulse does for pavucontrol.

GTK4 runs on the same GLib main loop as WirePlumber, so audio events reach the GUI thread with no polling or locking.

What's in it

  • model/: pure MoonBit, testable anywhere.
    • Volume curve: cubic percent ↔ linear channelVolumes, up to 150%, with dB.
    • A reducer that applies node, link and default events.
    • Per-tab view rows and the row diff the GUI applies.
  • wp/: a thin C stub plus MoonBit binding. MoonBit gets one (kind, id) callback per change and pulls details through accessors, so no C structs cross the FFI.
  • gtk/: a minimal hand-written GTK4 binding with one dispatch callback. Signals are suppressed during programmatic updates, so model updates never echo back into PipeWire.
  • cmd/moonmix: the GUI. Playback, Recording, Output Devices and Input Devices tabs with linked volume sliders, mute, a default-device toggle and a per-stream device selector. Everything updates live.
  • cmd/moonmix-probe: a headless CLI over the same stack, for smoke tests and debugging.
  • tools/pkg-cc: a compiler wrapper that adds pkg-config flags, because moon doesn't expand $(...) in moon.pkg link options.
  • tools/smoke-test.sh: starts a private PipeWire + WirePlumber with null sinks, a loopback mic and test streams. It checks the effect of every action and renders each GUI tab offscreen.
  • Packaging and releases: README (architecture, per-distro dependencies, build and run), .desktop file, sweet release config (moon.mod version annotated).
  • CI:
    • The pure job runs on the default runner.
    • The native build and smoke test run in a debian:trixie container, because bullseye has no WirePlumber 0.5 and its glibc needs -lpthread to link MoonBit's native runtime.

Verification

  • CI passes on Debian trixie (PipeWire 1.4.2, WirePlumber 0.5.8, GTK 4.18). The sandbox has Ubuntu 26.04 (PipeWire 1.6.2, WirePlumber 0.5.13, GTK 4.22.4); the smoke test passed 4/4 runs there after its last startup fix.
  • Coverage:
    • moon check --target native --deny-warn and moon fmt --check are clean.
    • 18 model tests pass on wasm-gc and native.
    • The native build links against libwireplumber, libpipewire and GTK4.
    • The smoke test checks listing, stream volumes and routing, volume to 50% (-18.06 dB), mute, setting the default (the playing stream follows it), and moving a stream.
  • Screenshots of all four tabs are in docs/screenshots/.

Getting CI green surfaced three quirks of the test setup, all now handled in tools/smoke-test.sh:

  • WirePlumber can wedge if streams appear during its startup, so the test waits until a default sink exists.
  • PipeWire 1.4's pw-cat doesn't create a stream from raw input, so the test plays a WAV with pw-play.
  • PipeWire 1.4 didn't apply a volume set on a suspended null sink, so the test changes the active sink.

Not verified

  • Real hardware and Bluetooth devices: their volumes go through mixer-api's device Route path, which only a desktop can exercise.
  • Deliberately out of scope for v1: the Configuration tab (card profiles), per-channel sliders and peak meters.

🤖 Generated with Claude Code

Adds moonmix, a pavucontrol-style volume control for modern Linux audio (PipeWire + WirePlumber). It's written in MoonBit, built with the native backend, and uses a GTK4 GUI. ## Why it's built this way The requirement was to talk to the audio stack through its libraries and never shell out to `wpctl`, `pactl`, `pw-cli` or similar tools. moonmix links libwireplumber-0.5 and does what wpctl does internally: - a `WpObjectManager` over audio nodes, links and the `default` metadata; - the `mixer-api` plugin for volume and mute (for hardware sinks it goes through the device Route, which is where pavucontrol's numbers live); - the `default-nodes-api` plugin for the default sink and source; - `target.object` in the `default` metadata to move a stream, as pipewire-pulse does for pavucontrol. GTK4 runs on the same GLib main loop as WirePlumber, so audio events reach the GUI thread with no polling or locking. ## What's in it - **`model/`**: pure MoonBit, testable anywhere. - Volume curve: cubic percent ↔ linear `channelVolumes`, up to 150%, with dB. - A reducer that applies node, link and default events. - Per-tab view rows and the row diff the GUI applies. - **`wp/`**: a thin C stub plus MoonBit binding. MoonBit gets one `(kind, id)` callback per change and pulls details through accessors, so no C structs cross the FFI. - **`gtk/`**: a minimal hand-written GTK4 binding with one dispatch callback. Signals are suppressed during programmatic updates, so model updates never echo back into PipeWire. - **`cmd/moonmix`**: the GUI. Playback, Recording, Output Devices and Input Devices tabs with linked volume sliders, mute, a default-device toggle and a per-stream device selector. Everything updates live. - **`cmd/moonmix-probe`**: a headless CLI over the same stack, for smoke tests and debugging. - **`tools/pkg-cc`**: a compiler wrapper that adds `pkg-config` flags, because moon doesn't expand `$(...)` in `moon.pkg` link options. - **`tools/smoke-test.sh`**: starts a private PipeWire + WirePlumber with null sinks, a loopback mic and test streams. It checks the effect of every action and renders each GUI tab offscreen. - **Packaging and releases**: README (architecture, per-distro dependencies, build and run), `.desktop` file, sweet release config (`moon.mod` version annotated). - **CI**: - The pure job runs on the default runner. - The native build and smoke test run in a `debian:trixie` container, because bullseye has no WirePlumber 0.5 and its glibc needs `-lpthread` to link MoonBit's native runtime. ## Verification - **CI passes on Debian trixie** (PipeWire 1.4.2, WirePlumber 0.5.8, GTK 4.18). The sandbox has Ubuntu 26.04 (PipeWire 1.6.2, WirePlumber 0.5.13, GTK 4.22.4); the smoke test passed 4/4 runs there after its last startup fix. - Coverage: - `moon check --target native --deny-warn` and `moon fmt --check` are clean. - 18 model tests pass on wasm-gc and native. - The native build links against libwireplumber, libpipewire and GTK4. - The smoke test checks listing, stream volumes and routing, volume to 50% (-18.06 dB), mute, setting the default (the playing stream follows it), and moving a stream. - Screenshots of all four tabs are in `docs/screenshots/`. Getting CI green surfaced three quirks of the *test setup*, all now handled in `tools/smoke-test.sh`: - WirePlumber can wedge if streams appear during its startup, so the test waits until a default sink exists. - PipeWire 1.4's `pw-cat` doesn't create a stream from raw input, so the test plays a WAV with `pw-play`. - PipeWire 1.4 didn't apply a volume set on a suspended null sink, so the test changes the active sink. ## Not verified - Real hardware and Bluetooth devices: their volumes go through mixer-api's device Route path, which only a desktop can exercise. - Deliberately out of scope for v1: the Configuration tab (card profiles), per-channel sliders and peak meters. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
nandi added 7 commits 2026-11-22 22:30:10 +00:00
Cubic percent <-> linear channelVolumes conversions (pavucontrol scale,
up to 150%), dB formatting, balance-preserving linked slider, a reducer
applying WirePlumber node/link/default events and per-tab view rows,
all covered by moon tests that run on any target.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Thin C layer over libwireplumber-0.5: an object manager for audio
nodes, links and the default metadata, plus the mixer-api and
default-nodes-api plugins (what wpctl uses internally) for volume, mute
and defaults. Streams are moved by setting target.object in the default
metadata, as pipewire-pulse does. No CLI tools are spawned.

tools/pkg-cc wraps the C compiler to append pkg-config flags because
moon does not expand $(pkg-config ...) in moon.pkg link options.

moonmix-probe prints what each tab shows and can apply one action.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hand-written minimal GTK4 binding (one dispatch callback, tag table,
signal suppression during programmatic updates) and the GUI: Playback,
Recording, Output Devices and Input Devices tabs with linked volume
sliders up to 150%, mute, default-device toggle and per-stream device
selector, updated live by diffing view rows. Includes a .desktop file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tools/smoke-test.sh starts a private PipeWire + WirePlumber with null
sinks/source and test streams, exercises every action through
moonmix-probe and renders the GUI offscreen under broadway.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
chore: Gitea Actions CI
CI / native (pull_request) Failing after 1m38s
CI / check (pull_request) Failing after 11s
5d74201d0c
Pure check and test job on the default runner; native build and
headless smoke test in a debian:trixie container (bullseye lacks
WirePlumber 0.5).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nandi added 2 commits 2026-11-22 22:58:22 +00:00
Linking MoonBit's native runtime on the bullseye runner fails with
undefined pthread symbols (glibc 2.31 needs -lpthread), so the check
job now only runs the wasm-gc tests and the native model tests move to
the debian:trixie job that already builds natively.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fix: make the smoke test check results and avoid a WirePlumber stall
CI / native (pull_request) Failing after 1m4s
CI / check (pull_request) Successful in 9s
6c7f45d5f9
The smoke test only checked exit codes, so CI passed the probe steps
even though volume and mute never changed. Each step now asserts the
expected state after the action and prints pw-cat, WirePlumber and node
diagnostics on failure.

The test microphone was a null-audio-sink with a Source media class.
WirePlumber's event dispatcher intermittently stalls on such a node and
then links nothing and ignores volume changes, which is what failed in
CI. It is now a loopback virtual source, like echo-cancel; three local
runs in a row pass. Screenshots are re-rendered from the new setup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nandi added 1 commit 2026-11-22 23:03:58 +00:00
fix: let WirePlumber settle before the smoke test starts streams
CI / native (pull_request) Failing after 1m33s
CI / check (pull_request) Successful in 10s
4147eaeaa4
Streams that appear while WirePlumber is still starting up can wedge its
event queue: no default sink is chosen, nothing is linked and volume
changes are dropped. This made the smoke test fail intermittently
locally and in CI. The test now polls moonmix-probe until a default sink
exists before starting the streams, then until the playback stream is
linked; four local runs in a row pass.

Also play a regular file instead of /dev/zero (PipeWire 1.4's pw-cat
exited silently on it in CI) and change the volume of the active sink,
since CI's PipeWire 1.4 did not apply a volume set on a suspended
null sink.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nandi added 1 commit 2026-11-22 23:14:08 +00:00
fix: play a WAV file with pw-play in the smoke test
CI / native (pull_request) Successful in 1m3s
CI / check (pull_request) Successful in 9s
bbef4b8ef7
In CI (PipeWire 1.4) pw-cat playing raw audio never created a stream,
from /dev/zero or from a regular file, so the Playback tab and the move
action could not be tested. Play a generated WAV file with pw-play
instead (header written in shell; the container has no python) and log
the player's exit status for diagnosis.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nandi changed title from moonmix v1: pavucontrol-like volume control in MoonBit (WirePlumber + GTK4) to Add moonmix: pavucontrol-style PipeWire mixer in MoonBit (WirePlumber + GTK4) 2026-11-22 23:15:54 +00:00
nandi merged commit 92ae5cdbfe into main 2026-11-22 23:52:37 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: geordi/moonmix#1