8.6 KiB
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 |
|---|---|
![]() |
![]() |
| Recording | Input Devices |
![]() |
![]() |
(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 whatwpctldoes internally. AWpObjectManagerwatches audio nodes, links and thedefaultmetadata. 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 setstarget.objectin thedefaultmetadata, 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 testcovers 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
install -Dm644 data/icons/hicolor/scalable/apps/org.latha.moonmix.svg ~/.local/share/icons/hicolor/scalable/apps/org.latha.moonmix.svg
install -Dm644 data/icons/hicolor/symbolic/apps/org.latha.moonmix-symbolic.svg ~/.local/share/icons/hicolor/symbolic/apps/org.latha.moonmix-symbolic.svg
gtk-update-icon-cache -f -t ~/.local/share/icons/hicolor # optional
The app icon is org.latha.moonmix (a speaker with a volume slider), shipped
as scalable and symbolic SVGs under data/icons/hicolor/. The window uses it
as its icon and the program name is org.latha.moonmix, which matches the
.desktop file so Wayland shells show it too. Run from a checkout, moonmix
also searches ./data/icons and $MOONMIX_ICON_DIR.
Icons
Everything else uses the desktop's icon theme (Adwaita, Breeze, Papirus...
any theme with the standard freedesktop names; install adwaita-icon-theme
if icons are missing). The names are chosen in model/icons.mbt and tested
with moon test; the GTK layer only asks the theme has_icon:
- Devices: the device's own
device.icon-name/node.icon-name, thendevice.form-factor(headphone, headset, speaker, microphone, webcam, handset, tv, hdmi...), HDMI/webcam/Bluetooth/USB hints, then the direction (speakers or microphone), thenaudio-card-symbolicandaudio-x-generic-symbolic. Symbolic variants are tried first so they follow the theme's foreground colour.image-missingis the very last resort. - Streams:
application.icon-name/media.icon-name, then the app's launcher icon found in the installed.desktopfiles (bypipewire.access.portal.app_id,application.process.binaryorapplication.name), thenapplication-x-executable-symbolic. - Mute button:
audio-volume-high/medium/low/muted-symbolicfollowing the volume and mute state. Row icons are 32 px, button and tab icons 16 px.
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 gio-unix-2.0. 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).



