#!/bin/sh
#
# set default volumes for playback on ALSA
#
# set_default_mixer [-f] [card#]
#
# written by Takashi Iwai <tiwai@suse.de>
#

forced=
if [ x$1 = x-f ]; then
    forced=yes
    shift
fi

if [ -f /var/lib/alsa/asound.state -a -z "$forced" ]; then
  /usr/sbin/alsactl restore >/dev/null 2>&1
  exit 0
fi

if [ -n "$1" ]; then
    case "$1" in
	[0-9]*)
	    card="-D hw:$1";;
	*)
	    card="-D $1";;
    esac
fi

if amixer $card | grep -q "'Master"; then
    slavevolp="100%"
    slavevoldb="0dB"
else
    slavevolp="75%"
    slavevoldb="-12dB"
fi

amixer -q -s $card <<EOF
set Master 75% unmute
set Master -12dB
set 'Master Mono' 75% unmute
set 'Master Mono' -12dB
set Front $slavevolp unmute
set Front $slavevoldb
set PCM $slavevolp unmute
set PCM $slavevoldb
set Synth $slavevolp unmute
set Synth $slavevoldb
set Speaker $slavevolp unmute
set Speaker $slavevoldb
set CD $slavevolp unmute
set CD $slavevoldb
# mute mic
set Mic 0% mute
# ESS 1969 chipset has 2 PCM channels
set PCM,1 90% unmute
set PCM,1 0dB
# Trident/YMFPCI/emu10k1
set Wave 100% unmute
set Music 100% unmute
set AC97 100% unmute
# CS4237B chipset:
set 'Master Digital' 75% unmute
# Envy24 chips with analog outs
set DAC 90% unmute
set DAC -12dB
set DAC,0 90% unmute
set DAC,0 -12dB
set DAC,1 90% unmute
set DAC,1 -12dB
# some notebooks use headphone instead of master
set Headphone $slavevolp unmute
set Headphone $slavevoldb
set Playback 100% unmute
# turn off digital switches
set "SB Live Analog/Digital Output Jack" off
set "Audigy Analog/Digital Output Jack" off
# VIA82xx
set "VIX DXS" 100%
set "VIX DXS",1 100%
set "VIX DXS",2 100%
set "VIX DXS",3 100%
# capture
set Capture 12dB cap
EOF

# run platform-defined scripts (if any)
for i in /etc/alsa.d/volume/*; do
    if [ -x "$i" ]; then
	case "$i" in
	    *~|*.bak|*.rpm*)
		;;
	    /etc/alsa.d/volume/[0-9]*)
		"$i" "$@"
	esac
    fi
done

exit 0
