#!/bin/sh
#
# load the default soundfont file automatically
#

. /etc/sysconfig/sound
test x"$LOAD_SEQUENCER" = xyes || exit 0

test -x /usr/bin/asfxload || exit 0

. /etc/rc.status

load_sf () {
  for d in /usr/share/sounds/sf2 \
           /usr/share/sfbank \
           /usr/local/lib/sfbank \
           /usr/share/sfbank/creative \
           /usr/local/lib/sfbank/creative \
	   "/windows/c/Program Files/Creative/SBLive/SFBank" \
	   "/windows/c/Programme/Creative/SBLive/SFBank" \
           ; do
    if [ -r "$d/$1" ]; then
      echo -n "Loading soundfont $d/$1"
      /usr/bin/asfxload "$d/$1"
      rc_status -v -r
      return 0
    fi
  done
  return 1
}

init_remote () {
  # this is needed for Audigy2 platinum EX
  devs=`grep '^[0-9].*Audigy' /proc/asound/cards | cut -b 1`
  for c in $devs; do
    echo -en "\xf0\x00\x20\x21\x61\x00\x00\x00\x7f\x00\xf7" > /dev/snd/midiC${c}D1
  done
}

case $SOUNDFONT_FILES in
/*)
  if [ -r "$SOUNDFONT_FILES" ]; then
      echo -n "Loading soundfont $SOUNDFONT_FILES"
      /usr/bin/asfxload "$d/$1"
      rc_status -v -r
      exit 0
  fi
  ;;
esac

for file in $SOUNDFONT_FILES default.bnk default.sf2 ; do
  if load_sf $file ; then
     break
  fi
done

init_remote

exit 0
