#
# Copyright (C) by Stefano Falsetto
# e-mail contact ....: mailto:stefko5@inwind.it
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#
# Config plugin for cdparanoia 
#

cat_variables_cdparanoia () {
    cat <<EOF
# Complete path for cdparanoia
cdparanoia_DECODER="$cdparanoia_DECODER"

# Device used to read audio tracks
CDPARA_DEVICE="$CDPARA_DEVICE"

# Handled format file in output
OUTPUT_FORMATS_cdparanoia=( $OUTPUT_FORMATS_cdparanoia )

# Parameters to output files in various formats
cdparanoia_TO_wav="$cdparanoia_TO_wav"
cdparanoia_TO_aiff="$cdparanoia_TO_aiff"
cdparanoia_TO_aifc="$cdparanoia_TO_aifc"
cdparanoia_TO_raw="$cdparanoia_TO_raw"
cdparanoia_TOFMT="$cdparanoia_TO_wav"


EOF
}


############
# MAIN
############

if [ $(expr "$SUPPORTED_FORMATS" : ".*CDA.*") -ne ${#SUPPORTED_FORMATS} ]; then
  begin_check cdparanoia
  find_prg cdparanoia
  cdparanoia_DECODER=$FOUND_PRG
  if [ -z "$cdparanoia_DECODER" ]; then
    missing cdparanoia "http://www.xiph.org/paranoia/"
  else
    EXTENSIONS="CDA"
    OUTPUT_FORMATS_cdparanoia="wav aiff aifc raw"
    cdparanoia_TO_wav="--output-wav"
    cdparanoia_TO_aiff="--output-aiff"
    cdparanoia_TO_aifc="--output-aifc"
    cdparanoia_TO_raw="--output-raw"
    cdparanoia_TOFMT=$cdparanoia_TO_wav
    AUDIO_PLUGINS="$AUDIO_PLUGINS cdparanoia"
    PARAMETERS="cdda:.*|--cdda-device"
    PLUGINS_WITH_PARAMETERS="$PLUGINS_WITH_PARAMETERS cdparanoia"
    SUPPORTED_FORMATS="$SUPPORTED_FORMATS $EXTENSIONS"
    QueryVersion $($cdparanoia_DECODER -V 2>&1 |$GREP "release"|cut -d' ' -f4) \
                 cdparanoia "9.7"
    echo

    CDPARA_DEVICE="/dev/cdrom"
    while [ 0 ]; do
      lechoc CYAN -n "Default device to read audio CD tracks [$CDPARA_DEVICE]: "
      read CDPD
      if [ "$CDPD" = "" ]; then
        break
      else
        if [ ! -b "$CDPD" ]; then
          lechoc GREEN "$CDPD is not a valid block device!"
        else
          DPARA_DEVICE=$CDPD
          break
        fi
      fi
    done

    echo
    echoc YELLOW " -> Default device to read CD audio tracks $CDPARA_DEVICE"
    echo
    #echoc CYAN "If device selected is wrong, you can edit CDPARA_DEVICE variable in"
    #echoc CYAN "$CONFFILE with a text editor or --cdda-device option at run time."
  fi
  end_check
fi

