Set not1mm's sound card in radio configure
not1mm's voice keyer gets the radio's sound card, named exactly as the sounddevice library in not1mm's own Python lists it: its settings dialog finds the device by exact name, and falls back to the first one listed. PipeWire's name for the card, through PortAudio's JACK support, comes first, since it stays the same from boot to boot. Without it, or with two cards of the same name, it's ALSA's, which has the card's number in it; a number radio wrote before is updated when the card's number changes. The closing message now leaves only fldigi and POTACAT for you to set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
4053664d77
commit
c2cb2bc2f4
@@ -779,10 +779,42 @@ configure_direwolf() {
|
||||
report "Dire Wolf" "$message"
|
||||
}
|
||||
|
||||
# Print the output devices not1mm can play to, as "NAME<tab>HOST API", one to
|
||||
# a line, using the sounddevice library in not1mm's own Python
|
||||
not1mm_outputs() {
|
||||
local python="${UV_TOOL_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/uv/tools}/not1mm/bin/python"
|
||||
[ -x "$python" ] || return 1
|
||||
"$python" -I -c '
|
||||
import sounddevice as sd
|
||||
for d in sd.query_devices():
|
||||
if d["max_output_channels"] > 0:
|
||||
print(d["name"] + "\t" + sd.query_hostapis(d["hostapi"])["name"])
|
||||
' 2> /dev/null
|
||||
}
|
||||
|
||||
# Print the name not1mm's voice keyer should use for the radio's sound card:
|
||||
# PipeWire's description of it, through PortAudio's JACK support, which stays
|
||||
# the same from boot to boot. Failing that, ALSA's name for it, which has the
|
||||
# card's number in it: "USB Audio CODEC: USB Audio (hw:1,0)".
|
||||
# not1mm_device CARD_NUMBER
|
||||
not1mm_device() {
|
||||
local outputs
|
||||
outputs="$(not1mm_outputs)" || return 1
|
||||
if [ -n "$PW_OUT_DESC" ] && [ "$(cut -f1 <<< "$outputs" | grep -cxF "$PW_OUT_DESC")" -eq 1 ]; then
|
||||
echo "$PW_OUT_DESC"
|
||||
elif [ -n "$1" ]; then
|
||||
cut -f1 <<< "$outputs" | grep -F "(hw:$1," | head -1 | grep .
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# not1mm: rig control through rigctld, unless it uses flrig, TCI or another
|
||||
# rigctld already
|
||||
# rigctld already, and the radio's sound card for its voice keyer.
|
||||
# configure_not1mm CARD_NUMBER
|
||||
configure_not1mm() {
|
||||
local tmp
|
||||
local tmp rig_state device current set_rig=0 set_sound=0
|
||||
SAID=() LEFT=()
|
||||
if [ ! -x "$HOME/.local/bin/not1mm" ]; then
|
||||
report not1mm "not installed"
|
||||
return
|
||||
@@ -795,34 +827,55 @@ configure_not1mm() {
|
||||
report not1mm "skipped, because it's running and would overwrite its settings when it quits. Quit it and run \`radio configure\` again"
|
||||
return
|
||||
fi
|
||||
case "$(jq -r --arg addr "$RIGCTLD_ADDR" '
|
||||
if .userigctld == true and "\(.CAT_ip):\(.CAT_port)" == $addr then "done"
|
||||
elif .userigctld == true or .useflrig == true or .usetci == true then "set"
|
||||
else "unset" end' "$NOT1MM_CONF")" in
|
||||
done)
|
||||
report not1mm "already set up"
|
||||
return ;;
|
||||
set)
|
||||
if (( ! FORCE )); then
|
||||
report not1mm "left alone: it has rig control set up already. \`radio configure --force\` replaces that"
|
||||
return
|
||||
rig_state="$(jq -r --arg addr "$RIGCTLD_ADDR" '
|
||||
if .userigctld == true and "\(.CAT_ip):\(.CAT_port)" == $addr then "already"
|
||||
elif .userigctld == true or .useflrig == true or .usetci == true then "theirs"
|
||||
else "empty" end' "$NOT1MM_CONF")" ||
|
||||
{ report not1mm "couldn't read $NOT1MM_CONF"; return 1; }
|
||||
case "$rig_state" in
|
||||
already) ;;
|
||||
theirs)
|
||||
if (( FORCE )); then
|
||||
set_rig=1
|
||||
else
|
||||
LEFT+=("its rig control")
|
||||
fi ;;
|
||||
unset) ;;
|
||||
*)
|
||||
report not1mm "couldn't read $NOT1MM_CONF"
|
||||
return 1 ;;
|
||||
*) set_rig=1 ;;
|
||||
esac
|
||||
back_up "$NOT1MM_CONF"
|
||||
tmp="$(mktemp "$NOT1MM_CONF.XXXXXX")" || return 1
|
||||
if jq --arg ip "${RIGCTLD_ADDR%:*}" --argjson port "${RIGCTLD_ADDR#*:}" '
|
||||
.userigctld = true | .useflrig = false | .usetci = false | .CAT_ip = $ip | .CAT_port = $port
|
||||
' "$NOT1MM_CONF" > "$tmp" && chmod --reference="$NOT1MM_CONF" "$tmp" && mv -f "$tmp" "$NOT1MM_CONF"; then
|
||||
report not1mm "rig control through rigctld"
|
||||
else
|
||||
rm -f "$tmp"
|
||||
report not1mm "couldn't change $NOT1MM_CONF"
|
||||
return 1
|
||||
(( ! set_rig )) || SAID+=("rig control through rigctld")
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
if device="$(not1mm_device "$1")"; then
|
||||
current="$(jq -r '.sounddevice // ""' "$NOT1MM_CONF")"
|
||||
if [ "$current" = "$device" ]; then
|
||||
:
|
||||
elif is_default_device "$current" || (( FORCE )) ||
|
||||
# The same card under the number it had before
|
||||
{ [[ "$device" == *"(hw:"* ]] && [[ "$current" == "${device%(hw:*}(hw:"*")" ]]; }; then
|
||||
set_sound=1
|
||||
SAID+=("voice keyer on \"$device\"")
|
||||
else
|
||||
LEFT+=("its sound card ($current)")
|
||||
fi
|
||||
else
|
||||
SAID+=("choose its sound card yourself: its sounddevice library doesn't list the radio's")
|
||||
fi
|
||||
fi
|
||||
|
||||
if (( set_rig || set_sound )); then
|
||||
back_up "$NOT1MM_CONF"
|
||||
tmp="$(mktemp "$NOT1MM_CONF.XXXXXX")" || return 1
|
||||
if ! jq --arg ip "${RIGCTLD_ADDR%:*}" --argjson port "${RIGCTLD_ADDR#*:}" --arg device "${device:-}" \
|
||||
--argjson rig "$set_rig" --argjson sound "$set_sound" '
|
||||
(if $rig == 1 then .userigctld = true | .useflrig = false | .usetci = false | .CAT_ip = $ip | .CAT_port = $port else . end)
|
||||
| (if $sound == 1 then .sounddevice = $device else . end)
|
||||
' "$NOT1MM_CONF" > "$tmp" || ! chmod --reference="$NOT1MM_CONF" "$tmp" || ! mv -f "$tmp" "$NOT1MM_CONF"; then
|
||||
rm -f "$tmp"
|
||||
report not1mm "couldn't change $NOT1MM_CONF"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
say_changes not1mm
|
||||
}
|
||||
|
||||
# QLog keeps its rig profiles in its log database. Add a "HamPack" profile for
|
||||
@@ -1205,7 +1258,7 @@ configure() {
|
||||
configure_pat
|
||||
configure_fldigi
|
||||
configure_direwolf "$card"
|
||||
configure_not1mm
|
||||
configure_not1mm "$card_number"
|
||||
configure_qlog
|
||||
configure_potacat "$name"
|
||||
configure_graywolf "$card" "$name"
|
||||
@@ -1217,9 +1270,9 @@ 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 fldigi, not1mm and POTACAT, which name it in ways radio can't: it's \"$PW_OUT_DESC\" ($card)."
|
||||
echo "Choose the radio's sound card yourself in fldigi and POTACAT, which name it in ways radio can't: it's \"$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, fldigi, not1mm and POTACAT."
|
||||
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, fldigi and POTACAT."
|
||||
fi
|
||||
[ ${#BACKUPS[@]} -eq 0 ] || { echo "The settings were backed up first, to:"; printf ' %s\n' "${BACKUPS[@]}"; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user