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
Showing only changes of commit 4147eaeaa4 - Show all commits
+23 -7
View File
@@ -33,9 +33,7 @@ context.objects = [
media.class = "Audio/Sink" audio.position = [ FL FR ] media.class = "Audio/Sink" audio.position = [ FL FR ]
object.linger = true } } object.linger = true } }
] ]
# The microphone is a loopback virtual source (like echo-cancel) rather than # The microphone is a loopback virtual source, like echo-cancel creates.
# a null-audio-sink with a Source media class: WirePlumber's event dispatcher
# intermittently stalls on the latter, which blocks all linking.
context.modules = [ context.modules = [
{ name = libpipewire-module-loopback { name = libpipewire-module-loopback
args = { args = {
@@ -65,15 +63,31 @@ trap cleanup EXIT INT TERM
pipewire >"$XDG_RUNTIME_DIR/pipewire.log" 2>&1 & PIDS="$PIDS $!" pipewire >"$XDG_RUNTIME_DIR/pipewire.log" 2>&1 & PIDS="$PIDS $!"
sleep 1 sleep 1
wireplumber >"$XDG_RUNTIME_DIR/wireplumber.log" 2>&1 & PIDS="$PIDS $!" wireplumber >"$XDG_RUNTIME_DIR/wireplumber.log" 2>&1 & PIDS="$PIDS $!"
sleep 2
# wait_for <pattern>: poll the probe (up to ~20 s) until it prints pattern.
wait_for() {
for _ in $(seq 1 40); do
"$PROBE" 2>/dev/null | grep -q -- "$1" && return 0
sleep 0.5
done
echo "timed out waiting for '$1'"
return 1
}
# Let WirePlumber finish its startup (it has picked a default sink) before
# any stream appears: streams that show up while it is still initialising
# can wedge its event queue, after which nothing gets linked.
wait_for '\[default'
LOGS="$XDG_RUNTIME_DIR" LOGS="$XDG_RUNTIME_DIR"
# Two minutes of silence as a regular file: older pw-cat (PipeWire 1.4)
# silently exits when reading raw audio from /dev/zero.
head -c 23040000 /dev/zero > "$LOGS/silence.raw"
pw-cat --playback --raw --rate 48000 --channels 2 --format s16 \ pw-cat --playback --raw --rate 48000 --channels 2 --format s16 \
-P '{ application.name = "Test Player" media.name = "Smoke test tone" }' \ -P '{ application.name = "Test Player" media.name = "Smoke test tone" }' \
/dev/zero >"$LOGS/play.log" 2>&1 & PIDS="$PIDS $!" "$LOGS/silence.raw" >"$LOGS/play.log" 2>&1 & PIDS="$PIDS $!"
pw-cat --record --raw --rate 48000 --channels 1 --format s16 \ pw-cat --record --raw --rate 48000 --channels 1 --format s16 \
-P '{ application.name = "Test Recorder" media.name = "Mic capture" }' \ -P '{ application.name = "Test Recorder" media.name = "Mic capture" }' \
/dev/null >"$LOGS/record.log" 2>&1 & PIDS="$PIDS $!" /dev/null >"$LOGS/record.log" 2>&1 & PIDS="$PIDS $!"
sleep 2 wait_for 'Test Player | .*-> ' || true
fail=0 fail=0
OUT="$LOGS/probe.out" OUT="$LOGS/probe.out"
@@ -92,7 +106,9 @@ step() {
fi fi
} }
step 'Test Player | 100%' step 'Test Player | 100%'
step 'Test Headphones | 50% (-18.06 dB)' volume test_headphones 50 # Change the volume of the sink the test stream plays to: in CI (PipeWire
# 1.4) a volume set on an idle, suspended null sink was not applied.
step 'Test Speakers | 50% (-18.06 dB)' volume test_speakers 50
step 'Test Microphone | .*muted' mute test_mic 1 step 'Test Microphone | .*muted' mute test_mic 1
step 'Test Headphones | .*\[default\]' default test_headphones step 'Test Headphones | .*\[default\]' default test_headphones
STREAM=$("$PROBE" | awk -F: '/Test Player/ {gsub(/ /,"",$1); print $1; exit}') STREAM=$("$PROBE" | awk -F: '/Test Player/ {gsub(/ /,"",$1); print $1; exit}')