#!/usr/bin/env bash
set -euo pipefail
rule_dir=${XDG_CONFIG_HOME:-$HOME/.config}/wireplumber/wireplumber.conf.d
rule_file=$rule_dir/50-mpcpi-no-acp.conf
if [[ -f "$rule_file" ]]; then
    exit 0
fi
mkdir -p "$rule_dir"
cat >"$rule_file" <<'RULE'
# Installed by the MPC-Pi bundle: keep ALSA devices off the ACP path so the
# graph rate is not resampled into a pinned 48 kHz device profile.
monitor.alsa.rules = [
  {
    matches = [ { device.name = "~^alsa_card\\..*" } ]
    actions = { update-props = { api.alsa.use-acp = false } }
  }
]
RULE
printf 'Installed %s (one-time); restarting wireplumber once to apply it\n' "$rule_file"
systemctl --user restart wireplumber || true
sleep 3
