SpriteandClaude Opus 5.5 6c7f45d5f9
CI / check (pull_request) Successful in 9s
CI / native (pull_request) Failing after 1m4s
fix: make the smoke test check results and avoid a WirePlumber stall
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>
2026-11-22 22:58:18 +00:00

moonmix

A pavucontrol-style volume control for modern Linux audio (PipeWire with WirePlumber), written in MoonBit with a GTK4 GUI.

moonmix talks to the audio stack through its libraries: libwireplumber-0.5 on top of libpipewire-0.3. It never runs wpctl, pactl, pw-cli, pw-dump or any other CLI tool.

Playback Output Devices
Playback tab Output Devices tab
Recording Input Devices
Recording tab Input Devices tab

(Rendered headlessly against a private PipeWire with null sinks; see Testing.)

Features (v1)

  • Playback: every application stream, with a volume slider, mute and the output device it plays to (choose another to move it).
  • Recording: capture streams, same controls, input device selector.
  • Output Devices / Input Devices: sinks and sources with volume, mute and a Default toggle that shows and sets the default device.
  • Volumes in percent exactly like pavucontrol/wpctl: the cubic mapping of PipeWire's linear channelVolumes, up to 150%, with the dB value next to it. One slider moves all channels, keeping the channel balance.
  • Live updates: devices and streams appearing, disappearing or changing elsewhere (another mixer, keyboard volume keys, a new Bluetooth headset) show up immediately.

Not yet included: the Configuration tab (card profiles), per-channel sliders, peak meters, monitor sources in Input Devices.

Architecture

cmd/moonmix        GUI: builds tabs, reconciles widgets with view rows
cmd/moonmix-probe  headless CLI over the same stack (smoke tests, debugging)
model/             pure MoonBit: volume curve, state reducer, view model
wp/                WirePlumber binding: wp_stub.c + wp.mbt
gtk/               minimal hand-written GTK4 binding: gtk_stub.c + gtk.mbt
tools/pkg-cc       C compiler wrapper that adds pkg-config flags
flowchart LR
  PW[(PipeWire)] <--> WP[libwireplumber<br/>mixer-api, default-nodes-api,<br/>object manager]
  WP -- "(kind, id) events" --> WPB[wp package]
  WPB -- "model.Event" --> S[model.State.apply]
  S --> V[model.rows / diff_rows]
  V --> G[GTK4 widgets]
  G -- "set volume / mute / default / move" --> WPB
  • WirePlumber, not raw PipeWire. The C layer (wp/wp_stub.c, about 460 lines) does what wpctl does internally. A WpObjectManager watches audio nodes, links and the default metadata. The mixer-api plugin reads and writes volume and mute; for hardware sinks it goes through the device's route, which is where pavucontrol's numbers live. The default-nodes-api plugin reads and sets the default sink and source. To move a stream, moonmix sets target.object in the default metadata, as pipewire-pulse does for pavucontrol. The C layer sends MoonBit one callback per change, (kind, id). MoonBit then pulls node properties and volumes through small accessor functions, so no C structs cross the FFI boundary.
  • One main loop. WirePlumber and GTK4 both run on the default GLib main context, so events arrive on the GUI thread with no locking or polling.
  • Pure core. Everything else is plain MoonBit in model/: the cubic and linear conversions, dB formatting, linked-slider scaling, the reducer that applies node, link and default events, the per-tab rows, and the row diff the GUI applies. moon test covers it on any target.
  • GTK binding. It is hand-written and minimal. Each widget gets a tag when it is created, and signals come back as (tag, value) through a single callback. While MoonBit updates widgets from the model, signals are suppressed so model updates never echo back into PipeWire. For a short time after the user moves a slider, remote updates to that slider are ignored so it doesn't jump while being dragged.

Building

Dependencies

You need MoonBit (curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash, then add ~/.moon/bin to PATH), a C compiler, pkg-config and the development files:

Distro Packages
Arch pipewire wireplumber gtk4 pkgconf base-devel
Debian 13+ / Ubuntu 24.04+ build-essential pkg-config libpipewire-0.3-dev libwireplumber-0.5-dev libgtk-4-dev
Fedora (untested) gcc pkgconf-pkg-config pipewire-devel wireplumber-devel gtk4-devel

You need WirePlumber 0.5 and GTK 4.12 or newer. Debian 11 and 12 ship WirePlumber 0.4, which is not supported.

Build and run

moon build --target native --release
./_build/native/release/build/cmd/moonmix/moonmix.exe

To install it for your user:

install -Dm755 _build/native/release/build/cmd/moonmix/moonmix.exe ~/.local/bin/moonmix
install -Dm644 data/org.latha.moonmix.desktop ~/.local/share/applications/org.latha.moonmix.desktop

Pkg-config flags: moon does not expand $(pkg-config ...) in moon.pkg link options. Instead, the packages point link.native.stub-cc and cc at tools/pkg-cc, a wrapper that adds pkg-config --cflags --libs libpipewire-0.3 wireplumber-0.5 gtk4. moon derives the archiver name from the compiler name, so tools/pkg-ar is a passthrough to ar. Set MOONMIX_CC or MOONMIX_AR to use another compiler or archiver.

Headless probe

moonmix-probe uses the same binding and model without a GUI:

P=./_build/native/debug/build/cmd/moonmix-probe/moonmix-probe.exe
$P                                  # print what every tab shows
$P volume alsa_output.pci-0000_00_1f.3.analog-stereo 40
$P mute 57 1                        # node id or node.name
$P default bluez_output.XX_XX.1
$P move <stream-id> <sink-id-or-name>

Testing

moon test --target wasm-gc          # pure model tests, no libraries needed
moon check --target native          # type-check everything
tools/smoke-test.sh /tmp/shot       # needs pipewire, wireplumber, pw-cat, gtk4-broadwayd

tools/smoke-test.sh starts a private PipeWire and WirePlumber in a temp XDG_RUNTIME_DIR. The instance has two null sinks, a loopback virtual microphone, and one playback and one capture stream created with pw-cat; the CLI is used only by the test harness. The script runs every probe action and checks its effect, then starts the GUI under GTK's broadway backend. With MOONMIX_SCREENSHOT set, the GUI renders each tab offscreen to a PNG and exits.

CI (.gitea/workflows/ci.yaml) runs the pure checks on the default runner. It runs the native build and the smoke test in a debian:trixie container, because bullseye has no WirePlumber 0.5.

Releases

Versioning uses sweet: add a change note with sweet change and prepare releases with sweet bump. The version lives in moon.mod (the // sweet-version line).

S
Description
PipeWire/WirePlumber volume control GUI (pavucontrol-like) in MoonBit
Readme
1.3 MiB
0 Stars 1 Watchers 0 Forks
Languages
MoonBit 53.8%
C 26.2%
Python 9.4%
Shell 7.9%
Just 1.3%
Other 1.4%