#bash

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




#******************************************************************************
# 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 -B "$track";;
			2) cdparanoia -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 -B "$tracks";;
			2) cdparanoia -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 -B "$tracks";;
			2) cdparanoia -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;
		export 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 -n "Do you like perform the recording under ROOT? [maximum priority] y/n: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		echo "Enter the ROOT password." ;
		su -c '
		echo " " ;
		echo "Press any key to start the recording." ;
		read;
		echo " " ;
		echo " " ;
		echo "Enter CTRL+C to finish the recording." ;
		echo "RECORDING WITH MAXIMUM PRIORITY [ROOT]...";
		echo " " ;
		sox -V -r 44100 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44100 -c 2 -w -s $file.wav';
	else
		echo " " ;
		echo "Press any key to start the recording." ;
		read;
		echo " " ;
		echo " " ;
		echo "Enter CTRL+C to finish 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;
	fi
	echo " " ;
	echo " " ;
	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;
	CleanDataTempDir;
	echo "";
	echo "Mounting the CD source...";
	mount /dev/cdrom /mnt/cdrom;
	echo "";
	echo "The copy must be performed under ROOT. Enter the password." ;
	if [ "${1}" = "1" ]	# copia real
	then
		su -c 'mkisofs -R -J -o image.raw /mnt/cdrom ; cdrecord -v -eject image.raw' ;
	else	# mode dummy
		su -c 'mkisofs -R -J -o image.raw /mnt/cdrom ; cdrecord -v -dummy -eject image.raw' ;
	fi			
	echo "";
	echo "Umounting the CD source...";
	umount /dev/cdrom /mnt/cdrom;
	CleanDataTempDir;
	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, make a dummy copy to check the buffer size is OK.";
	echo "If the current buffer size is not enough, increase the";
	echo "FIFO size in the CDRECORD configuration file.";
	echo "See menu OTHERS, option n 10." ;
	echo "Also you can low the copy speed." ;
	echo "****************************************************************************";
	Beep;
	echo "" ;
	echo "" ;
	echo "Insert the source and target CDs.";
	PressAnyKey;
	echo "";
	echo "Mounting the CD source...";
	mount /dev/cdrom /mnt/cdrom;
	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		
	echo "";
	echo "Umounting the CD source...";
	umount /dev/cdrom /mnt/cdrom;
	PressAnyKey;
	return ;
}



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

Image2cd () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "Copy data image file to CD-R";
	else
		echo "Dummy copy data image file to CD-R";
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo "" ;
	echo "WARNING:  MULTISESSION does not close recordable CD and allows copy" ;
	echo "  *****   of data to recordable CD on several ocasions." ;
	echo " ** | **  Remember: The first data image to CD-R for multisession" ;
	echo " ** 0 **  are different from second and followings data image files." ;
	echo "  *****   See menu DATA, option n 2" ;
	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 "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "Get data image file" ;
	else
		echo "Get multisession data image file" ;
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	DirOrg=`pwd`;
	DirDest=`pwd`;
	echo " " ;
	echo "-By default data image file will be stored in the selected directory-" ;
	echo -n "Create new directory for image file? y/n: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		CreateDirectory;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		DirDest=`pwd`;
	fi
	CleanDataTempDir;
	echo " " ;
	echo " " ;
	if [ "${1}" = "2" ]  # multisession
	then
		echo "ATTENTION  IN MULTISESSION DATA IMAGE FILES:";
		echo "           If this is the first data image file to the CD-R (The CD-R";
		echo "  *****    is blank yet), you must enter 'y' in the next question.";
		echo " ** | **   In the second and followings data images files to multisession";
		echo " ** o **   CD-R (multisession CD-R not blank) must be created with";
		echo "  *****    special features so enter 'n' in next question.";
		home2=$HOME;
		cd $DirOrg;
		cd ..;
		PadreDirOrg=`pwd`;
		export home2;
		export DirOrg;
		export DirDest;
		export PadreDirOrg;
		echo "";
		Beep;
		echo -n "This is the first data image file to CD-R? [y/n]: ";
		read opc;
		if [ "$opc" = "y" ]
		then
			echo "";
			echo "";
			echo "Creating first multisession data image file...";
			echo "";
			mkdir $home2/grabator/dirmulti;
			cd $home2/grabator/dirmulti;
			mv -f $DirOrg $home2/grabator/dirmulti;
			mkisofs -R -J -o $home2/grabator/cddata/image.raw $home2/grabator/dirmulti;
			mv -f $home2/grabator/dirmulti/* $PadreDirOrg;
			mv -f $home2/grabator/cddata/image.raw $DirDest;
			rm -fr $home2/grabator/dirmulti;
		else
			echo "";
			echo "";
			echo "To get a no-first multisession data image file,";
			echo "first, you must known some information under ROOT.";
			echo "";
			echo "Please, insert the multisession CD-R in the CD-Recorder (not CD-ROM).";
			PressAnyKey;
#			clear;
#			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
#			echo "Get multisession data image file" ;
#			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
#			echo "";
#			echo "";
#			home2=$HOME;
#			cd $DirOrg;
#			cd ..;
#			PadreDirOrg=`pwd`;
#			export home2;
#			export DirOrg;
#			export DirDest;
#			export PadreDirOrg;
			echo "The operation must be performed under ROOT. Enter the password.";
			su -c '
echo "";
echo "1. Getting the MSINFO number of CD-R ...";
msinfo=`cdrecord -msinfo`;
echo "";
echo "2. Getting SCSI CD-Recorder devices for CDRECORD.";
echo "";
cdrecord -scanbus;
echo "";
echo -n "Enter the SCSI CD-Recorder device [X,Y,Z], e.g. 0,1,0: ";
read cdrdevice;
#create a temporary directory to move the data and create a data image file.
echo "";
echo "";
echo "Creating multisession data image file...";
echo "";
mkdir $home2/grabator/dirmulti;
cd $home2/grabator/dirmulti;
mv -f $DirOrg $home2/grabator/dirmulti;
mkisofs -R -J -o $home2/grabator/cddata/image.raw -C $msinfo -M $cdrdevice $home2/grabator/dirmulti;
mv -f $home2/grabator/dirmulti/* $PadreDirOrg;
mv -f $home2/grabator/cddata/image.raw $DirDest;
rm -fr $home2/grabator/dirmulti;'
		fi
	else    # no multisession
		echo "Creating data image file..." ;
		echo " " ;
		mkisofs -R -J -o $DirDest/image.raw $DirOrg ;
	fi
	cd $DirDest;
	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 "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	dir=`pwd`;
	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 "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		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 > $dir/$archv.raw ;
				sox -t raw -r 44100 -c 2 -w -s $dir/$archv.raw  -r 44100 -c 2 -t wav -w -s $dir/$archv.wav ;
				rm -f $dir/$archv.raw ;
			done ;
			GetSizeInMB;
			break;
		else
			if [ -f $dir/$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 > $dir/$archvmp3.raw ;
		  		  sox -t raw -r 44100 -c 2 -w -s $dir/$archvmp3.raw  -r 44100 -c 2 -t wav -w -s $dir/$archvmp3.wav;
					rm -f $dir/$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 $dir ;
	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
	echo " " ;
	echo " " ;
	echo -n "Enter speed of copy (INTRO, Default speed): " ;
	read speed;
	export speed;
	GetCDRecordable;
	CopyCD ${1};
	PressAnyKey;
	return 0;
}

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

AudioDirectCopy () {
	cd $HOME/grabator/cdaudio
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Direct Audio CD copy to CD-R" ;
	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
		clear;
		echo "\

Welcome to GRABATOR!

Written by Jose L. Diaz.
March/2001

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

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

--------------------------------------------------------------
WARNING: For a correct GRABATOR funcionality, you must
         configure properly the CDRECORD configuration file in
         menu OTHERS, option n 10.
--------------------------------------------------------------";
		Beep;
		PressAnyKey;
		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 -B "$track";;
			2) cdparanoia -Y -B "$track";;
			3) cdparanoia -Z -B "$track";;
		esac;
		track=`expr ${track} + 1`;
	done
	Beep;
}

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

GetSizeInMB () {
	echo " " ;
	echo " " ;
	echo -n "Size in MBytes: "
	pwd | du -h
}

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

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

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

GoToDir () {
	while true;
	do
		echo "" ;
		echo "" ;
		echo "GRABATOR directories:" ;
		echo "______________________________________________________________________" ;
		ls -C --color $HOME/grabator ;
		echo "______________________________________________________________________" ;
		echo "-Select with mouse & paste the directory or enter the complete path-";
		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 '
if [ "$speed" = "" ]
then
	cdrecord -dao -eject -shorttrack -pad -audio *.wav;
else
	cdrecord -dao -eject speed=$speed -shorttrack -pad -audio *.wav;
fi';;
		2) su -c 'cdrecord -v -eject image.raw' ;;     # data copy
		3) su -c 'cdrecord -v -eject -multi image.raw' ;;  # multisession copy data
		4) su -c '
if [ "$speed" = "" ]
then
	cdrecord -dummy -dao -eject dev=0,0,0 -shorttrack -pad -audio *.wav;
else
	cdrecord -dummy -dao -eject speed=$speed dev=0,0,0 -shorttrack -pad -audio *.wav;
fi';;
		5) su -c '
clear;
cdparanoia -Q;
echo " " ;
echo " " ;
echo -n "Enter the number of tracks contained in the CD: " ;
read numtracks;
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 -n "Enter speed of copy (INTRO, Default speed): " ;
read speed;
echo " " ;
echo " " ;
echo -n "Extracting CD tracks... ";
echo " " ;
echo " " ;
track=1;
while [ "$track" -le "$numtracks" ];
do
	case $type in
		1) cdparanoia -B "$track";;
		2) cdparanoia -Y -B "$track";;
		3) cdparanoia -Z -B "$track";;
	esac;
	track=`expr ${track} + 1`;
done
if [ "$speed" = "" ]
then
	cdrecord -dao -eject -shorttrack -pad -audio *.wav;
else
	cdrecord -dao -eject speed=$speed -shorttrack -pad -audio *.wav;
fi';;
		6) su -c 'cdrecord -v -dummy -eject image.raw' ;;     # dummy audio copy
		7) su -c 'cdrecord -v -dummy -eject -multi image.raw' ;;  # dummy multisession copy data
		8) su -c 'mkisofs -R -J /mnt/cdrom | cdrecord -v -';;  # onthefly copy
		9) su -c 'mkisofs -R -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
		12) su -c '
if [ "$speed" = "" ]
then
	cdrecord -v -eject -nofix -pad -audio $archwav;
else
	cdrecord -v -eject speed=$speed -nofix -pad -audio $archwav;
fi';;
		13) su -c '
if [ "$speed" = "" ]
then
	cdrecord -v -eject -nofix -pad -dummy -audio $archwav;
else
	cdrecord -v -eject speed=$speed -nofix -pad -dummy -audio $archwav;
fi';;
	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 -B "$track" $nametrack.wav;
		mv track*.$nametrack.wav $nametrack.wav;
		clear ;
		Beep;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "Get WAV files from several Audio-CD" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GetSizeInMB;
		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 -B "$track" $nametrack.wav;
		mv track*.$nametrack.wav $nametrack.wav;
		Beep;
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "Get MP3 files from several Audio-CD" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GetSizeInMB;
		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;
}

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

ConvertCdrCopyFormat () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "The CD-R copy format is:" ;
	echo "WAV format, 16 bits, Stereo & 44.100 Hz" ;
	echo " " ;
	echo "WARNING: In big files this action is going to take a long time" ;
	echo "         and the quality sound maybe not good" ;
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo " " ;
	echo " " ;
	echo -n "Select the file [0 Exit]: " ;
	read archv;
	if [ "$archv" = "0" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "Enter the audio parameters of the original audio file:" ;
	echo " " ;
	echo " " ;
	echo "\
Enter the audio format of the original audio file.

The formats supported are:

       8svx     Amiga 8SVX musical instrument description.
       aiff     AIFF  files  used  on  Apple  IIc/IIgs  and SGI.
       au       SUN Microsystems AU files.
       cdr      CD-R.
       cvs      Continuously Variable Slope Delta modulation.
       dat      Text Data files.
       gsm      GSM 06.10 Lossy Speech Compression.
       hcom     Macintosh  HCOM  files.
       maud     An Amiga format.
       ossdsp    OSS /dev/dsp device driver.
       sf       IRCAM Sound Files.
       smp      Turtle Beach SampleVision files.
       sunau     Sun /dev/audio device driver.
       txw      Yamaha TX-16W sampler.
       vms      Used to compress speech audio such as voice mail.
       voc      Sound Blaster VOC files.
       wav      Microsoft .WAV RIFF files.
       wve      Psion 8-bit alaw.
       raw      Raw files (no header).
       ub, sb, uw, sw, ul
                 These  are  several  suffices  which  serve as a
                 shorthand for raw files with a  given  size  and
                 style.   Thus, ub, sb, uw, sw, and ul correspond
                 to 'unsigned  byte',  'signed  byte', 'unsigned
                 word',  'signed  word',  and 'ulaw' (byte).
       auto     This is a ``meta-type'' format.
";
	echo "-You can select & paste-";
	echo -n "Enter audio format [0 Exit]: " ;
	read format;
	if [ "$format" = "0" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo -n "Enter the original rate (XX.XXX  E.g: 44.100) [0 Exit]: " ;
	read rate;
	if [ "$rate" = "0" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "\
Enter the bits resolution of the original audio file.

The bits resolution supported types are:

	b : 8-bit  bytes.
	w : 16-bit words.
	l : 32-bit long words.
	f : 32-bit floats.
	d : 64-bit double floats.
	D : 80-bit IEEE floats.
	    [Floats and double floats are in native machine format]

";
	echo "-You can select & paste-";
	echo -n "Bits resolution [0 Exit]: " ;
	read bits;
	if [ "$bits" = "0" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "\
Enter the audio channels of the original audio file.

The most common number of audio channels are:

	1: Mono.
	2: Stereo.
	4: Four audio channels.
";
	echo -n "Audio channels [0 Exit]: " ;
	read channel;
	if [ "$channel" = "0" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	Beep;
	echo "Press any key to convert to WAV format, 16 bits, Stereo & 44.100 Hz." ;
	read;
	echo "" ;
	echo "" ;
	echo -n "Converting the file: " ;
	echo $archv;
	echo " " ;
	echo "WARNING: In big files this action is going to take a long time." ;
	echo "" ;
	sox -V -t $format -r $rate -c $channel -$bits -s $archv -t wav -r 44100 -c 2 -w -s $archv.cdformat.wav;
	Beep;
	echo "";
	echo -n "The file is found in: " ;
	pwd;
	GetSizeInMB;
	echo "";
	echo "";
	echo -n "Do you wish to delete the original file? 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 "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "WARNING: In Audio+Data CD, the data will be stored in the first track";
	echo "         of the CD-R and the next tracks will be the audio tracks.";
	echo "         You can't hear the track n 1, is silence.";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	if [ ! -f image.raw ]
	then
		Beep;
		echo "";
		echo "";
		echo "ERROR: 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 1.0
Written by Jose L. Diaz.
March/2001

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

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;
}

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

MountDataImage () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "View data image content" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ -b /dev/loop0 ]
	then
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		echo "" ;
		echo "" ;
		if [ ! -f image.raw ]
		then
			echo "WARNING: Data image file 'image.raw' not found!";
			Beep;
		else
			echo "This operation must be performed under ROOT. Enter the password.";
			su -c 'mount image.raw -r -v -t iso9660 -o loop /mnt ; ls -lChR /mnt | more ; umount /mnt';
		fi
	else
		Beep;
		echo "ERROR: The LOOP device [/dev/loop0] not exist.";
		echo "       To create it go to menu OTHERS, option n 9.";
	fi
	PressAnyKey;
	return;
}

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

CreateLoopDev () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Create a LOOP device" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	if [ -b /dev/loop0 ]
	then
		Beep;
		echo "WARNING: The LOOP device [/dev/loop0] is already created!";
	else
		echo -n "Create the /dev/loop0 device? y/n : ";
		read opc;
		if [ "$opc" = "y" ]
		then
			echo "" ;
			echo "This operation must be performed under ROOT. Enter the password.";
			su -c 'mknod /dev/loop0 b 7 0';
		fi
	fi
	PressAnyKey;
	return;
}

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

ConfCdrecord () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Modify CDRECORD configuration file [/etc/cdrecord.conf]" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	if [ ! -f /etc/cdrecord.conf ]
	then
		if [ ! -f /usr/bin/cdrecord ]
		then
			Beep;
			echo "WARNING: CDRECORD is not installed in your system!";
			echo "         Please, install it.";
			PressAnyKey;
			return;
		fi
	fi
	echo "This operation must be performed under ROOT. Enter the password.";
	su -c '
echo "" ;
echo "Getting SCSI CD-Recorder devices for CDRECORD...";
echo "" ;
cdrecord -scanbus;
echo "" ;
echo -n "Enter the default device [X,Y,Z], e.g. 0,1,0: ";
read device;
echo "" ;
echo -n "Enter the default speed copy, e.g. 2: ";
read speed;
echo "" ;
echo -n "Enter the fifo size [Default enter 4m]: ";
read fifosize;
echo "" ;
echo "" ;
echo -e "\a";
echo -n "Modify the /etc/cdrecord.conf file. Are you sure? y/n : ";
read opc;
if [ "$opc" = "y" ]
then
	mv /etc/cdrecord.conf /etc/cdrecord.conf.old ;
	echo "\
#ident @(#)cdrecord.dfl	1.2 00/04/16 Copyr 1998 J. Schilling
#
# This file is /etc/cdrecord.conf
# It contains defaults that are used if no command line option
# or environment is present.
# 
# The default device, if not specified elswhere
#
CDR_DEVICE=$device
# 
# The default speed, if not specified elswhere
#
CDR_SPEED=$speed

# 
# The default FIFO size if, not specified elswhere
#
CDR_FIFOSIZE=$fifosize

#
# The following definitions allow abstract device names.
# They are used if the device name does not contain the
# the characters ',', ':', '/' and '@'
#
# drive name	device	speed	fifosize driveropts
#
# teac=		1,3,0	-1	-1	""
# panasonic=	1,4,0	-1	-1	""
# plextor=	1,4,0	12	-1	""
# sanyo=	1,4,0	12	-1	burnproof
# yamaha=	1,5,0	-1	-1	""
# cdrom=	0,6,0	2	1m	""
#
#***********************************
# This file was created by GRABATOR
#***********************************
" > /etc/cdrecord.conf ;
		echo "" ;
		echo "/etc/cdrecord.conf was changed.";
		echo "The original file was saved to /etc/cdrecord.conf.old";
fi';
	PressAnyKey;
	return;
}

#******************************************************************************
	
MultiAudio () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "12" ]	# real copy (no dummy)
	then
		echo "Multisession audio CD-R copy" ;
	else
		echo "Multisession audio CD-R DUMMY copy" ;
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo -n "Select the file [0 Exit]: " ;
	read archwav;
	if [ "$archwav" = "0" ]
	then
		return;
	fi
	export archwav;
	echo " " ;
	echo -n "Enter speed of copy (INTRO, Default speed): " ;
	read speed;
	export speed;
	CopyCD ${1};
	Beep;
	PressAnyKey;
	return;
}

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

CloseMultiAudio () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Close multisession audio CD-R" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetOriginalCD;
	echo "";
	echo "";
	echo "This operation must be performed under ROOT. Enter the password.";
	su -c 'cdrecord -v -audio+dataeject -fix; echo ""; echo "The audio CD is close."';
	Beep;
	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/MPEG 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 "    6. Multisession audio CD-R copy";
	echo "    7. Multisession audio CD-R DUMMY copy";
	echo "    8. Close a multisession audio CD-R";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		0) break;;
		1) AudioDirectCopy;;
		2) AudioCopy 1;;
		3) MP3toCD 1;;
		4) AudioCopy 4;;	# dummy
		5) MP3toCD 4;;	# dummy
		6) MultiAudio 12;;
		7) MultiAudio 13;; #dummy
		8) CloseMultiAudio;;
	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 file and copy";
	echo "    2. Data-CD direct dummy copy to CD-R: Get data image file 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. Copy data image file to CD-R";
	echo "    6. Dummy copy data image file 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) Image2cd 1;;
		6) 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 audio file formats to CD-R copy file format";
	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) ConvertCdrCopyFormat;;
	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 "    9. Create a LOOP device";
	echo "   10. Modify CDRECORD configuration file [cdrecord.conf]";
	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;;
		9) CreateLoopDev;;
		10) ConfCdrecord;;
	esac;
done
}

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

menudata () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: GRABATOR :::::::::::::::::::::::::::::::::::::::::::::: Jose L. Diaz";
	echo "========================================================================";
	echo "";
	echo "::: DATA :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Get data image file";
	echo "    2. Get data image for Multisession copy";
	echo "    3. Mount/View data image";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		0) break;;
		1) GetImage 1;;
		2) GetImage 2;;
		3) MountDataImage;;
	esac;
done
}


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

CreateDirByDefault;
while true;
do
	clear;
	echo "=======================================================================";
	echo "::: GRABATOR :::::::::::::::::::::::::::::::::::::::::: By Jose L. Diaz";
	echo "=======================================================================";
	echo "    CD Creation & Sound                                    Version: 1.0";
	echo "";
	echo "";
	echo "";
	echo "    1. Audio CD-R";
	echo "    2. Data CD-R";
	echo "    3. Audio+Data CD-R";
	echo "    4. Audio";
	echo "    5. Data" ;
	echo "    6. Others";
	echo "    7. 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) menudata;;
		6) menuothers;;
		7) AboutGrabator;;
	esac;
done