#!/usr/bin/env bash

# Read in language file
source ${BBROOTDIR}/lang/${BBLANG}/audio_menu.lang

# Read in functions
source ${BBROOTDIR}/misc/commonfunctions.sh
source ${BBROOTDIR}/func/audiofunc.sh

####PROGRAM START#####

while true; do
# This is for the numbering of the menu choices. It is
# updated once before each entry printout in the menu
# except exit which should always be 0. The variable must
# be reset within this while loop or bad things will happen.
(( bb_m_c = 0 ))
# <colors>
#source "$BBROOTDIR"/misc/colors.idx
# </colors>   
clear
# <table>
echo -e "${BBTABLECOLOR}${BBDECOLINE}"
echo -e "${BBTABLECOLOR}|${BBHEADCOLOR} ${BBVERSION} ${BBTABLECOLOR}|"
echo -e "${BBTABLECOLOR}${BBDECOLINE}"
echo -e "${BBTABLECOLOR}|"
echo -e "${BBTABLECOLOR}|-(${BBSUBCOLOR}$bb_am_menu_title${BBTABLECOLOR})"
(( bb_m_c += 1 ))
echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_am_menu_1"
(( bb_m_c += 1 ))
echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_am_menu_2"
(( bb_m_c += 1 ))
echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_am_menu_3"
(( bb_m_c += 1 ))
echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_am_menu_4"
(( bb_m_c += 1 ))
echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_am_menu_5"
(( bb_m_c += 1 ))
echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_am_menu_6"
(( bb_m_c += 1 ))
echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_am_menu_7"
(( bb_m_c += 1 ))
echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_am_menu_8"
(( bb_m_c += 1 ))
echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_am_menu_9"
(( bb_m_c += 1 ))
echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_am_menu_10"
(( bb_m_c += 1 ))
echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_am_menu_11"
echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} 0) $bb_am_menu_0"
echo -e "${BBTABLECOLOR}|"
echo -n -e "${BBINPUTCOLOR}$bb_am_menu_input[0-$bb_m_c] |>${BBMAINCOLOR} "        
read action
echo -e "${BBCOLOROFF}"
# </table>

case $action in
	1)  # Burn Audio from Mp3s
		check_for_mp3s                  
		check_for_oggs			
		check_for_flacs			
		${BBROOTDIR}/burning/burning.sh --audio
		;;
	2) # Burn Audio Directly
		${BBROOTDIR}/burning/burning.sh --pipeline
		;;
	3)	
		copy_audio_cd
		;;
	4)      
		copy_cd_to_hd
		;;
	5)	# Burn a xmms playlist
		if eval ${BBROOTDIR}/misc/xmmsread.sh; then
			${BBROOTDIR}/burning/burning.sh --audio
		else
			echo $bb_am_ch5
			wait_for_enter
		fi
		;;
	6)
		create_mp3s_from_wavs
		;;	
	7)
		create_oggs_from_wavs
		;;
	8)
		create_flacs_from_wavs
		;;
	9)
		create_mp3s_from_cd
		;;
	10)
		create_oggs_from_cd
		;;
	11)
		create_flacs_from_cd
		;;
	0)      # Abort
		break
		;;
	*)
		echo "$bb_am_error[0-$bb_m_c]"
		wait_for_enter
		continue                                #Else go to menu
		;;
esac
done

