#bash

# GRABATOR
# Written by Jose L. Diaz. (grabatorscript@yahoo.com)
# March/2001
# Homepage: hhtp://www.geocities.com/grabatorscript
# This software comes with NO warranty of any kind. Use at your own risk.
# Report bugs or suggestions to: perguisa@netscape.net
#=======================================================




#******************************************************************************
# FUNCTIONS
#******************************************************************************


#******************************************************************************

GetMP3fromCD () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Get MP3 files from Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo -n "Do you wish create a new directory to stored the MP3 files? y/n: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		CreateDirectory;
	else
		GoToDir;
	fi
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	GetOriginalCD;
	while true;
	do
		echo "" ;
		echo "" ;
		echo "Enter the MP3 Kb/Seg quality :" ;
		echo "" ;
		echo "   1. 128 Kb/Seg, 44.1 KHz, 16 Bits, Stereo" ;
		echo "   2. 320 Kb/Seg, 44.1 KHz, 16 Bits, Stereo" ;
		echo "" ;
		echo -n "Value: " ;
		read value;
		echo "" ;
		if [ "$value" != "1" ] && [ "$value" != "2" ]
		then
			echo "Error. Incorrect value.";
		else
			break;
		fi
	done
	echo "" ;
	echo "" ;
	echo "Enter audio extraction type:" ;
	echo " " ;
	echo "	1. Maximum quality -Slow extraction-" ;
	echo "	2. Good quality, no errors -Quick extraction-" ;
	echo "	3. Regular quality, possible errors -Very quick extraction-" ;
	echo " " ;
	echo -n "Type: " ;
	read type;
	echo " " ;
	echo " " ;
	echo "Enter tracks to extract from audio CD:" ;
	echo " " ;
	echo " " ;
	echo "	Examples of audio tracks extracting:" ;
	echo " " ;
	echo "	1-   All CD tracks";
	echo "	2    Extract only track 2";
	echo "	-2   Extract from track 1 to 2";
	echo "	2-   Extract from track 2 to the last track of the CD";
	echo "	2-7  Extract tracks 2 to 7";
	echo "	1:[20.35]   Extract from second 20, sector 35 of track 1 to the end of track 1";
	echo "	1:[20.35]-  Extract from second 20, sector 35 of track 1 to the last track od CD";
	echo "" ;
	echo "" ;
	echo -n "Tracks (1-  All CD tracks): " ;
	read tracks;
	if [ "$tracks" = "1-" ]
	then
		echo "" ;
		cdparanoia -Q;
		echo " " ;
		echo " " ;
		echo -n "Enter the number of tracks contained in the CD: " ;
		read numtracks;
		echo " " ;
		echo " " ;
		track=1;
		while [ "$track" -le "$numtracks" ];
		do
			case $type in
			1) cdparanoia -z -B "$track";;
			2) cdparanoia -z -Y -B "$track";;
			3) cdparanoia -Z -B "$track";;
			esac;
			track=`expr ${track} + 1`;
			WAV2MP3Conversion $value *.wav;
		done
	else
		echo " " ;
		echo " " ;
		case $type in
			1) cdparanoia -z -B "$tracks";;
			2) cdparanoia -z -Y -B "$tracks";;
			3) cdparanoia -Y -B "$tracks";;
		esac;
		WAV2MP3Conversion $value *.wav;
	fi
	Beep;
	GetSizeInMB;
	PressAnyKey;
	return ;
}



#******************************************************************************
GetWAVfromCD () {
	clear;	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Get WAV files from Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo " " ;
	echo " " ;
	echo "Enter tracks to extract from audio CD:" ;
	echo " " ;
	echo " " ;
	echo "	Examples of audio tracks extracting:" ;
	echo " " ;
	echo "	1-   All CD tracks";
	echo "	2    Extract only track 2";
	echo "	-2   Extract from track 1 to 2";
	echo "	2-   Extract from track 2 to the last track of the CD";
	echo "	2-7  Extract tracks 2 to 7";
	echo "	1:[20.35]   Extract from second 20, sector 35 of track 1 to the end of track 1";
	echo "	1:[20.35]-  Extract from second 20, sector 35 of track 1 to the last track od CD";
	echo "" ;
	echo "" ;
	echo -n "Tracks (1-  All CD tracks): " ;
	read tracks;
	if [ "$tracks" = "1-" ]
	then
		GetWavTrackByTrack;
	else
		echo " " ;
		echo " " ;
		echo "Enter audio extraction type:" ;
		echo " " ;
		echo "	1. Maximum quality -Slow extraction-" ;
		echo "	2. Good quality, no errors -Quick extraction-" ;
		echo "	3. Regular quality, possible errors -Very quick extraction-" ;
		echo " " ;
		echo -n "Type: " ;
		read type;
		case $type in
			1) cdparanoia -z -B "$tracks";;
			2) cdparanoia -z -Y -B "$tracks";;
			3) cdparanoia -Y -B "$tracks";;
		esac;
	fi
	GetSizeInMB;
	PressAnyKey;
	return ;
}


#******************************************************************************

AudioRecord () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "Record audio in WAV format" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo " " ;
		echo " " ;
		echo "Recording in WAV format, Stereo, 16 bits & 44.100 Hz." ;
		echo " " ;
		echo " " ;
		echo -n "Recording title [0 Exit]: " ;
		read file
		if [ "$file" = "0" ]
		then
			return;
		fi
		if [ ! -d $HOME/grabator/$file ]
		then
			mkdir --verbose $HOME/grabator/$file ;
			cd $HOME/grabator/$file;
			break ;
		else
			echo " " ;
			Beep;
			echo "WARNING: The file already exist. Enter a diferent name.";
			PressAnyKey;
		fi
	done	
	echo " " ;
	echo " " ;
	echo "Press any key to start the recording." ;
	read;
	clear;
	echo " " ;
	echo "*******************************************************************";
	echo "**** WARNING:                                                  ****";
	echo "****        The rate in Hz to CD copy is 44.100 Hz.            ****";
	echo "****        It's possible you must to convert to this rate     ****";
	echo "****        before the copy.  Menu Opcin n 10                ****";
	echo "****        Play the WAV file to check it.                     ****";
	echo "*******************************************************************";
	echo " " ;
	echo "Enter CTRL+C to stop the recording." ;
	echo "RECORDING...";
	echo " " ;
	sox -V -r 44100 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44100 -c 2 -w -s $file.wav;
	echo -n "The recording is found in: " ;
	echo $HOME/grabator/$file ;
	GetSizeInMB;
	PressAnyKey;
	return;
}

#******************************************************************************

DataDirectCopy () {
	cd $HOME/grabator/cddata;
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	#copia real (no dummy)
	then
		echo "Data-CD direct copy to CD-R: Get data image and copy";
	else
		echo "Data-CD direct dummy copy to CD-R: Get data image and copy";
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "Insert the source and target CDs.";
	echo "WARNING: Mount the source Data CD!";
	Beep;
	PressAnyKey;
	echo "Cleaning temporary directories...";
	rm -f $HOME/grabator/cddata/*;
	echo " " ;
	echo " " ;
	echo "****************************************************************" ;
	echo "MULTISESSION does not close recordable CD and allows copy" ;
	echo "    of data to recordable CD on several ocasions." ;
	echo " " ;
	echo "    To close the whole recordable CD, you must carry out the";
	echo "    last data-copy session with NO multisession option" ;
	echo "****************************************************************" ;
	echo "    " ;
	echo " " ;
	echo -n "Do you wish to select MULTISESSION option? y/n: " ;
	read multi;
	echo "";
	echo "";
	echo "The copy must be performed under ROOT. Enter the password." ;
	if [ "$multi" = "y" ]
	then
		if [ "${1}" = "1" ]	# real copy
		then
			su -c 'mkisofs -J -o imagen.cd /mnt/cdrom ; cdrecord -v -multi -msinfo imagen.cd';
		else	# mode dummy
			su -c 'mkisofs -J -o imagen.cd /mnt/cdrom ; cdrecord -v -dummy -multi -msinfo imagen.cd';
		fi			
	else
		if [ "${1}" = "1" ]	# copia real
		then
			su -c 'mkisofs -J -o imagen.cd /mnt/cdrom ; cdrecord -v imagen.cd' ;
		else	# mode dummy
			su -c 'mkisofs -J -o imagen.cd /mnt/cdrom ; cdrecord -v -dummy imagen.cd' ;
		fi			
	fi
	echo "";
	echo "";
	echo "Cleaning temporary directories...";
	rm -f $HOME/grabator/cddata/*;
	PressAnyKey;
	return ;
}




#******************************************************************************

OntheflyDataCopy () {
#arguments: 1:  real copy, rest: dummy copy
	cd $HOME/grabator/cddata;
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "On-the-fly Data-CD copy to CD-R";
	else
		echo "On-the-fly Data-CD dummy copy to CD-R";
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "****************************************************************************";
	echo "CAUTION:";
	echo "" ;
	echo "Risk of buffer underrun on On-the-fly data copy!";
	echo "" ;
	echo "First, do a dummy copy to check the buffer size is OK.";
	echo "If the current buffer size is not enough, increase the";
	echo "'CDR_FIFOSIZE' field in /etc/cdrecord.conf file.";
	echo "Also you can low the copy speed." ;
	echo "****************************************************************************";
	Beep;
	echo "" ;
	echo "" ;
	echo "Insert the source and target CDs.";
	echo "WARNING: Mount the source Data CD!";
	Beep;
	if [ "${1}" = "1" ]	#copia real (no dummy)
	then
		echo "" ;
		echo "" ;
		echo -n "Do you wish to perform On-the-fly data copy? y/n: " ;
		read opc;
		if [ "$opc" = "y" ]
		then
			CopyCD 8;
		fi
	else	# copia modo dummy
		CopyCD 9
	fi		
	PressAnyKey;
	return ;
}



#******************************************************************************

Image2cd () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "Copy data image to CD-R";
	else
		echo "Dummy copy data image to CD-R";
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo " " ;
	echo "****************************************************************" ;
	echo "MULTISESSION does not close recordable CD and allows copy" ;
	echo "    of data to recordable CD on several ocasions." ;
	echo " " ;
	echo "    To close the whole recordable CD, you must carry out the";
	echo "    last data-copy session with NO multisession option" ;
	echo "****************************************************************" ;
	echo "    " ;
	echo " " ;
	echo -n "Do you wish to select MULTISESSION option? y/n: ";
	read multi;
	GetCDRecordable;
	if [ "$multi" = "y" ]
	then
		if [ "${1}" = "1" ]
		then
			CopyCD 3; # multisesion copy
		else
			CopyCD 7; # multisession dummy copy
		fi		
	else
		if [ "${1}" = "1" ]
		then
			CopyCD 2; # copy
		else
			CopyCD 6; # dummy copy
		fi		
	fi
	PressAnyKey;
	return ;
}

#******************************************************************************

GetImage () {
	cd $HOME/grabator/cddata;
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Get data image" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	DirOrg=`pwd`;
	DirDest=`pwd`;
	echo " " ;
	echo " " ;
	echo -n "Create directory for image file? y/n: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		CreateDirectory;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		DirDest=`pwd`;
	fi
	echo " " ;
	echo " " ;
	echo "Creating image file..." ;
	echo " " ;
	cd $DirDest;
	mkisofs -r -J -o image.raw $DirOrg ;
	GetSizeInMB;
	echo -n "Data image file is found in: ";
	pwd;
	PressAnyKey;
	return ;
}


#******************************************************************************

MP3toCD () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "MP3 files to CD-R copy" ;
	else
		echo "MP3 files to CD-R DUMMY copy" ;
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	CleanAudioTempDir;
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		if [ "${1}" = "1" ]	# real copy (no dummy)
		then
			echo "MP3 files to CD-R copy" ;
		else
			echo "MP3 files to CD-R DUMMY copy" ;
		fi	
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo " " ;
		echo " " ;
		echo -n "Selection of MP3/MPEG directory files: " ;
		pwd;
		echo " " ;
		echo " " ;
		ls -C --color *.mp3;
		echo " " ;
		echo " " ;
		echo -n "Select the file [* All, f Finish selection, 0 Exit]: " ;
		read archvmp3;
		echo " " ;
		echo " " ;
		if [ "$archvmp3" = "f" ]
		then
			break;
		fi
		if [ "$archvmp3" = "0" ]
		then
			return;
		fi
		if [ "$archvmp3" = "*" ]
		then
			for archv in *.mp3;
			do
				mpg123 -s -r 44100 $archv > $HOME/grabator/cdaudio/$archv.raw ;
				sox -t raw -r 44100 -c 2 -w -s $HOME/grabator/cdaudio/$archv.raw  -r 44100 -c 2 -t wav -w -s $HOME/grabator/cdaudio/$archv.wav ;
				rm -f $HOME/grabator/cdaudio/$archv.raw ;
			done ;
			GetSizeInMB;
			break;
		else
			if [ -f $HOME/grabator/cdaudio/$archvmp3.wav ]
			then
				Beep;
				echo -n "WARNING: ";
				echo -n $archvmp3;
				echo " was converted before.";
				PressAnyKey;
			else
				if [ ! -f $archvmp3 ]
				then
					Beep;
					echo "ERROR: File not found.";
					PressAnyKey;
				else
					mpg123 -s -r 44100 $archvmp3 > $HOME/grabator/cdaudio/$archvmp3.raw ;
		  		  sox -t raw -r 44100 -c 2 -w -s $HOME/grabator/cdaudio/$archvmp3.raw  -r 44100 -c 2 -t wav -w -s $HOME/grabator/cdaudio/$archvmp3.wav;
					rm -f $HOME/grabator/cdaudio/$archvmp3.raw ;
					GetSizeInMB;
					PressAnyKey;
				fi
			fi
		fi
	done
	echo " " ;
	echo "WARNING:" ;
	echo "	74 minutes audio CD capacity (aprox.): 650 Mb." ;
	echo "	80 minutes audio CD capacity (aprox.): 700 Mb." ;
	GetCDRecordable;
	cd $HOME/grabator/cdaudio ;
	CopyCD ${1};
	PressAnyKey;
	CleanAudioTempDir;
	return;
}

#******************************************************************************

AudioCopy () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "WAV files to CD-R copy" ;
	else
		echo "WAV files to CD-R DUMMY copy" ;
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	GetCDRecordable;
	CopyCD ${1};
	PressAnyKey;
	return 0;
}

#******************************************************************************

AudioDirectCopy () {
	cd $HOME/grabator/cdaudio
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Direct Audio CD copy to CD-R" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	GetOriginalCD;
	GetCDRecordable;
	CleanAudioTempDir;
	CopyCD 5;
	PressAnyKey;
	CleanAudioTempDir;
	return;
}


#******************************************************************************

CreateDirByDefault () {
# go to GRABATOR directory and if it is not found, create it
	if [ ! -d $HOME/grabator ]
	then
		mkdir $HOME/grabator;
	fi

	if [ ! -d $HOME/grabator/cdaudio ]
	then
		mkdir $HOME/grabator/cdaudio;
	fi

	if [ ! -d $HOME/grabator/cddata ]
	then
		mkdir $HOME/grabator/cddata;
	fi
}

#******************************************************************************

GetDirWavTracks () {
# show the existing directories
	echo "" ;
	echo "" ;
	echo "GRABATOR directories:" ;
	echo "______________________________________________________________________" ;
	ls -C --color $HOME/grabator ;
	echo "______________________________________________________________________" ;
	echo "" ;
	echo "Enter directory name already exist or new" ;
	echo -n "where the audio files will be stored [0 Exit]: "
	read nomdir ;
	if [ "$nomdir" = "0" ]
	then
		return 1;
	fi
	if [ ! -d $HOME/grabator/$nomdir ]
	then
		mkdir --verbose $HOME/grabator/$nomdir ;
	else
		echo " " ;
		Beep;
		echo "WARNING: The directory already exist and may contain files.";
		PressAnyKey;
	fi
	cd $HOME/grabator/$nomdir;
}

#******************************************************************************

GetWavTrackByTrack () {
# extract tracks running cdparanoia once per track. A better quality is obtained
	clear;
	cdparanoia -Q;
	echo " " ;
	echo " " ;
	echo -n "Enter the number of tracks contained in the CD: " ;
	read numtracks;
	echo " " ;
	echo " " ;
	echo "Enter audio extraction type:" ;
	echo " " ;
	echo "	1. Maximum quality -Slow extraction-" ;
	echo "	2. Good quality, no errors -Quick extraction-" ;
	echo "	3. Regular quality, possible errors -Very quick extraction-" ;
	echo " " ;
	echo -n "Type: " ;
	read type;
	echo " " ;
	echo " " ;
	echo -n "Extracting CD tracks... ";
	echo " " ;
	echo " " ;
	track=1;
	while [ "$track" -le "$numtracks" ];
	do
		case $type in
			1) cdparanoia -z -B "$track";;
			2) cdparanoia -z -Y -B "$track";;
			3) cdparanoia -Z -B "$track";;
		esac;
		track=`expr ${track} + 1`;
	done
	Beep;
}

#******************************************************************************

GetSizeInMB () {
	echo " " ;
	echo " " ;
	echo -n "Total size [MB]: "
	pwd | du -h
}

#******************************************************************************

PressAnyKey () {
	Beep ;
	echo "Press any key to continue." ;
	read ;
	return ;
}

#******************************************************************************

GoToDir () {
	while true;
	do
		echo " " ;
		echo " " ;
		echo "GRABATOR directories:" ;
		echo "______________________________________________________________________" ;
		ls -C --color $HOME/grabator ;
		echo "______________________________________________________________________" ;
		echo " " ;
		echo -n "Enter the directory where the files are [0 Exit]: " ;
		read nomdir;
		if [ "$nomdir" != "0" ] && [  "$nomdir" != "" ]
		then
			if [ -d $HOME/grabator/$nomdir ]
			then
				cd $HOME/grabator/$nomdir ;
				break;
			else
				if [ -d $nomdir ]
				then
					cd $nomdir ;
					break;
				else
					echo " " ;
					echo " " ;
					Beep;
					echo "ERROR: The directory is not found.";
					echo "       Write the complete path. E.g.: /usr/users1/audio";
					PressAnyKey;
					clear;
				fi
			fi
		else
			return 1
		fi
	done
	echo "";
	echo "Directory files:";
	echo "";
	ls -C --color *;
	GetSizeInMB;
	return 0;
}

#******************************************************************************

GetCDRecordable () {
	echo " " ;
	echo " " ;
	echo "Insert CD-R Recordable." ;
	echo "Press any key to continue." ;
	read ;
}
#******************************************************************************

GetOriginalCD() {
	echo " " ;
	echo " " ;
	echo "Insert Audio or Data CD." ;
	echo "Press any key to continue." ;
	read ;
}

#******************************************************************************

CopyCD () {
	echo " " ;
	echo " " ;
	echo "The copy must be performed under ROOT. Enter the password." ;
	case ${1} in
		1) su -c grabator-AudioCopy ;;   # audio copy
		2) su -c 'cdrecord -v -eject image.raw' ;;     # data copy
		3) su -c 'cdrecord -v -multi -eject image.raw' ;;  # multisession copy data
		4) su -c grabator-AudioCopydummy ;;	# dummy audio copy
		5) su -c grabator-AudioDirectCopy ;;
		6) su -c 'cdrecord -v -dummy -eject image.raw' ;;     # dummy audio copy
		7) su -c 'cdrecord -v -dummy -multi -eject image.raw' ;;  # dummy multisession copy data
		8) su -c 'mkisofs -J /mnt/cdrom | cdrecord -v -';;  # onthefly copy
		9) su -c 'mkisofs -J /mnt/cdrom | cdrecord -v -dummy -';;   # onthefly dummy copy
		10) su -c 'cdrecord -v -dao -eject -shorttrack -pad image.raw -audio *.wav';;  # audio + data copy
		11) su -c 'cdrecord -v -dummy -dao -eject -shorttrack -pad image.raw -audio *.wav';; # audio + data  dummy copy
	esac;
}


#******************************************************************************

CleanAudioTempDir () {
	echo " " ;
	echo "Cleaning GRABATOR temporary directories..." ;
	rm -f $HOME/grabator/cdaudio/* ;
}

#******************************************************************************

CleanDataTempDir () {
	echo " " ;
	echo "Cleaning GRABATOR temporary directories..." ;
	rm -f $HOME/grabator/cddata/* ;
}

#******************************************************************************

CreateDirectory () {
	while true;
	do
		echo " " ;
		echo " " ;
		echo "Directory creation:" ;
		echo "Enter directory name" ;
		echo -n "where the files will be stored [0 Exit]: "
		read nomdir ;
		if [ "$nomdir" = "0" ]
		then
			return 1;
		fi
		if [ ! -d $HOME/grabator/$nomdir ]
		then
			echo "" ;
			mkdir --verbose $HOME/grabator/$nomdir ;
			cd $HOME/grabator/$nomdir;
			break ;
		else
			echo " " ;
			Beep;
			echo "WARNING: The directory already exist. Enter a diferent name.";
			PressAnyKey;
		fi
	done
}

#******************************************************************************

Beep () { echo -e "\a"; }    # a beep sound

#******************************************************************************

WAV2MP3Conversion () {
# MP3 creation with error check.
# After te conversion the original WAV files are deleted
# arguments:
#	1. MP3 quality -Kb/seg-
#	2. the file to convert
	echo "MP3 conversion..." ;
	echo "" ;
	case ${1} in
		1) bladeenc -del -br 128 -crc ${2};;
		2) bladeenc -del -br 320 -crc ${2};;
	esac;
	echo " " ;
	echo "MP3 conversion finished. " ;
}


#******************************************************************************

DelAll () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Delete ALL GRABATOR directories" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "GRABATOR directories:" ;
	echo "______________________________________________________________________" ;
	ls -C --color $HOME/grabator ;
	echo "______________________________________________________________________" ;
	echo "";
	echo "WARNING: GRABATOR audio and data files will be lost!.";
	echo "";
	echo -n "Are you sure? y/n: ";
	read opc;
	echo "";
	if [ "$opc" = "y" ]
	then
		rm -rvf $HOME/grabator/*
		# creating GRABATOR standard temporary files
		mkdir $HOME/grabator/cdaudio;
		mkdir $HOME/grabator/cddata;
		PressAnyKey;
	fi
	return;
}

#******************************************************************************

GetWAVfromSeveralCD () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Get WAV files from several Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo "" ;
	echo "" ;
	echo "Insert Audio CD";
	echo -n "and enter the CD track number [0 Exit]: ";
	read track;
	if [ "$track" = "0" ]
	then
		break;
	fi
	while true ;
	do
		echo " " ;
		echo -n "Enter a title for the CD track: ";
		read nametrack;
		echo " " ;
		echo "Extracting CD track to audio CD quality..." ;
		echo " " ;
		cdparanoia -z -B "$track" $nametrack.wav;
		clear ;
		Beep;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "Get WAV files from several Audio-CD" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo " " ;
		echo " " ;
		echo "Insert new Audio CD";
		echo -n "and enter the CD track number [0 Exit]: ";
		read track;
		if [ "$track" = "0" ]
		then
			break;
		fi
	done
	Beep;
	echo "WAV conversion finished. " ;
	echo -n "WAV files from Audio-CD are found in: " ;
	pwd;
	return ;
}

#******************************************************************************

GetMP3fromSeveralCD () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Get MP3 files from several Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo "" ;
	echo "" ;
	echo "Insert Audio CD";
	echo -n "and enter the CD track number [0 Exit]: ";
	read track;
	if [ "$track" = "0" ]
	then
		break;
	fi
	while true ;
	do
		echo " " ;
		echo -n "Enter a title for the CD track: ";
		read nametrack;
		echo " " ;
		echo "Extracting CD track..." ;
		echo " " ;
		cdparanoia -z -B "$track" $nametrack.wav;
		mv track*.$nametrack.wav $nametrack.wav;
		Beep;
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "Get MP3 files from several Audio-CD" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo " " ;
		echo " " ;
		echo "Insert new Audio CD";
		echo -n "and enter the CD track number [0 Exit]: ";
		read track;
		if [ "$track" = "0" ]
		then
			break;
		fi
	done
	Beep;
	echo "Tracks selection finished by the user." ;
	while true;
	do
		echo "" ;
		echo "" ;
		echo "Enter the MP3 Kb/Seg quality :" ;
		echo "" ;
		echo "   1. 128 Kb/Seg, 44.1 KHz, 16 Bits, Stereo" ;
		echo "   2. 320 Kb/Seg, 44.1 KHz, 16 Bits, Stereo" ;
		echo "" ;
		echo -n "Value: " ;
		read value;
		echo "" ;
		if [ "$value" != "1" ] && [ "$value" != "2" ]
		then
			echo "Error. Incorrect value.";
		else
			break;
		fi
	done
	echo "MP3 conversion..." ;
	echo "";
	WAV2MP3Conversion $value "*.wav";
	echo " " ;
	Beep;
	echo "MP3 conversion finished. " ;
	echo -n "MP3 files from Audio-CD are found in: " ;
	pwd;
	read;
	return ;
}

#******************************************************************************

DelDir () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Delete a GRABATOR directory" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo "";
	echo "WARNING: Audio or data files will be lost!.";
	echo "";
	echo -n "Are you sure? y/n: ";
	read opc;
	echo "";
	if [ "$opc" = "y" ]
	then
		rm -rvf `pwd` ;
		# creating GRABATOR standard temporary files
		if [ ! -d $HOME/grabator/cdaudio ]
		then
			mkdir $HOME/grabator/cdaudio;
		fi

		if [ ! -d $HOME/grabator/cddata ]
		then
			mkdir $HOME/grabator/cddata;
		fi
		Beep;
		PressAnyKey;
	fi
	return;
}


#******************************************************************************

DelTemp () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Delete files of GRABATOR temporary directories [AUDIOCD & DATACD]" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "WARNING: GRABATOR temporary audio and data files will be lost!.";
	echo "";
	echo -n "Are you sure? y/n: ";
	read opc;
	echo "";
	if [ "$opc" = "y" ]
	then
		rm -fv $HOME/grabator/cdaudio/*
		echo "";
		echo "";
		echo "";
		rm -fv $HOME/grabator/cddata/*
		PressAnyKey;
	fi
	return;
}

#******************************************************************************

PlayWAV () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "Play WAV files [WAV, 44.100 Hz, 16 bits, Stereo]" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		echo " " ;
		echo " " ;
		echo -n "Select file to play [* All, 0 Exit]: " ;
		read archv;
		if [ "$archv" = "0" ]
		then
			return;
		fi
		if [ "$archv" = "*" ]
		then
			for archv in *.wav;
			do
				clear;
				echo "Play WAV files" ;
				echo "_____________________________________" ;
				echo " " ;
				echo " " ;
				echo " " ;
				echo -n "You are listening: ";
				echo $archv;
				echo " " ;
				echo " " ;
				echo " " ;
				echo " " ;
				sox -t wav -r 44100 -c 2 -w -s $archv  -r 44100 -c 2 -t ossdsp -w -s /dev/dsp ;
			done ;
			break;
		fi
		echo " " ;
		if [ -f $archv ]
		then
			echo -n "You are listening: ";
			echo $archv;
			echo " " ;
			sox -t wav -r 44100 -c 2 -w -s $archv  -r 44100 -c 2 -t ossdsp -w -s /dev/dsp;
		else
			Beep;
			echo "ERROR: File not found.";
			PressAnyKey;
		fi
		echo " " ;
		echo " " ;
		echo -n "Play new file? y/n: " ;
		read opc;
		if [ "$opc" != "y" ]
		then
			break;
		fi		
	done
	return;
}	

#******************************************************************************

PlayMP3 () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "Play MP3/MPEG files" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		echo " " ;
		echo " " ;
		echo -n "Select the file to play [* All, 0 Exit]: " ;
		read archv;
		if [ "$archv" = "0" ]
		then
			return;
		fi
		if [ "$archv" = "*" ]
		then
			for archv in *.mp3;
			do
				clear;
				echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
				echo "Play MP3/MPEG files" ;
				echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
				echo " " ;
				echo " " ;
				echo " " ;
				echo -n "You are listening: ";
				echo $archv;
				echo " " ;
				echo " " ;
				echo " " ;
				echo " " ;
				mpg123 $archv;
			done ;
			break;
		fi
		echo " " ;
		if [ -f $archv ]
		then
			echo -n "You are listening: ";
			echo $archv;
			echo " " ;
			mpg123 $archv;
		else
			Beep;
			echo "ERROR: File not found.";
			PressAnyKey;
		fi
		echo " " ;
		echo " " ;
		echo -n "Play new file? y/n: " ;
		read opc;
		if [ "$opc" != "y" ]
		then
			break;
		fi		
	done
	return;
}	

#******************************************************************************

WAVtoMP3 () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "Convert WAV files to MP3 format" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		echo " " ;
		echo " " ;
		echo -n "Select the file [* All, 0 Exit]: " ;
		read archvwav;
		if [ "$archvwav" = "0" ]
		then
			return;
		fi
		while true;
		do
			echo "" ;
			echo "" ;
			echo "Enter the MP3 Kb/Seg quality :" ;
			echo "" ;
			echo "   1. 128 Kb/Seg, 44.1 KHz, 16 Bits, Stereo" ;
			echo "   2. 320 Kb/Seg, 44.1 KHz, 16 Bits, Stereo" ;
			echo "" ;
			echo -n "Value: " ;
			read value;
			echo "" ;
			if [ "$value" != "1" ] && [ "$value" != "2" ] 
			then
				echo "Error. Incorrect value.";
			else
				break;
			fi
		done
		echo " " ;
		echo " " ;
		if [ "$archvwav" = "*" ]
		then
			WAV2MP3Conversion $value "*.wav";
			break;
		else
			if [ -f $archvwav.mp3 ]
			then
				Beep;
				echo -n "WARNING: ";
				echo -n $archvwav;
				echo "  was converted before.";
				PressAnyKey;
			else
				if [ ! -f $archvwav ]
				then
					Beep;
					echo "ERROR: File not found.";
					PressAnyKey;
				else
					WAV2MP3Conversion $value $archvwav;
					break;
				fi
			fi
		fi
	done
	echo " " ;
	echo " " ;
	echo -n "The MP3 files are found in: " ;
	echo $nomdir;
	PressAnyKey;
	return;
}


#******************************************************************************

MP3toWAV () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "Convert MP3/MPEG files to WAV format" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		echo " " ;
		echo " " ;
		echo -n "Select the file [* All, 0 Exit]: " ;
		read archvmp3;
		echo " " ;
		echo " " ;
		if [ "$archvmp3" = "0" ]
		then
			return;
		fi
		if [ "$archvmp3" = "*" ]
		then
			for archv in *.mp3;
			do
				mpg123 -s -r 44100 $archv > $archv.raw ;
				sox -t raw -r 44100 -c 2 -w -s $archv.raw  -r 44100 -c 2 -t wav -w -s $archv.wav ;
				rm -f $archv.raw ;
			done ;
			break;
		else
			if [ -f $archvmp3.wav ]
			then
				Beep;
				echo -n "WARNING: ";
				echo -n $archvmp3;
				echo " was converted before.";
				PressAnyKey;
			else
				if [ ! -f $archvmp3 ]
				then
					Beep;
					echo "ERROR: File not found.";
					PressAnyKey;
				else
					mpg123 -s -r 44100 $archvmp3 > $archvmp3.raw ;
					sox -t raw -r 44100 -c 2 -w -s $archvmp3.raw  -r 44100 -c 2 -t wav -w -s $archvmp3.wav ;
					rm -f $archvmp3.raw ;
					break;
				fi
			fi
		fi
	done
	echo " " ;
	echo " " ;
	echo -n "The WAV files are found in: " ;
	echo $nomdir;
	PressAnyKey;
	return;
}

#******************************************************************************

RateTo44100HZ () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Convert no 44.100 Hz sample rate to 44.100 Hz in WAV files" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "WARNING: In big files this action is going to take a long time." ;
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo " " ;
	echo " " ;
	Beep;
	echo -n "Select the file [0 Exit]: " ;
	read archv;
	echo " " ;
	echo -n "Enter the original rate of the WAV file: " ;
	read rate;
	if [ "$archv" = "0" ]
	then
		return;
	fi
	echo "" ;
	echo "" ;
	echo "Press any key to convert." ;
	read;
	echo "" ;
	echo "" ;
	echo -n "Converting the file: " ;
	echo $archv.44100hz.wav
	echo "" ;
	sox -V -t wav -r $rate -c 2 -w -s $archv  -r 44100 -c 2 -t wav -w -s $archv.44100hz.wav;
	Beep;
	echo "";
	echo -n "The file is found in: " ;
	pwd;
	GetSizeInMB;
	echo "";
	echo "";
	echo "";
	echo -n "Do you wish to delete the original file [no 44.100 Hz rate]? y/n: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		echo "";
		rm -fv $archv;
	fi
	PressAnyKey;
	return ;
}

#******************************************************************************

Scanbus () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "View SCSI devices for CDRECORD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo "The operation must be performed under ROOT. Enter the password.";
	su -c 'cdrecord -scanbus' root;
	PressAnyKey;
	return;
}

#******************************************************************************

ViewAllDir () {
	cd $HOME/grabator;
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "View contents of all GRABATOR directories" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo "Press 'q' to stop." ;
	echo "" ;
	echo "____________________________________________________________________________" ;
	pwd;
	echo "" ;
	ls -Rhl|more;
	PressAnyKey;
	return ;
}

#******************************************************************************

FreeSizeHD () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "View free space in Hard Disks" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo "Free space:" ;
	echo " " ;
	df -hT;
	PressAnyKey;
	return ;
}

#******************************************************************************

InfoAudioCd () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "View Audio-CD information" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	GetOriginalCD;
	cdparanoia -Q;
	PressAnyKey;
	return ;
}

#******************************************************************************

ViewSizeDir () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "View size of a directory [in MB]" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo "WAV size <===> audio time relationship: " ;
	echo "" ;
	echo "	8.75 MB  <===>  1 Minute" ;
	echo "	650 MB   <===>  74 Minutes" ;
	echo "	700 MB   <===>  80 Minutes" ;
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	PressAnyKey;
	return ;
}

#******************************************************************************

AudioDataCD () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "Audio+Data CD copy" ;
	else
		echo "Audio+Data CD DUMMY copy" ;
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	if [ ! -f image.raw ]
	then
		Beep;
		echo "";
		echo "";
		echo "WARNING: Data image file (image.raw) not found!";
		echo "         Create it before! (see main menu, option 2)";
	else
		GetCDRecordable;
		if [ "${1}" = "1" ]	# real copy (no dummy)
		then
			CopyCD 10;
		else
			CopyCD 11;
		fi	
	fi
	PressAnyKey;
	return;
}

AboutGrabator () {
clear;
echo "\
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
About GRABATOR
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Version 0.9
Written by Jose L. Diaz.
March/2001

Homepage: hhtp://www.geocities.com/grabatorscript

This is free software.
Only, I would like to know how many countries of the world GRABATOR is being
used, for that reason would be thankful to you that you sent me a mail
(grabatorscript@yahoo.com) indicating your country, city and the date.
Thanks.

This software comes with NO warranty of any kind. Use at your own risk.

Report bugs or suggestions to: grabatorscript@yahoo.com";

PressAnyKey;
return;
}



#******************************************************************************
# MAIN MENU FUNCTIONS ---------------------------------
#******************************************************************************

menuaudiocd () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: GRABATOR :::::::::::::::::::::::::::::::::::::::::::::: Jose L. Diaz";
	echo "========================================================================";
	echo "";
	echo "::: AUDIO CD-R :::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "	1. Direct Audio CD copy to CD-R";
	echo "	2. WAV files to CD-R copy";
	echo "	3. MP3 files to CD-R copy";
	echo "	4. WAV files to CD-R DUMMY copy";
	echo "	5. MP3/MPEG files to CD-R DUMMY copy";
	echo "";
	echo "	0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		0) break;;
		1) AudioDirectCopy;;	# extraccion perfecta, copia a 1x
		2) AudioCopy 1;;
		3) MP3toCD 1;;
		4) AudioCopy 4;;	# simulacion
		5) MP3toCD 4;;	# simulacion
	esac;
done
}

#******************************************************************************

menudatacd () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: GRABATOR :::::::::::::::::::::::::::::::::::::::::::::: Jose L. Diaz";
	echo "========================================================================";
	echo "";
	echo "::: DATA CD-R ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "	1. Data-CD direct copy to CD-R: Get data image and copy";
	echo "	2. Data-CD direct dummy copy to CD-R: Get data image and copy";
	echo "	3. On-the-fly Data-CD copy to CD-R";
	echo "	4. On-the-fly Data-CD dummy copy to CD-R";
	echo "	5. Get data image";
	echo "	6. Copy data image to CD-R";
	echo "	7. Dummy copy data image to CD-R";
	echo "";
	echo "	0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		0) break;;
		1) DataDirectCopy 1;;
		2) DataDirectCopy 2;;  # dummy
		3) OntheflyDataCopy 1;;
		4) OntheflyDataCopy 2;;  # dummy
		5) GetImage;;
		6) Image2cd 1;;
		7) Image2cd 2;;  # dummy
	esac;
done
}

#******************************************************************************

menumixcd () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: GRABATOR :::::::::::::::::::::::::::::::::::::::::::::: Jose L. Diaz";
	echo "========================================================================";
	echo "";
	echo "::: AUDIO + DATA CD-R ::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "	1. Audio+Data CD copy";
	echo "	2. Audio+Data CD DUMMY copy";
	echo "";
	echo "	0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		0) break;;
		1) AudioDataCD 1;;
		2) AudioDataCD 2;;
	esac;
done
}

#******************************************************************************

menuaudio () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: GRABATOR :::::::::::::::::::::::::::::::::::::::::::::: Jose L. Diaz";
	echo "========================================================================";
	echo "";
	echo "::: AUDIO ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "	1. Get WAV files from Audio-CD";
	echo "	2. Get MP3 files from Audio-CD";
	echo "	3. Get WAV files from several Audio-CD";
	echo "	4. Get MP3 files from several Audio-CD";
	echo "	5. Record audio in WAV format";
	echo "	6. Play WAV files";
	echo "	7. Play MP3/MPEG files";
	echo "	8. Convert MP3/MPEG files to WAV format";
	echo "	9. Convert WAV files to MP3 format";
	echo "	10.Convert no 44.100 Hz sample rate to 44.100 Hz in WAV files";
	echo "";
	echo "	0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		0) break;;
		1) GetWAVfromCD;;
		2) GetMP3fromCD;;
		3) GetWAVfromSeveralCD;;
		4) GetMP3fromSeveralCD;;
		5) AudioRecord;;
		6) PlayWAV;;
		7) PlayMP3;;
		8) MP3toWAV;;
		9) WAVtoMP3;;
		10) RateTo44100HZ;;
	esac;
done
}

#******************************************************************************

menuothers () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: GRABATOR :::::::::::::::::::::::::::::::::::::::::::::: Jose L. Diaz";
	echo "========================================================================";
	echo "";
	echo "::: OTHERS :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "	1. View contents of all GRABATOR directories";
	echo "	2. View size of a directory in MB";
	echo "	3. View SCSI devices for CDRECORD";
	echo "	4. Delete a GRABATOR directory";
	echo "	5. Delete files of GRABATOR temporary directories [AUDIOCD & DATACD]";
	echo "	6. Delete ALL GRABATOR directories";
	echo "	7. View free space in Hard Disks";
	echo "	8. View Audio-CD information";
	echo "";
	echo "	0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		0) break;;
		1) ViewAllDir;;
		2) ViewSizeDir;;
		3) Scanbus;;
		4) DelDir;;
		5) DelTemp;;
		6) DelAll;;
		7) FreeSizeHD;;
		8) InfoAudioCd;;
	esac;
done
}


#******************************************************************************
# MAIN MENU ------------------------------
#******************************************************************************

CreateDirByDefault;
while true;
do
	clear;
	echo "=======================================================================";
	echo "::: GRABATOR :::::::::::::::::::::::::::::::::::::::::: By Jose L. Diaz";
	echo "=======================================================================";
	echo "    CD Creation & Sound                                    Version: 0.9";
	echo "";
	echo "";
	echo "";
	echo "	1. Audio CD-R";
	echo "	2. Data CD-R";
	echo "	3. Audio+Data CD-R";
	echo "	4. Audio";
	echo "	5. Others";
	echo "	6. About GRABATOR" ;
	echo "" ;
	echo "	0. Exit GRABATOR" ;
	echo "" ;
	echo "" ;
	echo -n "Choose option: ";
	read opc;
	case $opc in
		0) clear; exit 0;;
		1) menuaudiocd;;
		2) menudatacd;;
		3) menumixcd;;
		4) menuaudio;;
		5) menuothers;;
		6) AboutGrabator;;
	esac;
done