#!/usr/bin/env fish

set opts "Fone\nSpeaker\nHDMI\nPhone"
set out (printf $opts | wdmenu -p "Output: ")
set vol (pamixer --get-volume)

switch "$out"
    case Fone
        pactl set-card-profile 0 output:analog-stereo+input:analog-stereo
        pactl set-default-sink (pactl list sinks short | grep alsa | head -n1 | cut -f2)
        pactl set-sink-port @DEFAULT_SINK@ analog-output-headphones
    case Speaker
        pactl set-card-profile 0 output:analog-stereo+input:analog-stereo
        pactl set-default-sink (pactl list sinks short | grep alsa | head -n1 | cut -f2:)
        pactl set-sink-port @DEFAULT_SINK@ analog-output-speaker
    case HDMI
        pactl set-card-profile 0 (
                env LC_ALL=C pactl  list cards |
                string replace -raf '^\s*(output:hdmi-stereo.*?input.*?): .*' '$1' |
                head -n1 )
        pactl set-default-sink (pactl list sinks short | grep hdmi | head -n1 | cut -f2)
    case Phone
        pactl unload-module module-null-sink
        pactl unload-module module-rtp-send

        pactl load-module module-null-sink sink_name=rtp format=s16be channels=2 rate=48000
        pactl load-module module-rtp-send source=rtp.monitor destination=192.168.0.169 port=4010 mtu=320

        pactl set-default-sink rtp
end

pamixer --set-volume "$vol"

# vim: ft=fish
