feature: WirePlumber binding and headless probe

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>
This commit is contained in:
SpriteandClaude Opus 5.5 committed 2026-11-22 22:28:50 +00:00
1 parent c7314f4188
commit c55883b8ad
10 files changed
+985

No files matched your search

+146
View File
@@ -0,0 +1,146 @@
// moonmix-probe: headless companion to the GUI. Connects through the same
// WirePlumber binding and model, prints what each tab would show, and can
// apply one action. Used for smoke tests and debugging without a display.
//
// moonmix-probe print all tabs
// <id> may be a numeric node id or a node.name.
//
// moonmix-probe volume <id> <pct> set linked volume (cubic %)
// moonmix-probe mute <id> <0|1>
// moonmix-probe default <id> make sink/source the default
// moonmix-probe move <stream> <dev> route a stream to a device
///|
extern "C" fn c_exit(code : Int32) = "exit"
///|
fn print_state(state : @model.State) -> Unit {
for tab in @model.Tab::all() {
println("== \{tab.label()}")
let rows = @model.rows(state, tab)
if rows.length() == 0 {
println(" (none)")
}
for r in rows {
let flags = []
if r.is_default {
flags.push("default")
}
if r.mute {
flags.push("muted")
}
if r.current_choice >= 0 {
flags.push("-> " + r.choices[r.current_choice].label)
}
let vol = if r.has_volume { r.volume_text } else { "(no volume)" }
let f = if flags.length() > 0 {
" [" + flags.join(", ") + "]"
} else {
""
}
println(" \{r.id}: \{r.title} | \{vol} | ch=\{r.volumes.length()}\{f}")
}
}
}
///|
fn parse(s : String) -> Double {
@string.parse_double(s) catch {
_ => {
println("moonmix-probe: not a number: \{s}")
c_exit(2)
0.0
}
}
}
///|
/// Node id from a number or a node.name.
fn resolve(state : @model.State, s : String) -> Int32 {
for id, n in state.nodes {
if n.name == s {
return id
}
}
parse(s).to_int()
}
///|
fn act(state : @model.State, args : Array[String]) -> Bool {
match args {
["volume", id, pct] => {
let id = resolve(state, id)
let vols = match state.nodes.get(id) {
Some(n) => n.volumes
None => []
}
@wp.set_volumes(id, @model.scale_linked(vols, parse(pct)))
}
["mute", id, on] => @wp.set_mute(resolve(state, id), on == "1")
["default", id] => {
let id = resolve(state, id)
match state.nodes.get(id).map(fn(n) { n.kind() }) {
Some(Sink) => @wp.set_default_sink(id)
Some(Source) => @wp.set_default_source(id)
_ => false
}
}
["move", stream, dev] =>
@wp.move_stream(resolve(state, stream), resolve(state, dev))
_ => {
println("moonmix-probe: unknown command")
false
}
}
}
///|
fn main {
let argv = @env.args()
let args = if argv.length() > 1 { argv[1:].to_owned() } else { [] }
let state = @model.State::new()
@wp.on_event(fn(ev) {
for e in @wp.to_model_events(ev) {
let _ = state.apply(e)
}
match ev {
// default-nodes-api reports defaults shortly after Ready: settle first.
Ready => @wp.timeout(300, 2)
Timeout(2) => {
print_state(state)
if args.length() > 0 {
let ok = act(state, args)
println(
"== action \{args.join(" ")}: \{if ok { "ok" } else { "FAILED" }}",
)
@wp.timeout(800, 1)
} else {
@wp.quit()
}
}
Timeout(1) => {
print_state(state)
@wp.quit()
}
PluginError => {
println("moonmix-probe: WirePlumber API modules failed to load")
c_exit(3)
}
Disconnected => {
println("moonmix-probe: disconnected")
c_exit(4)
}
Timeout(99) => {
println("moonmix-probe: timed out waiting for WirePlumber")
c_exit(5)
}
_ => ()
}
})
if !@wp.start() {
println("moonmix-probe: cannot connect to PipeWire")
c_exit(1)
}
@wp.timeout(10000, 99)
@wp.run()
}
+15
View File
@@ -0,0 +1,15 @@
// Headless probe: prints what each tab shows, can apply one action.
import {
"geordi/moonmix/model",
"geordi/moonmix/wp",
"moonbitlang/core/env",
"moonbitlang/core/string",
}
supported_targets = "-all+native"
pkgtype(kind: "executable")
options(
link: { "native": { "cc": "tools/pkg-cc" } },
)
+12
View File
@@ -0,0 +1,12 @@
// Generated using `moon info`, DON'T EDIT IT
package "geordi/moonmix/cmd/moonmix-probe"
// Values
// Errors
// Types and methods
// Type aliases
// Traits