Set POTACAT's sound card in radio configure

POTACAT keeps Chromium's device ids, which only it can see, with each
device's name beside it, and when a saved id matches no device it takes
the one device of that name when it starts (lib/audio-device-heal.js).
So HamPack's rig gets PipeWire's names for the radio's card as those
names, which is how Chromium names PipeWire's devices, and placeholder
ids that match nothing. Only HamPack's rig gets a sound card; one you
chose on it is left alone unless --force, which now keeps the rig's
other settings.

Every program that uses the radio's sound card now gets it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Young
2026-11-28 13:31:11 -07:00
co-authored by Claude Opus 5.5
parent 8020cdc061
commit b2ffaf9592
5 changed files with 104 additions and 24 deletions
+51 -17
View File
@@ -1059,27 +1059,61 @@ configure_potacat() {
else
state="empty"
fi
local set_rig=0 set_sound=0 sound=""
SAID=() LEFT=()
case "$state" in
already) report POTACAT "already set up"; return ;;
already) ;;
theirs)
if (( ! FORCE )); then
report POTACAT "left alone: it has a radio set up already. \`radio configure --force\` adds rigctld to My Rigs and makes it active"
return
if (( FORCE )); then
set_rig=1
else
LEFT+=("its own radio")
fi ;;
*) set_rig=1 ;;
esac
(( ! set_rig )) || SAID+=("rig \"$1 (HamPack's rigctld)\" is rigctld, and active")
back_up "$global"
tmp="$(mktemp "$global.XXXXXX")" || return 1
if ! jq --argjson t "$target" --arg name "$1 (HamPack's rigctld)" --arg cat "$cat_file" --arg global "$global" '
.rigs = ([(.rigs // [])[] | select(.id != "rig_hampack")] + [{id: "rig_hampack", name: $name, catTarget: $t}])
| .activeRigId = "rig_hampack"
| if $cat == $global then .catTarget = $t else . end
' "$global" > "$tmp" || ! chmod --reference="$global" "$tmp" || ! mv -f "$tmp" "$global"; then
rm -f "$tmp"
report POTACAT "couldn't change $global"
return 1
# The sound card goes on HamPack's rig only. POTACAT keeps Chromium's device
# ids, which only it can see, with the device's name (its label) beside
# each. When a saved id matches no device, POTACAT takes the one device
# whose name is the saved label (lib/audio-device-heal.js, at launch). So
# the rig gets PipeWire's names for the card as labels, which is how
# Chromium names PipeWire's devices, and ids that match nothing.
if [ -n "$PW_IN_NAME" ] && { (( set_rig )) || jq -e 'any(.rigs // [] | .[]; .id == "rig_hampack")' "$global" > /dev/null; }; then
sound="$(jq -r --arg in "$PW_IN_DESC" --arg out "$PW_OUT_DESC" '
(first(.rigs // [] | .[] | select(.id == "rig_hampack")) // {}) as $r
| def unset(id): (id // "") as $i | $i == "" or $i == "default" or $i == "communications" or ($i | startswith("hampack:"));
if $r.remoteAudioInputLabel == $in and $r.remoteAudioOutputLabel == $out then "already"
elif unset($r.remoteAudioInput) and unset($r.remoteAudioOutput) then "empty"
else "theirs" end' "$global")" || { report POTACAT "couldn't read $global"; return 1; }
if [ "$sound" = empty ] || { [ "$sound" = theirs ] && (( FORCE )); }; then
set_sound=1
SAID+=("sound card \"$PW_OUT_DESC\", which POTACAT finds by name when it starts")
elif [ "$sound" = theirs ]; then
LEFT+=("its sound card")
fi
fi
if [ "$cat_file" != "$global" ]; then
if (( set_rig || set_sound )); then
back_up "$global"
tmp="$(mktemp "$global.XXXXXX")" || return 1
if ! jq --argjson t "$target" --arg name "$1 (HamPack's rigctld)" --arg cat "$cat_file" --arg global "$global" \
--argjson rig "$set_rig" --argjson sound "$set_sound" \
--arg in_id "hampack:$PW_IN_NAME" --arg in_label "$PW_IN_DESC" --arg out_id "hampack:$PW_OUT_NAME" --arg out_label "$PW_OUT_DESC" '
(first(.rigs // [] | .[] | select(.id == "rig_hampack")) // {}) as $old
| ($old
+ (if $rig == 1 then {id: "rig_hampack", name: $name, catTarget: $t} else {} end)
+ (if $sound == 1 then {remoteAudioInput: $in_id, remoteAudioInputLabel: $in_label,
remoteAudioOutput: $out_id, remoteAudioOutputLabel: $out_label} else {} end)) as $new
| .rigs = ([(.rigs // [])[] | select(.id != "rig_hampack")] + [$new])
| if $rig == 1 then .activeRigId = "rig_hampack" | (if $cat == $global then .catTarget = $t else . end) else . end
' "$global" > "$tmp" || ! chmod --reference="$global" "$tmp" || ! mv -f "$tmp" "$global"; then
rm -f "$tmp"
report POTACAT "couldn't change $global"
return 1
fi
fi
if (( set_rig )) && [ "$cat_file" != "$global" ]; then
back_up "$cat_file"
mkdir -p "$(dirname "$cat_file")" && { [ -f "$cat_file" ] || echo '{}' > "$cat_file"; } || return 1
tmp="$(mktemp "$cat_file.XXXXXX")" || return 1
@@ -1089,7 +1123,7 @@ configure_potacat() {
return 1
fi
fi
report POTACAT "rig \"$1 (HamPack's rigctld)\" is rigctld, and active"
say_changes POTACAT
}
# Graywolf keeps its settings in graywolf.db. If it has no channels yet and
@@ -1337,7 +1371,7 @@ configure() {
if [ -z "$card" ]; then
echo "No sound card was found with the radio: choose the one it's connected to in each program yourself."
elif (( pipewire )); then
echo "Choose the radio's sound card yourself in POTACAT, which names it in a way radio can't: it's \"$PW_OUT_DESC\" ($card)."
echo "The radio's sound card is \"$PW_OUT_DESC\" ($card)."
else
echo "PipeWire didn't list the radio's sound card, $card (\"$(attr "${CARD_USB[$(card_of "$radio")]}" product)\"), so choose it yourself in WSJT-X, JS8Call and POTACAT."
fi