#!/bin/bash

# CDDOIT 1.5
# Author:  Jose L. Diaz.
# April/2003
# Homepage: http://www.geocities.com/cddoit/index.html
# This software comes with NO warranty of any kind. Use at your own risk.
# Report bugs or suggestions to: cddoit@yahoo.com
# ===============================================================================



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


#******************************************************************************
GetWavTime () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Get total time duration from WAV files";
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1; # exit from the menu choice
	fi
	echo "";
	echo "";
	echo "Total Time duration of WAV files in $PWD:";
	echo "";
	secs=0;
	GetWavSecsDir;
	echo "        Minutes (+-): $(($secs / 60)) Minutes";
	echo "        Seconds (exact): $secs Seconds";
	PressAnyKey;
	return;
}


#******************************************************************************
GetWavSecsDir () {
# get the time duration IN SECONDS from all wav files in the current directory
	onesec=176444   # 1 second = 176444 bytes in wav cd format.
	numwav=`ls -l *.wav | wc -l`;
	if [ "$numwav" -gt "1" ]
	then
		bytestrack=`wc -c *.wav | grep total | cut -d't' -f1`;
	else
		bytestrack=`wc -c *.wav | cut -d' ' -f1`;
	fi
	secs=$(( $bytestrack / $onesec ));
	return $secs;
}



#******************************************************************************
denoise () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Noise reduction";
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "NOTE: The audio noise reduction is not an exact science.";
	echo "      More noise reduction cycles generate less noise, BUT less";
	echo "      audio quality (low treeble) too!. Try to balance between";
	echo "      cycles and quality.";
	echo "";
	echo "      Noise reduction uses a lot of disk space (at least three times";
	echo "      the file size) and time.";
	echo "";
	echo "      Good luck.";
	echo "";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1; # exit from the menu choice
	fi
	echo "";
	echo "";
	echo -n "Select the audio file [0: Exit]: " ;
	read archv;
	if [ "$archv" = "0" ] || [ "$archv" = "" ]
	then
		return;
	fi
	if [ ! -f "$archv" ]
	then
		echo " " ;
		echo " " ;
		echo "ERROR: File not found!" ;
		Beep;
		PressAnyKey;
		return;
	fi
	
	track="$archv";
	echo "";
	echo "";
	echo -n "Enter the audio format [ENTER: wav]: ";
	read audioformat;
	if [ "$audioformat" = "" ]
	then
		audioformat="wav"; # default
	fi
	echo "";
	echo "";
	echo -n "Enter the number of noise reduction cycles [ENTER: 2 cycles]: ";
	read numcycles;
	if [ "$numcycles" = "0" ]
	then
		echo "";
		echo "No denoise perfomed.";
		PressAnyKey;
		return;
	fi
	if [ "$numcycles" = "" ]
	then
		numcycles="2"; # default
	fi
	echo "";
	echo "";
	echo "Starting denoise...";
	echo "______________________________________________";
	# get rough frequency
	sox -t "$audioformat" "$track" -e stat 2> .RoughFequNoise1.cddoit;
	grep Rough .RoughFequNoise1.cddoit > .RoughFequNoise2.cddoit;
	RoughFrequ=`cut -d':' -f2 .RoughFequNoise2.cddoit`;
	# remove noise
	sox -t "$audioformat" "$track" "Ytrack"."$audioformat" bandreject $RoughFrequ $RoughFrequ;
	ncycle=1;
	echo "Cycle $ncycle/$numcycles finished.";
	if [ "$numcycles" = "1" ]  # only a one cycle will be perfomed
	then
		mv -f "Ytrack"."$audioformat" "$archv".denoise."$audioformat";   # the Xtrack temporal file will be not used
	else
		opc="Y";
		while [ "$ncycle" -lt "$numcycles" ];
		do
			if [ "$opc" = "Y" ]
			then
				# remove noise
				sox -t "$audioformat" "Ytrack"."$audioformat" "Xtrack"."$audioformat" bandreject $RoughFrequ $RoughFrequ;
				opc="X";
			else
				# remove noise
				sox -t "$audioformat" "Xtrack"."$audioformat" "Ytrack"."$audioformat" bandreject $RoughFrequ $RoughFrequ;
				opc="Y";
			fi
			ncycle=`expr ${ncycle} + 1`;
			echo "Cycle $ncycle/$numcycles finished.";
		done
		if [ "$opc" = "Y" ]
		then
			# last created is Y
			mv -f "Xtrack"."$audioformat" "$archv".denoise."$audioformat";
			rm -f "Ytrack"."$audioformat";
		else
			mv -f "Ytrack"."$audioformat" "$archv".denoise."$audioformat";
			rm -f "Xtrack"."$audioformat";
		fi
	fi
	rm -f .RoughFequNoise1.cddoit;
	rm -f .RoughFequNoise2.cddoit;
	echo "______________________________________________";
	echo "Denoise finished.";
	PressAnyKey;
	return;
}



#******************************************************************************
CDTrackSaver () {
	# play and save a CD audio track in a WAV file with cdparanoia & sox
	# USE ONLY WHEN THE RIPPERING IS NOT POSSIBLE!.
	# args:  1: the CD track
	#        2: The wav filename
	cdparanoia -Z -B "${1}" - | sox -t wav -r 44100 -w -s -c 2 - -t WAV -r 44100 -w -s -c 2 "${2}";
	return;
}


#******************************************************************************
CDTrackPlayer () {
	# Play a CD audio track in the soundcard (/dev/dsp) with cdparanoia & sox
	cdparanoia -Z -B "${1}" - | sox -t wav -r 44100 -w -s -c 2 - -t ossdsp -r 44100 -w -s -c 2 /dev/dsp;
	return;
}

#******************************************************************************
CDplayer () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: CD Player";
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetOriginalCD;
	echo "Reading CD ...";
	GetCDNumTracks;
	while true;
	do
		cd $HOME/cddoit/;
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: CD Player";
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "";
		echo "The CD contains $CDNumTracks audio tracks.";
		echo "";
		echo "    1. Play the whole CD";
		echo "    2. Play a track";
		echo "    3. Play a playlist";
		echo "    4. Show all the playlist";
		echo "    5. Show a playlist tracks";
		echo "    6. Create a playlist";
		echo "    7. Delete a playlist";
		echo "    8. Eject the CD";
		echo "";
		echo "    0. Exit CD Player";
		echo "";
		echo "    STOP Playing ==> CTRL+C";
		echo "";
		echo -n "Choose option: ";
		read opc;
		echo "";
		echo "";
		case $opc in
			"") break;;
			0) break;;
			1) echo "Playing the Audio CD..."; cdplay;;
			2)  echo -n "Enter track number: ";
				read tracknum;
				echo "";
				echo "";
				echo "Playing the track number $tracknum ::::::::::::::::::::::::::::::::::::::::::::::::";
				echo "";
				CDTrackPlayer $tracknum;;
			3)  echo "CDDOIT Playlists:";
				echo "-----------------";
				ls -a .*.cddoit.playlist;
				if [ "$?" = "1" ]
				then
					echo "";
					echo "";
					echo "WARNING: No playlist available.";
					PressAnyKey;
				else
					echo "";
					echo -n "Enter the playlist name [You can select & paste]: ";
					read playlist;
					if [ ! -f $HOME/cddoit/"$playlist" ]
					then
						echo "";
						echo "";
						echo "ERROR: Playlist not found!";
					else
						clear;
						echo "";
						echo "";
						echo "::: PLAYLIST: $playlist :::";
						cnt=1;
						tracknum=`cut -f $cnt --delimiter="," $HOME/cddoit/"$playlist"`;
						until [ "$tracknum" = "END" ];
						do
							echo "";
							echo "Playing the track number $tracknum ::::::::::::::::::::::::::::::::::::::::::::::::";
							echo "";
							CDTrackPlayer $tracknum;
							cnt=`expr ${cnt} + 1`;
							tracknum=`cut -f $cnt --delimiter="," $HOME/cddoit/"$playlist"`;
						done
					fi
				fi;;
			4)  echo "CDDOIT Playlists:";
				echo "-----------------";
				ls -a .*.cddoit.playlist;
				if [ "$?" = "1" ]
				then
					echo "";
					echo "";
					echo "WARNING: No playlist available.";
				fi
				PressAnyKey;;
			5)  echo "CDDOIT Playlists:";
				echo "-----------------";
				ls -a .*.cddoit.playlist;
				if [ "$?" = "1" ]
				then
					echo "";
					echo "";
					echo "WARNING: No playlist available.";
				else
					echo "";
					echo "";
					echo -n "Enter the playlist name [You can select & paste]: ";
					read playlist;
					echo "";
					echo -n "Tracks from $playlist: ";
					cat $playlist;
				fi
				PressAnyKey;;
			6)  echo -n "Enter the playlist name [You can select & paste]: ";
				read playlist;
				echo -n "Enter the track numbers separates by commas [e.g: 7,3,23,12,1,1,5]: ";
				read playlisttracks;
				echo $playlisttracks,END > $HOME/cddoit/."$playlist".cddoit.playlist;
				echo "Playlist created.";
				PressAnyKey;;
			7)  echo "CDDOIT Playlists:";
				echo "-----------------";
				ls -a .*.cddoit.playlist;
				if [ "$?" = "1" ]
				then
					echo "";
					echo "";
					echo "WARNING: No playlist available.";
				fi
				echo "";
			    echo -n "Enter the playlist name [You can select & paste]: ";
				read playlist;
				rm -fv $HOME/cddoit/"$playlist";
				PressAnyKey;;
			8) eject; break;;
		esac;
	done
	return;
}



#******************************************************************************
GetCDNumTracks () {
	cdparanoia -Q 2> $HOME/cddoit/.cdnumtracks.cddoit;
	if [ "$?" = "1" ]
	then
		PressAnyKey;
		return 1;
	fi
	CDNumTracks=`cat $HOME/cddoit/.cdnumtracks.cddoit | grep -1 "TOTAL" | grep -v "(" | cut -b -3`;
	rm -f $HOME/cddoit/.cdnumtracks.cddoit;
	return $CDNumTracks;
}


#******************************************************************************
RecordCDAudioTracks () {
# This function record all tracks from the CD.
# It's only when Cdparanoia can't extract the audio OK (many "V" appears).
# Every track from the CD is recording in separate wav files.
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Get WAV files when ripering fails";
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "NOTE: This function maybe is usefull when the normal audio extraction fails.";
	echo "      (For example, when the CD is damaged and the rippering is not good,";
	echo "      many 'V' in the extraction sequence).";
	echo "      However, the audio quality is NOT guaranted with this method.";
	echo "";
	echo "";
	echo "Recording is in CD copy format: WAV format, Stereo, 16 bits & 44.100 Hz." ;
	GetOriginalCD;
	CreateDirectory;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	GetCDNumTracks;
	echo "";
	echo "The number of audio tracks in the CD is: $CDNumTracks";
	echo "";
	echo "";
	cnt=1;
	while [ "$cnt" -le "$CDNumTracks" ];
	do
		echo "";
		echo "";
		echo "Recording CD track $cnt to "$nomdir".track$cnt.cddoit.wav ...";
		echo "";
		CDTrackSaver $cnt "$nomdir".track$cnt.cddoit.wav;
		if [ "$cnt" -lt "10" ]
		then
			mv "$nomdir".track$cnt.cddoit.wav "$nomdir".track0$cnt.cddoit.wav;
		fi
		echo "";
		echo ""$nomdir".track$cnt.cddoit.wav recorded.";
		echo "-----------------------------------------------------------------------";
		cnt=`expr ${cnt} + 1`;
	done	
	PressAnyKey;
	return;
}




#******************************************************************************
CreateCDDOITDir () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Create a new CDDOIT directory (Empty)";
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	CreateDirectory;
	PressAnyKey;
	return;
}

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

normalize () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Adjust max volume in audio files" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "NOTE: Allows adjust to the highest audio volume possible of an input file";
	echo "      without clipping. Also, you can enter your own volume values.";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1; # exit from the menu choice
	fi
	echo "";
	echo "";
	echo -n "Select the audio file [0: Exit]: " ;
	read archv;
	if [ "$archv" = "0" ] || [ "$archv" = "" ]
	then
		return;
	fi
	if [ ! -f "$archv" ]
	then
		echo " " ;
		echo " " ;
		echo "ERROR: File not found!" ;
		Beep;
		PressAnyKey;
		return;
	fi
	echo " " ;
	echo " " ;
	echo -n "Enter the audio format (Usually the file extension. e.g: wav): ";
	read audiotype;
	echo " " ;
	echo " " ;
	echo "NOTE: In big files this action is going to take a long time.";
	echo "Getting the highest volume value..." ;
	echo " " ;
	sox -t $audiotype "$archv" -e stat -v 2> volmax.cddoit;
	volmax=`cut -d'.' -f1 volmax.cddoit`;
	volmax2=`cut -d'.' -f2 volmax.cddoit`;
	rm -f volmax.cddoit;
	Beep;
	echo " " ;
	echo "The highest volume value in "$archv" is: $volmax.$volmax2";
	echo " " ;
	echo -n "Enter a normalization volume value [Press ENTER for highest value]: ";
	read normvalue;
	echo " ";
	echo "NOTE: In big files this action is going to take a long time.";
	if [ "$normvalue" = "" ]
	then
		echo "Normalizing "$archv" at $volmax.$volmax2 volume without clipping...";
		echo " ";
		sox -V -v $volmax.$volmax2 -t $audiotype "$archv" "$archv".normalized.$audiotype;
	else
		echo "Normalizing "$archv" at $normvalue volume...";
		echo " ";
		sox -V -v $normvalue -t $audiotype "$archv" "$archv".normalized.$audiotype;
	fi
	Beep;
	echo " " ;
	echo "Volume adjust finished." ;
	echo "The new audio file is: "$archv".normalized.$audiotype";
	PressAnyKey;
	return;
}



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

CreateBootImage () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	case ${1} in
		1) echo "CDDOIT: Create a 'El Torito' image file -Bootable CD-";;
	esac;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "Enter the directory to get the image file:";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1; # exit from the menu choice
	fi
	DirOrg=$PWD;
	echo "";
	echo "";
	echo "Enter the directory where the image file will be created:";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1; # exit from the menu choice
	fi
	DirDest=$PWD;
	PressAnyKey;
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	case ${1} in
		1) echo "CDDOIT: Create a 'El Torito' image file -Bootable CD-";;
	esac;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "NOTE: To create a bootable CD, a boot file is needed.";
	echo "      You can get this boot file from a bootable floppy disk";
	echo "      (e.g: A linux boot floppy) or from a bootable CD";
	echo "      (e.g: Your linux distribution CD).";
	echo "";
	echo "Enter the device where the boot file is found:";
	echo "      1. Bootable floppy disk (Recomended. It's automatic!)";
	echo "      2. Bootable CD";
	echo "";
	echo -n "Device [0: Exit]: ";
	read device;
	echo "";
	if [ "$device" = "0" ] || [ "$device" = "" ]
	then
		return;
	fi
	if [ "$device" = "1" ]  || [ "$device" = "2" ]
	then
		if [ "$device" = "1" ]
		then
			echo "";
			echo "Insert the bootable floppy disk. No mount the floppy.";
			PressAnyKey;
			echo "";
			echo "Creating the boot file...";
			dd if=/dev/fd0 of="$DirOrg"/boot.img bs=10k count=144;
			echo "Boot file created.";
		fi	
		if [ "$device" = "2" ]
		then
			echo "";
			echo "In this case, first you must copy the boot file (usually named 'boot.xxx')";
			echo "from the CD to "$DirOrg", rename it to 'boot.img' and then press ENTER.";
			echo "NOTE: Remember remove this file from "$DirOrg" after the image file creation.";
			PressAnyKey;
		fi
	else
		return;
	fi
	echo "";
	echo "";
	echo "Creating a EL TORITO image file...";
	echo "";
	cd "$DirOrg";
	mkisofs -v -b boot.img -c boot.catalog -o "$DirDest"/image.raw "$DirOrg";
	if [ "$?" != "0" ]
	then
		echo "";
		echo "Error in the image file creation.";
		PressAnyKey;
		return;
	fi
	if [ "$device" = "1" ] # from a floppy disk
	then
		rm -fv "$DirOrg"/boot.img;
	fi
	echo "";
	echo "EL TORITO image file created in "$DirDest".";
	echo "";
	echo "";
	echo -n "Do you wish create the EL TORITO CD now? [y/n]: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		GetCDRecordable;
		while true;
		do
			cd "$DirDest";
			CopyCD 2; # a normal data copy		
			if [ "$?" = "1" ] # CopyCD error (possible SU error)
			then
				echo "";
				echo "ERROR. CD-Copy could not be started.";
				echo "       Possible incorrect ROOT password.";
				Beep;
				echo "";
				echo -n "Re-enter the password again? [y/n]: ";
				read opc;
				if [ "$opc" != "y" ]
				then
					break;
				fi
			else
				break;
			fi
		done
		echo "";
		echo "";
		echo "CD copy finished.";
		echo -n "Do you wish delete the EL TORITO image file now? [y/n]: ";
		read opc;
		if [ "$opc" == "y" ]
		then
			echo "";
			rm -fv "$DirDest"/image.raw;
		fi
	fi
	PressAnyKey;
	return;
}


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

AudioDirectCopyMultisession () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Direct Audio CD copy to CD-R in Multisession" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "WARNING: In this case the CD copy in DAO mode is not possible.";
	echo "         Use this option if your hard disk no have enough free space.";
	echo "         Otherwise, use the normal direct audio CD copy, in";
	echo "         menu AUDIO CD-R, option n 1";
	GetOriginalCD;
	GetCDRecordable;
	cd "$HOME/cddoit/cdaudio"
	CleanAudioTempDir;
	DirectCopyMulti="y";
	export DirectCopyMulti;
	while true;
	do
		CopyCD 5;
		if [ "$?" = "1" ] # CopyCD error (possible SU error)
		then
			echo "";
			echo "ERROR. CD-Copy could not be started.";
			echo "       Possible incorrect ROOT password.";
			Beep;
			echo "";
			echo -n "Re-enter the password again? [y/n]: ";
			read opc;
			if [ "$opc" != "y" ]
			then
				break;
			fi
		else
			break;
		fi
	done
	CleanAudioTempDir;
	PressAnyKey;
	return;
}



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

ClearLogFiles () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Clear log files" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "WARNING: All cddoit log files will be lost!.";
	echo "";
	echo -n "Are you sure? [y/n(ENTER)]: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		echo "";
		rm -vf "$HOME"/cddoit/log/*;
		PressAnyKey;
	fi
	return;
}


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

CdrwBlankForced () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Forced blank completelly the CD-ReWritable. Slow blank" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo "WARNING: Use this option ONLY whether the normal blank is not OK," ;
	echo "         e.g. The CR-RW contains errors (bad CR-RW)." ;
	echo "         This action may take a long time." ;
	GetCDRecordable;
	echo "The operation must be performed under ROOT. Enter the password.";
	su -c 'cdrecord -v -eject -force -blank=all' root;
	Beep;
	PressAnyKey;
	return;
}



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

CdrwUncloseSession () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Unclose the last session from the CD-ReWritable.";
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetCDRecordable;
	echo "The operation must be performed under ROOT. Enter the password.";
	su -c 'cdrecord -v -eject -blank=unclose' root;
	Beep;
	PressAnyKey;
	return;
}


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

CdrwBlankAllFast () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Blank the CD-ReWritable. Fast blank" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetCDRecordable;
	echo "The operation must be performed under ROOT. Enter the password.";
	su -c 'cdrecord -v -eject -blank=fast' root;
	Beep;
	PressAnyKey;
	return;
}

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

CdrwBlankAllSlow () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Blank completelly the CD-ReWritable. Slow blank" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo "WARNING: This action may take a long time." ;
	GetCDRecordable;
	echo "The operation must be performed under ROOT. Enter the password.";
	su -c 'cdrecord -v -eject -blank=all' root;
	Beep;
	PressAnyKey;
	return;
}


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

GetCdRecorderInfo () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Get Information about your CD Recorder" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo "The operation must be performed under ROOT. Enter the password.";
	su -c 'cdrecord -prcap' root;
	PressAnyKey;
	return;
}


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

PlayManyFormats () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Play many audio files [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" ] || [ "$archv" = "" ]
		then
			return;
		fi
		if [ "$archv" = "*" ]
		then
			for archv in *.wav;
			do
				clear;
				echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
				echo "CDDOIT: Playing audio files" ;
				echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
				echo " " ;
				echo " " ;
				echo -n "You are listening: ";
				echo "$archv";
				echo " " ;
				echo " " ;
				sox -t auto -r 44100 -c 2 -w -s "$archv"  -r 44100 -c 2 -t ossdsp -w -s /dev/dsp;
				read;
			done ;
			break;
		fi
		echo " " ;
		if [ -f "$archv" ]
		then
			clear;
			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
			echo "CDDOIT: Playing audio files" ;
			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
			echo " " ;
			echo " " ;
			echo -n "You are listening: ";
			echo "$archv";
			echo " " ;
			echo " " ;
			sox -t auto -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;
}	


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

ConvertBetweenFormats ()
# Arguments:  1. Interactive audio conversion
#             2. audio conversion program
{
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert between audio file formats" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo " WARNING:" ;
	echo "  *****   In big files this action is going to take a long time." ;
	echo " ** | **  Some audio formats are not compatible in some conversions." ;
	echo " ** 0 **  The final quality sound from poor quality formats maybe" ;
	echo "  *****   not good." ;
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo " " ;
	echo " " ;
	echo -n "Select the audio file [0: Exit]: " ;
	read archv;
	if [ "$archv" = "0" ] || [ "$archv" = "" ]
	then
		return;
	fi
	if [ ! -f "$archv" ]
	then
		echo " " ;
		echo " " ;
		echo "ERROR: File not found!" ;
		Beep;
		PressAnyKey;
		return;
	fi
	echo " " ;
	echo " " ;
	echo "Now, you must enter the audio parameters about the original file." ;
	PressAnyKey;
	clear;
	echo "ENTER THE AUDIO PARAMETERS OF THE ORIGINAL AUDIO FILE:" ;
	echo " " ;
	echo "\
1. 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.
       avr      Audio Visual Research
       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.
       sph      SPHERE  (SPeech HEader Resources)
       smp      Turtle Beach SampleVision files.
       snd      Under DOS same as sndt format.Other platforms same as .au format.
       sndt     SoundTool files. Older DOS file format.
       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, al, sl: unsigned byte, signed byte, unsigned word,
                signed word, ulaw (byte), alaw (byte) and "signed long".
       auto     This is a ``meta-type'' format.
";
	echo "-You can select & paste-";
	echo -n "Enter audio format [0: Exit]: " ;
	read format;
	if [ "$format" = "0" ] || [ "$format" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert between audio file formats" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo -n "2. Enter the original sample rate (E.g: 44101 or 8000) [0: Exit]: " ;
	read rate;
	if [ "$rate" = "0" ] || [ "$rate" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert between audio file formats" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "\
3. 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" ] || [ "$bits" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert between audio file formats" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "\
4. 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" ] || [ "$channel" = "" ]
	then
		return;
	fi
	echo "" ;
	echo "" ;
	echo "The audio parameters of the original audio file has been saved." ;
	echo "" ;
	echo "Now, you must enter the audio parameters about the target file." ;
	PressAnyKey;
	clear;
	echo "ENTER THE AUDIO PARAMETERS OF THE TARGET AUDIO FILE:" ;
	echo "=================================================== " ;
	echo " " ;
	echo "\
1. Enter the audio format of the target 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.
       avr      Audio Visual Research
       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.
       sph      SPHERE  (SPeech HEader Resources)
       smp      Turtle Beach SampleVision files.
       snd      Under DOS same as the sndt format
                Under all other platforms it is the same as the .au format.
       sndt     SoundTool files. Older DOS file format.
       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, al, sl
                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', 'ulaw' (byte),"alaw" (byte),
                and "signed  long".
       auto     This is a ``meta-type'' format.
";
	echo "-You can select & paste-";
	echo -n "Enter audio format [0: Exit]: " ;
	read fformat;
	if [ "$fformat" = "0" ] || [ "$fformat" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert between audio file formats" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo -n "2. Enter the target sample rate (E.g: 44101 or 8000) [0: Exit]: " ;
	read frate;
	if [ "$frate" = "0" ] || [ "$frate" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert between audio file formats" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "\
3. Enter the bits resolution of the target 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 fbits;
	if [ "$fbits" = "0" ] || [ "$fbits" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert between audio file formats" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "\
4. Enter the audio channels of the target 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 fchannel;
	if [ "$fchannel" = "0" ] || [ "$fchannel" = "" ]
	then
		return;
	fi
	if [ "${1}" = "2" ]   # audio conversion program
	then
		echo "";
		echo "";
		echo "OK, now you must enter the parameters of the conversion program.";
		PressAnyKey;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert between audio file formats" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	if [ "${1}" = "2" ]   # audio conversion program
	then
		# programming parameters
		echo "PROGRAMMING OF AUDIO CONVERSION";
		echo "===============================";
		echo "";	
		echo "WARNING: Be carefull and check:";
		echo "         . Date & time is correct in your host!";
		echo "         . Others audio conversion or recording programs ";
		echo "           are NOT running at the same time!";
		echo "";	
		echo "";	
		echo -n "1. Enter the date and time to start audio conversion, now is ";	
		date +[%d/%m/%y][%H:%M];
		echo -n "        Year [YY]: ";
		read syear;
		echo -n "        Month [MM]: ";
		read smonth;
		echo -n "        Day [DD]: ";
		read sday;
		echo -n "        Hour [HH]: ";
		read shour;
		echo -n "        Minute [MM]: ";	
		read sminute;
		# creating the warning-file
		echo "CDDOIT Warning" > "NO REMOVE THIS DIRECTORY.README!";
		echo "**************" >> "NO REMOVE THIS DIRECTORY.README!";
		echo "" >> "NO REMOVE THIS DIRECTORY.README!";
		echo "No delete this directory!." >> "NO REMOVE THIS DIRECTORY.README!";
		echo "This directory was created for a CDDOIT audio conversion program." >> "NO REMOVE THIS DIRECTORY.README!";
		echo "If you delete the directory the audio program will be failed." >> "NO REMOVE THIS DIRECTORY.README!";
		echo "" >> "NO REMOVE THIS DIRECTORY.README!";
		echo "This warning-file will be removed automatically after audio program finished." >> "NO REMOVE THIS DIRECTORY.README!";
		echo "" >> "NO REMOVE THIS DIRECTORY.README!";
		echo "You can check the CDDOIT audio recording programs in the CDDOIT menu AUDIO." >> "NO REMOVE THIS DIRECTORY.README!";
		echo "" ;
		echo "" ;
		# running the AT command
		echo "Saving start conversion parameters...";
		echo "sox -t $format -r $rate -c $channel -$bits -s "$archv" -t $fformat -r $frate -c $fchannel -$fbits -s "$archv".$fformat" > "$archv.start.at";
		echo 'rm -f "NO REMOVE THIS DIRECTORY.README!"' >> "$archv.start.at";
		at -f "$archv.start.at" -m $shour:$sminute $sday.$smonth.$syear;
		rm -f "$archv.start.at";
		if [ "$?" = "1" ]   # AT command is not correct
		then
			echo "ERROR: the format of the start parameters is not correct.";
			PressAnyKey;
			return;
		fi
		echo "";	
		echo "";	
		echo "The start parameters were saved OK.";	
		echo "The audio conversion is scheduled OK.";
		echo "" ;
		echo "After the conversion, you can check the output messages in your mail!";
		echo -n "The audio conversion will be found in: " ;
		pwd ;
	else
		echo -n "Press ENTER to start the conversion." ;
		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. Be patient." ;
		echo "" ;
		sox -V -t $format -r $rate -c $channel -$bits -s "$archv" -t $fformat -r $frate -c $fchannel -$fbits -s "$archv".$fformat;
		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
	fi
	PressAnyKey;
	return ;
}


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

SleepTimerRecord ()
{
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Sleeptimer recording" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo " " ;
		echo " " ;
		echo "The recording start now and you choose when finish." ;
		echo "Recording is in WAV format, Stereo, 16 bits & 44.100 Hz." ;
		echo " " ;
		echo " " ;
		echo -n "Recording title [0: Exit]: " ;
		read file;
		export file;
		if [ "$file" = "0" ] || [ "$file" = "" ]
		then
			return;
		fi
		if [ ! -d "$HOME/cddoit/$file" ]
		then
			echo "" ;
			mkdir --verbose "$HOME/cddoit/$file" ;
			cd "$HOME/cddoit/$file";
			break ;
		else
			echo " " ;
			Beep;
			echo "WARNING: The file already exist. Enter a diferent name.";
			PressAnyKey;
		fi
	done	
	echo " " ;
	echo -n "Enter the recording duration [In minutes]: " ;
	read timerec;
	echo "" ;
	echo "" ;
	echo "NOTE: Press 'y' if your SOX version is older or the recording" ;
	echo "      quality is not good.";
	echo "      Default 'n'.";
	echo -n "Do you wish the audio recording in 44101 Hz [y/n(ENTER)]: ";
	read opc44101;
	if [ "$opc44101" = "y" ]
	then
		echo "" ;
		echo "" ;
		echo " WARNING: The sample rate in WAV files to CD copy is 44.100 Hz and" ;
		echo "  *****   this recording is in 44.101 Hz." ;
		echo " ** | **  You must convert to this sample rate before the CD copy." ;
		echo " ** 0 **  You can do it now or convert later in menu AUDIO, option n 10." ;
		echo "  *****   In big files this action is going to take a long time" ;
		echo "" ;
		echo -n "Do you like perform conversion to 44.100 Hz when recording finish? [y/n]: " ;
		read opcconv;
		if [ "$opcconv" = "y" ]
		then
			echo "" ;
			echo -n "Remove old audio 44.101 Hz file after the conversion? [y/n]: " ;
			read opcrem;
		fi
	fi
	echo "";
	echo "";	
	echo "Saving finish recording parameters...";
	echo 'numpid=`ps -u "$USER" | grep 'sox'`' > "$HOME/cddoit/$file/$file.sleeptimer.cddoit";
	echo 'kill $numpid' >> "$HOME/cddoit/$file/$file.sleeptimer.cddoit";
	if [ "$opc44101" = "y" ]
	then
		if [ "$opcconv" = "y" ]
		then
			echo 'sox -V -r 44101 -c 2 -t wav -w -s "$file".44101.wav -t wav -r 44100 -c 2 -w -s "$file".44100.wav' >> "$HOME/cddoit/$file/$file.sleeptimer.cddoit";
			if [ "$opcrem" = "y" ]
			then
				echo 'rm -vf "$file.44101.wav"' >> "$HOME/cddoit/$file/$file.sleeptimer.cddoit";
			fi
		fi
	fi
	at -f "$HOME/cddoit/$file/$file.sleeptimer.cddoit" -m now + $timerec minutes;
	rm -f "$HOME/cddoit/$file/$file.sleeptimer.cddoit";
	if [ "$?" = "1" ]   # AT command is not correct
	then
		echo "ERROR: the format of the finish parameters is not correct.";
		rm -fr "$HOME/cddoit/$file";
		PressAnyKey;
		return;
	fi
	echo "";	
	echo "The finish parameters were saved OK.";	
	echo "";	
	echo "";	
	echo "Press ENTER to start the recording." ;
	read;
	if [ "$opc44101" = "y" ]
	then
		echo 'sox -V -r 44101 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44101 -c 2 -w -s "$file.44101.wav"' > "$HOME/cddoit/$file/$file.sleeptimer.cddoit";
	else
		echo 'sox -V -r 44100 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44100 -c 2 -w -s "$file.44100.wav"' > "$HOME/cddoit/$file/$file.sleeptimer.cddoit";
	fi
	at -f "$HOME/cddoit/$file/$file.sleeptimer.cddoit" -m now;
	rm -f "$HOME/cddoit/$file/$file.sleeptimer.cddoit";
	echo "";	
	echo "RECORDING...";	
	echo "Now, the audio recording is active.";	
	if [ "$opc44101" = "y" ]
	then
		if [ "$opcconv" = "y" ]
		then
			echo "The audio conversion will be performed after the recording.";
		fi
	fi
	echo "" ;
	echo "" ;
	echo -n "The recording is found in: " ;
	echo "$HOME/cddoit/$file" ;
	PressAnyKey;
	return;
}



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

ModulesManager ()
{
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Multimedia kernel modules manager" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "";
		echo "";
		echo "::: Load/Unload dynamically kernel modules in your system ::::::::::::::::::";
		echo "";
		echo "    NOTE: Kernel modules provides funcionality for many devices.";
		echo "";
		echo "";
		echo "    1. Load a kernel module";
		echo "    2. Unload a kernel module";
		echo "    3. List of available multimedia modules";
		echo "";
		echo "    0. Back to main menu";
		echo "";
		echo -n "Choose option: ";
		read opc;
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Multimedia kernel modules manager" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "";
		echo "";
		case $opc in
			"") break;;
			0) break;;
			1)  if [ -f "$HOME/cddoit/.last_module_load.cddoit" ]
			    then
					echo -n "The last module loaded was: ";
					cat "$HOME/cddoit/.last_module_load.cddoit";
					echo "";
					echo "";
					echo "Enter the name of the module";
					echo -n "[Press ENTER to load the last module, 0: Exit]: ";
					read module;
					if [ "$module" = "" ]  # reload the last module
					then
						last_mod=`cat "$HOME/cddoit/.last_module_load.cddoit"`;
						export last_mod;
						echo "";
						echo "This operation must be performed under ROOT. Enter the password.";
						su -c '/sbin/modprobe -v $last_mod';
						PressAnyKey;
						break;
					fi
				else
					echo -n "Enter the name of the module [0: Exit]: ";
					read module;
				fi
				if [ "$module" = "0" ]
				then
					return;
				fi
				echo "";
				echo -n "Parameters of the module [Press ENTER for no parameters]: ";
				read modargs;
				export module;
				export modargs;
				echo "";
				echo "This operation must be performed under ROOT. Enter the password.";
				su -c '/sbin/modprobe -v $module io=0x$modargs';
				echo $module io=0x$modargs > "$HOME/cddoit/.last_module_load.cddoit";
				PressAnyKey;;
			2)  if [ -f "$HOME/cddoit/.last_module_load.cddoit" ]
			    then
					echo -n "The last module loaded was: ";
					cat "$HOME/cddoit/.last_module_load.cddoit";
					echo "";
					echo "";
					echo "Enter the name of the module";
					echo -n "[Press ENTER to unload the last module, 0: Exit]: ";
					read module;
					if [ "$module" = "" ]  # reload the last module
					then
						last_mod=`cat "$HOME/cddoit/.last_module_load.cddoit"`;
						export last_mod;
						echo "";
						echo "This operation must be performed under ROOT. Enter the password.";
						su -c '/sbin/modprobe -vr $last_mod';
						PressAnyKey;
						break;
					fi
				else
					echo -n "Enter the name of the module [0: Exit]: ";
					read module;
				fi
				if [ "$module" = "0" ]
				then
					return;
				fi
				export module;
				echo "";
				echo "This operation must be performed under ROOT. Enter the password.";
				su -c '/sbin/modprobe -vr $module';
				PressAnyKey;;
			3)  echo "LIST OF AVAILABLE MULTIMEDIA MODULES";
				echo "============================================================================" ;
				echo "";
				echo "WARNING: This list show only 'misc' modules.";
				echo "         Many of them may be not multimedia modules.";
				echo "";
				echo "";
				echo "You can select with the mouse and paste the name of the module later.";
				echo "Select only the name of the module, e.g:";
				echo "         In  /lib/modules/X.X.XX-XX/misc/name-module.o";
				echo "         only select 'name-module' (without .o)";
				echo "";
				echo "Press 'q' to exit the list.";
				PressAnyKey;
				echo "";
				/sbin/modprobe -l -t misc | more;
				PressAnyKey;;
		esac;
	done
	return;
}	



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

PlayAudioFormats () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Play audio files" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		echo " " ;
		echo " " ;
		echo -n "Select file to play [*: All, 0: Exit]: " ;
		read archv;
		if [ "$archv" = "0" ] || [ "$archv" = "" ]
		then
			return;
		fi
		if [ "$archv" = "*" ]
		then
			for archv in *.wav;
			do
				clear;
				echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
				echo "CDDOIT: Playing audio files" ;
				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
			clear;
			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
			echo "CDDOIT: Playing WAV files" ;
			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
			echo " " ;
			echo " " ;
			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;
}	


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

AudioRecordSpecificFormat () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Record audio in specific format" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo " " ;
		echo " " ;
		echo -n "Recording title [0: Exit]: " ;
		read file;
		export file;
		if [ "$file" = "0" ] || [ "$file" = "" ]
		then
			return;
		fi
		if [ ! -d "$HOME/cddoit/$file" ]
		then
			echo "" ;
			mkdir --verbose "$HOME/cddoit/$file" ;
			cd "$HOME/cddoit/$file";
			break ;
		else
			echo " " ;
			Beep;
			echo "WARNING: The file already exist. Enter a diferent name.";
			PressAnyKey;
		fi
	done	
	PressAnyKey;
	clear;
	echo "ENTER THE AUDIO PARAMETERS OF THE AUDIO RECORDING:" ;
	echo "==================================================" ;
	echo " " ;
	echo "\
1. Enter the audio format of the audio recording.

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.
       avr      Audio Visual Research
       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.
       sph      SPHERE  (SPeech HEader Resources)
       smp      Turtle Beach SampleVision files.
       snd      Under DOS same as the sndt format
                Under all other platforms it is the same as the .au format.
       sndt     SoundTool files. Older DOS file format.
       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, al, sl
                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', 'ulaw' (byte),"alaw" (byte),
                and "signed  long".
       auto     This is a ``meta-type'' format.
";
	echo "-You can select & paste-";
	echo -n "Enter audio format [0: Exit]: " ;
	read format;
	if [ "$format" = "0" ] || [ "$format" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Record audio in specific format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo -n "2. Enter the original sample rate (E.g: 44101 or 8000) [0: Exit]: " ;
	read rate;
	if [ "$rate" = "0" ] || [ "$rate" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Record audio in specific format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo "\
3. Enter the bits resolution of the audio recording.

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" ] || [ "$bits" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Record audio in specific format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "\
4. Enter the audio channels of the audio recording.

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" ] || [ "$channel" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Record audio in specific format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	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 ENTER 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 $rate -c $channel -t ossdsp -$bits -s /dev/dsp -t $format -r $rate -c $channel -$bits -s "$file.$format"';
		if [ "$?" = "1" ]   # if SU return bad code...
		then
			PressAnyKey;
			return;
		fi
	else
		echo " " ;
		echo "Press ENTER to start the recording." ;
		read;
		echo " " ;
		echo " " ;
		echo "Enter CTRL+C to finish the recording." ;
		echo "RECORDING...";
		echo " " ;
		sox -V -r $rate -c $channel -t ossdsp -$bits -s /dev/dsp -t $format -r $rate -c $channel -$bits -s "$file.$format";
	fi
	echo "" ;
	echo "" ;
	echo -n "The recording is found in: " ;
	echo "$HOME/cddoit/$file" ;
	GetSizeInMB;
	PressAnyKey;
	return;
}


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

GetAIFFfromCD ()
{
	clear;	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Get AIFF files from Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo " " ;
	echo " " ;
	echo "Enter the AIFF type:" ;
	echo " " ;
	echo "    1. AIFF audio file" ;
	echo "    2. AIFF-C audio file" ;
	echo " " ;
	echo -n "Type: ";
	read aifftype;
	echo " " ;
	echo " " ;
	echo "Enter tracks to extract from audio CD:" ;
	echo " " ;
	echo " " ;
	echo "	Examples of audio track extracting:" ;
	echo " " ;
	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 [Press ENTER for all CD tracks]: " ;
	read tracks;
	if [ "$tracks" = "" ]
	then
		tracks="1-";
	fi
	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 [ENTER, Maximum quality]: " ;
	read type;
	if [ "$type" = "" ]
	then
		type="1";
	fi
	echo "" ;
	echo "" ;
	case $aifftype in
		1)  case $type in
				1) cdparanoia -B -f "$tracks";;
				2) cdparanoia -Y -B -f "$tracks";;
				3) cdparanoia -Z -B -f "$tracks";;
			esac;
			;;
		2)  case $type in
				1) cdparanoia -B -a "$tracks";;
				2) cdparanoia -Y -B -a "$tracks";;
				3) cdparanoia -Z -B -a "$tracks";;
			esac;
			;;
	esac;
	if [ "$?" = "1" ]
	then
		PressAnyKey;
		return 1;
	fi
	GetSizeInMB;
	PressAnyKey;
	return ;
}



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

GetRAWfromCD ()
{
	clear;	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Get RAW files from Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo " " ;
	echo " " ;
	echo "Enter the RAW type:" ;
	echo " " ;
	echo "    1. Host byte order 16 bits PCM" ;
	echo "    2. Little-endian 16 bits PCM" ;
	echo "    3. Big-endian 16 bits PCM" ;
	echo " " ;
	echo -n "Type: ";
	read rawtype;
	echo " " ;
	echo " " ;
	echo "Enter tracks to extract from audio CD:" ;
	echo " " ;
	echo " " ;
	echo "	Examples of audio track extracting:" ;
	echo " " ;
	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 [Press ENTER for all CD tracks]: " ;
	read tracks;
	if [ "$tracks" = "" ]
	then
		tracks="1-";
	fi
	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 [ENTER, Maximum quality]: " ;
	read type;
	if [ "$type" = "" ]
	then
		type="1";
	fi
	echo "" ;
	echo "" ;
	case $rawtype in
		1)  case $type in
				1) cdparanoia -B -p "$tracks";;
				2) cdparanoia -Y -B -p "$tracks";;
				3) cdparanoia -Z -B -p "$tracks";;
			esac;
			;;
		2)  case $type in
				1) cdparanoia -B -r "$tracks";;
				2) cdparanoia -Y -B -r "$tracks";;
				3) cdparanoia -Z -B -r "$tracks";;
			esac;
			;;
		3)  case $type in
				1) cdparanoia -B -R "$tracks";;
				2) cdparanoia -Y -B -R "$tracks";;
				3) cdparanoia -Z -B -R "$tracks";;
			esac;
			;;
	esac;
	if [ "$?" = "1" ]
	then
		PressAnyKey;
		return 1;
	fi
	GetSizeInMB;
	PressAnyKey;
	return ;
}

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

Convert44101to44100 ()
{
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert 44.101 Hz to 44.000 Hz rate in WAV files" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo "";
	echo "";
	echo "NOTE: This option is special for CDDOIT recordings, so the original";
	echo "      44.101 Hz file must be in WAV format and stereo.";
	echo "      In big files this action is going to take a long time" ;
	echo "";
	echo "";
	echo -n "Enter the WAV file name: ";
	read file;
	echo "";
	echo "";
	echo -n "Remove old audio 44.101 Hz file after the conversion? [y/n]: " ;
	read opc;
	echo "";
	echo "";
	echo "Press ENTER to start the conversion.";
	read;
	echo "";
	echo "";
	echo "Converting 44.101 Hz to 44.100 Hz in WAV format...";
	echo "";
	sox -V -r 44101 -c 2 -t wav -w -s "$file" -t wav -r 44100 -c 2 -w -s "$file".44100.wav;
	if [ "$opc" = "y" ]
	then
		rm -f "$file";
	fi
	echo "";
	echo "";
	echo "Sample rate conversion finished.";
	Beep;
	PressAnyKey;
	return;
}


#******************************************************************************
GetWholeCDSingleFile ()
{
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Get the whole Audio-CD in a single audio file" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo "";
	echo "";
	echo "Enter the audio type:" ;
	echo "" ;
	echo "    1. WAV audio file" ;
	echo "    2. RAW host byte order 16 bits PCM" ;
	echo "    3. RAW little-endian 16 bits PCM" ;
	echo "    4. RAW big-endian 16 bits PCM" ;
	echo "    5. AIFF audio file" ;
	echo "    6. AIFF-C audio file" ;
	echo " " ;
	echo -n "Type [0: Exit]: ";
	read audiotype;
	if [ "$audiotype" = "0" ] || [ "$audiotype" = "" ]
	then
		return;
	fi
	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 [ENTER, Maximum quality]: " ;
	read type;
	if [ "$type" = "" ]
	then
		type="1";
	fi
	echo "";
	echo "";
	echo -n "Enter file name -without extension-: ";
	read audioname;
	echo "";
	case $audiotype in
		1)  echo "Extracting in WAV format...";
			echo "";
			case $type in
				1) cdparanoia 1- "$audioname".wav;;
				2) cdparanoia -Y 1- "$audioname".wav;;
				3) cdparanoia -Z 1- "$audioname".wav;;
			esac;
			;;
		2)  echo "Extracting in RAW host byte order 16 bits PCM format...";
			echo "";
			case $type in
				1) cdparanoia -p 1- "$audioname".raw;;
				2) cdparanoia -p -Y 1- "$audioname".raw;;
				3) cdparanoia -p -Z 1- "$audioname".raw;;
			esac;
			;;
		3)  echo "Extracting in RAW little-endian 16 bits PCM format...";
			echo "";
			case $type in
				1) cdparanoia -r 1- "$audioname".raw;;
				2) cdparanoia -r -Y 1- "$audioname".raw;;
				3) cdparanoia -r -Z 1- "$audioname".raw;;
			esac;
			;;
		4)  echo "Extracting in RAW big-endian 16 bits PCM format...";
			echo "";
			case $type in
				1) cdparanoia -R 1- "$audioname".raw;;
				2) cdparanoia -R -Y 1- "$audioname".raw;;
				3) cdparanoia -R -Z 1- "$audioname".raw;;
			esac;
			;;
		5)  echo "Extracting in AIFF format...";
			echo "";
			case $type in
				1) cdparanoia -f 1- "$audioname".aiff;;
				2) cdparanoia -f -Y 1- "$audioname".aiff;;
				3) cdparanoia -f -Z 1- "$audioname".aiff;;
			esac;
			;;
		6)  echo "Extracting in AIFF-C format...";
			echo "";
			case $type in
				1) cdparanoia -a 1- "$audioname".aifc;;
				2) cdparanoia -a -Y 1- "$audioname".aifc;;
				3) cdparanoia -a -Z 1- "$audioname".aifc;;
			esac;
			;;
	esac;
	Beep;
	GetSizeInMB;
	PressAnyKey;
	return;
}


#******************************************************************************
RenameMP3ListTracks () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Rename the MP3 file names in a directory" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	for mp3file in *.mp3;
	do
		echo "";
		echo "____________________________________________________________________________";
		echo -n "File name: ";
		echo $mp3file;
		echo "Enter the new file name -without MP3 extension- [0: Exit, 1: Keep this file]";
		echo -n "New name: ";
		read newname;
		if [ "$newname" = "0" ] || [ "$newname" = "" ]
		then
			break;
		fi
		if [ "$newname" = "1" ]
		then
			continue;
		fi
		mv -fv "$mp3file" "$newname".mp3;
	done;
	PressAnyKey;
	return;
}

#******************************************************************************
RenameAudioListTracks () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Rename the audio file names in a directory" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo "";
	echo "";
	echo -n "Enter the audio extension [without .] (e.g.: wav): ";
	read ext;
	for audiofile in *.$ext;
	do
		echo "";
		echo "____________________________________________________________________________";
		echo -n "File name: ";
		echo $audiofile;
		echo "Enter the new file name -without extension- [0: Exit, 1: Keep this file]";
		echo -n "New name: ";
		read newname;
		if [ "$newname" = "0" ] || [ "$newname" = "" ]
		then
			break;
		fi
		if [ "$newname" = "1" ]
		then
			continue;
		fi
		mv -fv "$audiofile" "$newname".$ext;
	done;
	PressAnyKey;
	return;
}



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

CancelProgramRecordStarted () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Cancel an audio program already started" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo "" ;
	echo "Active audio program:" ;
	echo " " ;
	ps -u "$USER" | grep 'sox';
	if [ "$?" = "1" ]
	then
		echo "" ;
		echo "Now, there is not CDDOIT program in execution.";
	else
		echo " " ;
		echo -n "Enter the first number of line above [0: Exit]: ";
		read numpid;
		if [ "$numpid" = "0" ] || [ "$numpid" = "" ]
		then
			return;
		fi
		kill $numpid;
		if [ "$?" = "1" ]
		then
			echo " " ;
			echo "ERROR. The number is invalid!".
			Beep;
		else
			echo " " ;
			echo "Audio program canceled.";
			echo " " ;
			echo " " ;
			echo "NOTE: Although, the audio recording was canceled, the";
			echo "      audio program is active yet. It is not necessary" ;
			echo "      cancel it, but is recommended." ;
			echo " " ;
			echo -n "Do you wish cancel the audio program now? [y/n(ENTER)]: ";
			read opc;
			if [ "$opc" = "y" ]
			then
				DelProgramRecord;
				return;
			fi
		fi
	fi
	PressAnyKey;
	return;
}

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

ViewAtJobs () {
	echo "WARNING: Maybe some program jobs are not from CDDOIT. " ;
	echo " " ;
	if [ "${1}" = "2" ] # is an audio conversion (only start job)
	then
		echo "An CDDOIT audio conversion recording program consist in one" ;
		echo "number. The start program job." ;
	else
		echo "An CDDOIT audio recording program consist in two numbers (in" ;
		echo "two consecutives lines), one for the start and the second" ;
		echo "for the finish program job." ;
	fi
	echo "" ;
	echo "Information:" ;
	echo "    a: The program job is not in execution yet." ;
	echo "    =: The program job is in execution now." ;
	echo "" ;
	echo "List of active program jobs:" ;
	echo " " ;
	atq;
	echo " " ;
	return;
}


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

ViewProgramRecords () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: View audio programs" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	ViewAtJobs ${1};
	PressAnyKey;
	return;
}


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

DelProgramRecord () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Delete an audio program" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	ViewAtJobs;
	echo "CAUTION: Be carefull, check the correct CDDOIT program jobs (see" ;
	echo "         time period) before delete it" ;
	echo " " ;
	echo -n "Enter the number of the init program job [0: Exit]: " ;
	read numjobinit;
	if [ "$numjobinit" = "0" ] || [ "$numjobinit" = "" ]
	then
		return;
	fi
	if [ "${1}" != "2" ] # is not an audio conversion (only start job)
	then
		echo -n "Enter the number of the finish program job: " ;
		read numjobend;
	fi
	echo " " ;
	echo " " ;
	echo -n "Are you sure? [y/n(ENTER)]: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		atrm $numjobinit;
		atrm $numjobend;
		echo " " ;
		echo "Program jobs: $numjobinit, $numjobend deleted.";
		echo "" ;
		echo "" ;
		echo "WARNING: Maybe this program has a CDDOIT directory asociated." ;
		echo "         If you wish in the next screen you can remove it." ;
		PressAnyKey;
		DelDir;	
	else
		PressAnyKey;
	fi
	return;
}


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

ProgramRecord () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Program an audio recording" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo " " ;
		echo " " ;
		echo "Recording is in WAV format, Stereo, 16 bits & 44.100 Hz." ;
		echo " " ;
		echo " " ;
		echo -n "Recording title [0: Exit]: " ;
		read file;
		if [ "$file" = "0" ] || [ "$file" = "" ]
		then
			return;
		fi
		if [ ! -d "$HOME/cddoit/$file" ]
		then
			echo "" ;
			mkdir --verbose "$HOME/cddoit/$file" ;
			cd "$HOME/cddoit/$file";
			echo "CDDOIT Warning" > "NO REMOVE THIS DIRECTORY.README!";
			echo "**************" >> "NO REMOVE THIS DIRECTORY.README!";
			echo "" >> "NO REMOVE THIS DIRECTORY.README!";
			echo "No delete this directory!." >> "NO REMOVE THIS DIRECTORY.README!";
			echo "This directory was created for a CDDOIT audio recording program." >> "NO REMOVE THIS DIRECTORY.README!";
			echo "If you delete the directory the audio program will be failed." >> "NO REMOVE THIS DIRECTORY.README!";
			echo "" >> "NO REMOVE THIS DIRECTORY.README!";
			echo "This warning-file will be removed automatically after audio program finished." >> "NO REMOVE THIS DIRECTORY.README!";
			echo "" >> "NO REMOVE THIS DIRECTORY.README!";
			echo "You can check the CDDOIT audio recording programs in the CDDOIT menu AUDIO." >> "NO REMOVE THIS DIRECTORY.README!";
			break;
		else
			echo " " ;
			Beep;
			echo "WARNING: The file already exist. Enter a diferent name.";
			PressAnyKey;
		fi
	done
	echo "" ;
	echo "" ;
	echo "NOTE: Press 'y' if your SOX version is older or the recording" ;
	echo "      quality is not good.";
	echo "      Default 'n'.";
	echo -n "Do you wish the audio recording in 44101 Hz [y/n(ENTER)]: ";
	read opc44101;
	PressAnyKey;
	clear;
	echo "PROGRAMMING OF AUDIO RECORDING";
	echo "==============================";
	echo "";	
	echo "WARNING: Be carefull and check:";
	echo "         . Date & time is correct in your host!";
	echo "         . When program start, the audio source must be ON";
	echo "                and your user will be in logon!";
	echo "";	
	echo "";	
	echo -n "1. Enter the date and time to start audio recording, now is ";	
	date +[%d/%m/%y][%H:%M];
	echo -n "        Year [YY]: ";
	read syear;
	echo -n "        Month [MM]: ";
	read smonth;
	echo -n "        Day [DD]: ";
	read sday;
	echo -n "        Hour [HH]: ";
	read shour;
	echo -n "        Minute [MM]: ";	
	read sminute;
	echo "";	
	echo "";	
	echo -n "2. Enter the date and time to finish audio recording, now is ";
	date +[%d/%m/%y][%H:%M];
	echo -n "        Year [YY]: ";
	read fyear;
	echo -n "        Month [MM]: ";
	read fmonth;
	echo -n "        Day [DD]: ";
	read fday;
	echo -n "        Hour [HH]: ";
	read fhour;
	echo -n "        Minute [MM]: ";	
	read fminute;
	PressAnyKey;
	if [ "$opc44101" = "y" ]
	then
		echo "" ;
		echo "" ;
		echo " WARNING: The sample rate in WAV files to CD copy is 44.100 Hz and" ;
		echo "  *****   this recording is in 44.101 Hz." ;
		echo " ** | **  You must convert to this sample rate before the CD copy." ;
		echo " ** 0 **  You can do it now or convert later in menu AUDIO, option n 10." ;
		echo "  *****   In big files this action is going to take a long time" ;
		echo "" ;
		echo -n "Do you like perform conversion to 44.100 Hz after the recording? [y/n]: " ;
		read opcconv;
		if [ "$opcconv" = "y" ]
		then
			echo "";	
			echo -n "Remove old audio 44.101 Hz file after the conversion? [y/n]: " ;
			read opcrem;
		fi
	fi
	echo "";	
	echo "";	
	echo "Saving start recording parameters...";	
	if [ "$opc44101" = "y" ]
	then
		echo "sox -V -r 44101 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44101 -c 2 -w -s \""$file.44101.wav"\"" > "$HOME/cddoit/$file/$file.start.at";
	else
		echo "sox -V -r 44100 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44100 -c 2 -w -s \""$file.44100.wav"\"" > "$HOME/cddoit/$file/$file.start.at";
	fi
	at -f "$HOME/cddoit/$file/$file.start.at" -m $shour:$sminute $sday.$smonth.$syear;
	rm -f "$HOME/cddoit/$file/$file.start.at";
	if [ "$?" = "1" ]   # AT command is not correct
	then
		echo "ERROR: the format of the start parameters is not correct.";
		rm -fr "$HOME/cddoit/$file";
		PressAnyKey;
		return;
	fi
	echo "";
	echo "";	
	echo "Saving finish recording parameters...";
	echo 'numpid=`ps -u "$USER" | grep 'sox'`' > "$HOME/cddoit/$file/$file.finish.at";
	echo 'kill $numpid' >> "$HOME/cddoit/$file/$file.finish.at";
	if [ "$opc44101" = "y" ]
	then
		if [ "$opcconv" = "y" ]
		then
			echo "sox -V -r 44101 -c 2 -t wav -w -s \""$file.44101.wav"\" -t wav -r 44100 -c 2 -w -s \""$file.44100.wav"\"" >> "$HOME/cddoit/$file/$file.finish.at";
			if [ "$opcrem" = "y" ]
			then
				echo "rm -f \"$file.44101.wav\"" >> "$HOME/cddoit/$file/$file.finish.at";
			fi
		fi
	fi
	echo 'rm -f "NO REMOVE THIS DIRECTORY.README!"' >> "$HOME/cddoit/$file/$file.finish.at";
	at -f "$HOME/cddoit/$file/$file.finish.at" -m $fhour:$fminute $fday.$smonth.$syear;
	rm -f "$HOME/cddoit/$file/$file.finish.at";
	if [ "$?" = "1" ]   # AT command is not correct
	then
		echo "ERROR: the format of the finish parameters is not correct.";
		rm -fr "$HOME/cddoit/$file";
		PressAnyKey;
		return;
	fi
	echo "";	
	echo "";	
	if [ "$opc44101" = "y" ]
	then
		if [ "$opcconv" = "y" ]
		then
			echo "The conversion will be started after the recording finished.";
			echo "";	
		fi
	fi
	echo "The start and finish parameters were saved OK.";	
	echo "The audio recording is scheduled OK.";
	echo "" ;
	echo "After the recording, you can check the output messages in your mail!";
	echo -n "The audio recording will be found in: " ;
	echo "$HOME/cddoit/$file" ;
	PressAnyKey;
	return;
}



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

GetMP3fromCD () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Get MP3 files from Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	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 [ENTER, Maximum quality]: " ;
	read type;
	if [ "$type" = "" ]
	then
		type="1";
	fi
	echo " " ;
	echo " " ;
	echo "Enter tracks to extract from audio CD:" ;
	echo " " ;
	echo " " ;
	echo "	Examples of audio tracks extracting:" ;
	echo " " ;
	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 [Press ENTER for all CD tracks]: " ;
	read tracks;
	if [ "$tracks" = "" ]
	then
		tracks="1-";
	fi
	del="-del";
	empty="";
	if [ "$tracks" = "1-" ]
	then
		cdparanoia -Q 2> $HOME/cddoit/.cdnumtracks.cddoit;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
		numtracks=`cat $HOME/cddoit/.cdnumtracks.cddoit | grep -1 "TOTAL" | grep -v "(" | cut -b -3`;
		rm -f $HOME/cddoit/.cdnumtracks.cddoit;
		echo " " ;
		echo " " ;
		echo "Total number of audio tracks in the CD: $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;
			if [ "$?" = "1" ]
			then
				PressAnyKey;
				return 1;
			fi
			track=`expr ${track} + 1`;
			WAV2MP3Conversion $value *.wav $empty $del;
		done
	else
		echo " " ;
		echo " " ;
		case $type in
			1) cdparanoia -B "$tracks";;
			2) cdparanoia -Y -B "$tracks";;
			3) cdparanoia -Z -B "$tracks";;
		esac;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
		for wavfile in *.wav;
		do
			WAV2MP3Conversion $value "$wavfile" $empty $del;
		done;
	fi
	Beep;
	GetSizeInMB;
	echo "" ;
	echo "" ;
	echo -n "Do you like to rename the new MP3 file names? [y/n]: " ;
	read opc;
	if [ "$opc" = "y" ]
	then
		RenameMP3ListTracks;
	else
		PressAnyKey;
		return ;
	fi
}



#******************************************************************************
GetWAVfromCD () {
	clear;	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: 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 "	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 [Press ENTER for all CD tracks]: " ;
	read tracks;
	if [ "$tracks" = "" ]
	then
		tracks="1-";
	fi
	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 [ENTER, Maximum quality]: " ;
		read type;
		if [ "$type" = "" ]
		then
			type="1";
		fi
		echo "" ;
		echo "" ;
		case $type in
			1) cdparanoia -B "$tracks";;
			2) cdparanoia -Y -B "$tracks";;
			3) cdparanoia -Z -B "$tracks";;
		esac;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
	fi
	GetSizeInMB;
	PressAnyKey;
	return ;
}


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

AudioRecord () {
# parameters:  1  CD copy format recording (44100)
#              2  recording to 44101 Hz 
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Record audio in WAV format" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo " " ;
		echo " " ;
		if [ "${1}" = "2" ]
		then
			echo "Recording is in WAV format, Stereo, 16 bits & 44.101 Hz." ;
			echo "";
			echo "NOTE: This option is only for compatibility with some soundcards";
			echo "      and old versions of SOX";
			echo "      Use this option only if you detect errors in the 44.100 Hz";
			echo "      audio recording";
		else
			echo "Recording is in WAV format, Stereo, 16 bits & 44.100 Hz.";
		fi
		echo " " ;
		echo " " ;
		echo -n "Recording title [0: Exit]: " ;
		read file;
		export file;
		if [ "$file" = "0" ] || [ "$file" = "" ]
		then
			return;
		fi
		if [ ! -d "$HOME/cddoit/$file" ]
		then
			echo "" ;
			mkdir --verbose "$HOME/cddoit/$file" ;
			cd "$HOME/cddoit/$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
		cdformat=${1};
		export cdformat;
		echo "Enter the ROOT password." ;
		su -c '
		echo " " ;
		echo "Press ENTER to start the recording." ;
		read;
		echo " " ;
		echo " " ;
		echo "Enter CTRL+C to finish the recording." ;
		echo "RECORDING WITH MAXIMUM PRIORITY [ROOT]...";
		echo " " ;
		if [ "cdformat" = "2" ]
		then
			sox -V -r 44101 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44101 -c 2 -w -s "$file.44101.wav"
		else
			sox -V -r 44100 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44100 -c 2 -w -s "$file.44100.wav"
		fi';
		if [ "$?" = "1" ]   # if SU return bad code...
		then
			PressAnyKey;
			return;
		fi
	else
		echo " " ;
		echo "Press ENTER to start the recording." ;
		read;
		echo " " ;
		echo " " ;
		echo "Enter CTRL+C to finish the recording." ;
		echo "RECORDING...";
		echo " " ;
		if [ "${1}" = "2" ]
		then
			sox -V -r 44101 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44101 -c 2 -w -s "$file.44101.wav";
		else
			sox -V -r 44100 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44100 -c 2 -w -s "$file.44100.wav";
		fi
	fi
	if [ "${1}" = "2" ]
	then
		echo "" ;
		echo "" ;
		echo " WARNING: The sample rate in WAV files to CD copy is 44.100 Hz and" ;
		echo "  *****   this recording is in 44.101 Hz." ;
		echo " ** | **  You must convert to this sample rate before the CD copy." ;
		echo " ** 0 **  You can do it now or convert later in menu AUDIO, option n 10." ;
		echo "  *****   In big files this action is going to take a long time" ;
		echo "" ;
		echo -n "Do you like perform conversion to 44.100 Hz now? [y/n]: " ;
		read opc;
		if [ "$opc" = "y" ]
		then
			echo "";
			echo "";
			sox -V -r 44101 -c 2 -t wav -w -s "$file".44101.wav -t wav -r 44100 -c 2 -w -s "$file".44100.wav;
			echo "";
			echo "Sample rate conversion finished.";
			echo "";
			Beep;
			echo -n "Remove old audio 44.101 Hz file after the conversion? [y/n]: " ;
			read opc;
			if [ "$opc" = "y" ]
			then
				echo "";
				rm -vf "$file.44101.wav";
			fi
		fi
	fi
	echo "" ;
	echo "" ;
	echo -n "The recording is found in: " ;
	echo "$HOME/cddoit/$file" ;
	GetSizeInMB;
	PressAnyKey;
	return;
}

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

DataDirectCopy () {
	cd "$HOME/cddoit/cddata";
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	#copia real (no dummy)
	then
		echo "CDDOIT: Data-CD direct copy to CD (Create data image and copy)";
	else
		echo "CDDOIT: Data-CD direct dummy copy to CD (Create data image and dummy copy)";
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "Insert the source and target CDs.";
	PressAnyKey;
	CleanDataTempDir;
	echo "";
	echo "";
	echo "The copy must be performed under ROOT. Enter the password." ;
	if [ "${1}" = "1" ]	# copia real
	then
		su -c 'echo "" ; echo "Creating the CD image..." ; cat /dev/cdrom > image.raw ; cdrecord -v -eject image.raw' ;
	else	# mode dummy
		su -c 'echo "" ; echo "Creating the CD image..." ; cat /dev/cdrom > image.raw ; cdrecord -v -dummy -eject image.raw' ;
	fi			
	echo "";
	PressAnyKey;
	return ;
}




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

OntheflyDataCopy () {
#arguments: 1:  real copy, rest: dummy copy
	cd "$HOME/cddoit/cddata";
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "CDDOIT: On-the-fly Data-CD copy to CD";
	else
		echo "CDDOIT: On-the-fly Data-CD dummy copy to CD";
	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 "****************************************************************************";
	echo "" ;
	echo "" ;
	echo "Insert the source and target CDs.";
	PressAnyKey;
	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 0;
}



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

Image2cd () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "CDDOIT: Copy data image file to CD-R";
	else
		echo "CDDOIT: Dummy copy data image file to CD-R";
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	while true;
	do
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		if [ ! -f "image.raw" ]
		then
			echo "";
			echo "";
			echo "ERROR: Data image file [image.raw] not found!";
			echo "       Enter the correct path.";
			Beep;
			PressAnyKey;
		else
			break;
		fi
	done
	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
	if [ "$?" != "1" ] # No error on SU
	then
		echo "" ;
		echo "" ;
		echo "Data copy finished." ;
		echo "" ;
		echo -n "Do you like delete the Data Image file [image.raw]? [y/n]: ";
		read opc;
		if [ "$opc" = "y" ]
		then
			echo "" ;
			rm -fv image.raw;
		fi
	fi
	PressAnyKey;
	return ;
}

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

GetImage () {
	cd "$HOME/cddoit/cddata";
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "CDDOIT: Create data image file" ;
	else
		echo "CDDOIT: Create multisession data image file" ;
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	DirOrg=$PWD;
	DirDest=$PWD;
	HomeUser=$HOME;
	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
	echo " " ;
	echo " " ;
	echo "NOTE: If you wish, in the CD-R, the files inside the directory";
	echo "      then press 'Y' otherwise the files will be copied in the" ;
	echo "      first level." ;
	echo " " ;
	echo -n "Do you wish include the directory $DirOrg in the copy? [y/n]: ";
	read opc;
	if [ "$opc" != "y" ]
	then
		cd "$DirOrg";
		DirOrg=$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.";
		mkdir "$HOME/cddoit/dirmulti";
		ln -s "$DirOrg" "$HOME/cddoit/dirmulti";
		echo "";
		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 "";
			mkisofs -R -J -f -o "$DirDest/image.raw" "$HOME/cddoit/dirmulti";
		else
			export DirOrg;
			export DirDest;
			export HomeUser;
			echo "";
			echo "";
			echo "To create 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;
			echo "";
			echo "";
			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 "";
mkisofs -R -J -f -o "$DirDest/image.raw" -C $msinfo -M $cdrdevice "$HomeUser/cddoit/dirmulti";'
			if [ "$?" = "1" ]
			then
				PressAnyKey;
				return ;
			fi
		fi
		rm -fr "$HOME/cddoit/dirmulti";
	else    # no multisession
		echo " " ;
		echo " " ;
		echo "Creating data image file..." ;
		echo " " ;
		mkisofs -R -J -f -o "$DirDest/image.raw" "$DirOrg";
	fi
	cd "$DirDest";
	GetSizeInMB;
	echo -n "Data image file is found in: ";
	pwd;
	PressAnyKey;
	return ;
}


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

MP3toCD () {
	CleanAudioTempDir;
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		if [ "${1}" = "1" ]	# real copy (no dummy)
		then
			echo "CDDOIT: MP3 files to CD-R copy" ;
		else
			echo "CDDOIT: 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" ] || [ "$archvmp3" = "" ]
		then
			return;
		fi
		if [ "$archvmp3" = "*" ]
		then
			for archv in *.mp3;
			do
				mpg123 -s -r 44100 "$archv" > "$HOME/cddoit/cdaudio/$archv.raw";
				sox -t raw -r 44100 -c 2 -w -s "$HOME/cddoit/cdaudio/$archv.raw"  -r 44100 -c 2 -t wav -w -s "$HOME/cddoit/cdaudio/$archv.wav" ;
				rm -f "$HOME/cddoit/cdaudio/$archv.raw" ;
			done ;
			GetSizeInMB;
			break;
		else
			if [ -f "$HOME/cddoit/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/cddoit/cdaudio/$archvmp3.raw" ;
		  		  sox -t raw -r 44100 -c 2 -w -s "$HOME/cddoit/cdaudio/$archvmp3.raw"  -r 44100 -c 2 -t wav -w -s "$HOME/cddoit/cdaudio/$archvmp3.wav";
					rm -f "$HOME/cddoit/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/cddoit/cdaudio" ;
	while true;
	do
		CopyCD ${1};
		if [ "$?" = "1" ] # CopyCD error (possible SU error)
		then
			echo "";
			echo "ERROR. CD-Copy could not be started.";
			echo "       Possible incorrect ROOT password.";
			Beep;
			echo "";
			echo -n "Re-enter the password again? [y/n]: ";
			read opc;
			if [ "$opc" != "y" ]
			then
				break;
			fi
		else
			break;
		fi
	done
	CleanAudioTempDir;
	Beep;
	echo "";
	echo "";
	echo "Copy finished.";
	PressAnyKey;
	return 0;
}

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

AudioCopy () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "CDDOIT: WAV files to CD-R copy" ;
	else
		echo "CDDOIT: WAV files to CD-R DUMMY copy" ;
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	dir=`pwd`;
	echo " " ;
	echo " " ;
	echo -n "Enter speed of copy (ENTER, Default speed): " ;
	read speed;
	export speed;
	echo " " ;
	echo "DAO: The audio tracks are recorded without 4 seconds between us. (Default)";
	echo "     If your CD-Recorder can record in DAO mode (very possible), press ENTER.";
	echo -n "Do you like a DAO recording? [y(ENTER)/n]: ";
	read dao;
	export dao;
	GetCDRecordable;
	while true;
	do
		CopyCD ${1};
		if [ "$?" = "1" ] # CopyCD error (possible SU error)
		then
			echo "";
			echo "ERROR. CD-Copy could not be started.";
			echo "       Possible incorrect ROOT password.";
			Beep;
			echo "";
			echo -n "Re-enter the password again? [y/n]: ";
			read opc;
			if [ "$opc" != "y" ]
			then
				break;
			fi
		else
			break;
		fi
	done
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "";
		echo "";
		echo "CD audio copy finished.";
		echo "The originals WAV files are in $dir.";
		echo -n "Do you wish remove the $dir directory now? [y/n(ENTER)]: ";
		read opc;
		if [ "$opc" = "y" ]
		then
			echo "";
			rm -frv $dir;
		fi
	fi
	PressAnyKey;
	return 0;
}

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

AudioDirectCopy () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]
	then
		echo "CDDOIT: Direct Audio CD copy to CD-R" ;
	else
		echo "CDDOIT: Direct Audio CD DUMMY copy to CD-R" ;
	fi
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "NOTE: If your hard disk no have enough free space, use the the multisession";
	echo "      audio direct copy in menu AUDIO CD-R, option n 10.";
	cd "$HOME/cddoit/cdaudio"
	CleanAudioTempDir;
	GetOriginalCD;
	GetCDRecordable;
	while true;
	do
		if [ "${1}" = "1" ]
		then
			home2="$HOME";
			export home2;
			CopyCD 5;
		else
			CopyCD 14; # dummy copy
		fi
		if [ "$?" = "1" ] # CopyCD error (possible SU error)
		then
			echo "";
			echo "ERROR. CD-Copy could not be started.";
			echo "       Possible incorrect ROOT password.";
			Beep;
			echo "";
			echo -n "Re-enter the password again? [y/n]: ";
			read opc;
			if [ "$opc" != "y" ]
			then
				break;
			fi
		else
			break;
		fi
	done
	CleanAudioTempDir;
	PressAnyKey;
	return;
}


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

CreateDirByDefault () {
# go to CDDOIT directory and if it is not found, create it
	if [ ! -d "$HOME/cddoit" ]
	then
		clear;
		echo "\

Welcome to CDDOIT 1.5!

Author:  Jose L. Diaz.
April/2003

Homepage: http://www.geocities.com/cddoit/index.html

This is free software.
Only, I would like to know in many countries of the world CDDOIT is being
used, for that reason would be thankful to you that you sent me a mail
(cddoit@yahoo.com) indicating only your country and city.
All mails will be replied when new versions appears.
Thanks in advance.

I am from Madrid, Spain.

Report bugs or suggestions to: cddoit@yahoo.com
This software comes with NO warranty of any kind. Use at your own risk.


--------------------------------------------------------------
WARNING: For a correct CDDOIT funcionality, you must
         configure properly the CDRECORD configuration file in
         menu OTHERS, option n 10.
--------------------------------------------------------------";
		PressAnyKey;
		mkdir "$HOME/cddoit";
	fi
	if [ ! -d "$HOME/cddoit/cdaudio" ]
	then
		mkdir "$HOME/cddoit/cdaudio";
	fi
	if [ ! -d "$HOME/cddoit/cddata" ]
	then
		mkdir "$HOME/cddoit/cddata";
	fi
	if [ ! -d "$HOME/cddoit/log" ]
	then
		mkdir "$HOME/cddoit/log";
	fi
}

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

GetDirWavTracks () {
# show the existing directories
	echo "" ;
	echo "" ;
	echo "CDDOIT directories:" ;
	echo "____________________________________________________________________________" ;
	ls -Cm --color "$HOME/cddoit" ;
	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" ] || [ "$nomdir" = "" ]
	then
		return 1;
	fi
	if [ ! -d "$HOME/cddoit/$nomdir" ]
	then
		echo "" ;
		mkdir --verbose "$HOME/cddoit/$nomdir" ;
		cd "$HOME/cddoit/$nomdir";
	else
		echo " " ;
		echo "WARNING: The directory already exist and may contain files.";
		echo " " ;
		cd "$HOME/cddoit/$nomdir";
		echo "Files in "$HOME/cddoit/$nomdir" :" ;
		echo "____________________________________________________________________________" ;
		ls -C;
		echo "____________________________________________________________________________" ;
		PressAnyKey;
	fi
}

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

GetWavTrackByTrack () {
# extract tracks running cdparanoia once per track. Better quality
	cdparanoia -Q 2> $HOME/cddoit/.cdnumtracks.cddoit;
	if [ "$?" = "1" ]
	then
		PressAnyKey;
		return 1;
	fi
	numtracks=`cat $HOME/cddoit/.cdnumtracks.cddoit | grep -1 "TOTAL" | grep -v "(" | cut -b -3`;
	rm -f $HOME/cddoit/.cdnumtracks.cddoit;
	echo " " ;
	echo " " ;
	echo "Total number of audio tracks in the CD: $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 [ENTER, Maximum quality]: " ;
	read type;
	if [ "$type" = "" ]
	then
		type="1";
	fi
	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;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
		track=`expr ${track} + 1`;
	done
	Beep;
}

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

GetSizeInMB () {
# argument:  ${1}  a directory
# if argument is not included, the actual directory size is view.

	echo " " ;
	echo " " ;
	echo -n "Size in MBytes: "
	if [ "${1}" != "" ]
	then
		du -h "${1}";
	else
		pwd | du -h;
	fi
}

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

PressAnyKey () {
	echo "";
	echo "";
	echo -n "|= Press ENTER to continue ==>";
	read;
	return;
}

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

GoToDir () {
	while true;
	do
		echo "" ;
		echo "" ;
		echo "CDDOIT directories:" ;
		echo "____________________________________________________________________________" ;
		ls -Cm --color "$HOME/cddoit" ;
		echo "____________________________________________________________________________" ;
		echo "-Select with mouse and paste the directory or enter the complete path-";
		echo " " ;
		echo -n "Enter the directory where the original files are [0: Exit]: " ;
		read nomdir;
		if [ "$nomdir" != "0" ] && [  "$nomdir" != "" ]
		then
			if [ -d "$HOME/cddoit/$nomdir" ]
			then
				cd "$HOME/cddoit/$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 *;
	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
	if [ "$dao" = "n" ]
	then
		cdrecord -v -eject -pad -audio *.wav;
	else
		cdrecord -v -dao -eject -shorttrack -pad -audio *.wav;
	fi
else
	if [ "$dao" = "n" ]
	then
		cdrecord -v -eject speed=$speed -pad -audio *.wav;
	else
		cdrecord -v -dao -eject speed=$speed -shorttrack -pad -audio *.wav;
	fi
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 -v -dummy -dao -eject -shorttrack -pad -audio *.wav;
else
	cdrecord -v -dummy -dao -eject speed=$speed -shorttrack -pad -audio *.wav;
fi';;
		5) su -c '
cdparanoia -Q 2> $home2/cddoit/.cdnumtracks.cddoit;
if [ "$?" = "1" ]
then
	PressAnyKey;
	return 1;
fi
numtracks=`cat $home2/cddoit/.cdnumtracks.cddoit | grep -1 "TOTAL" | grep -v "(" | cut -b -3`;
rm -f $home2/cddoit/.cdnumtracks.cddoit;
echo " " ;
echo " " ;
echo "Total number of audio tracks in the CD: $numtracks";
echo " " ;
echo " " ;
echo -n "Enable CD copy log? [y/n(ENTER)]: " ;
read log;
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 [ENTER, Maximum quality]: " ;
read type;
if [ "$type" = "" ]
then
	type="1";
fi
echo " " ;
echo -n "Enter speed of copy (ENTER, Default speed): " ;
read speed;
echo " " ;
echo "DAO: The audio tracks are recorded without 4 seconds between us. (Default)";
echo "     If your CD-Recorder can record in DAO mode (is very possible) press ENTER.";
echo -n "Do you like a DAO recording? [y(ENTER)/n]: ";
read dao;
echo " " ;
echo " " ;
echo -n "Extracting CD tracks... ";
echo " " ;
echo " " ;
logid=`date +%d-%m-%y.%H:%M`;
track=1;

# check for multisession direct audio cd copy
if [ "$DirectCopyMulti" = "y" ]
then
	while [ "$track" -le "$numtracks" ];
	do
		case $type in
			1) cdparanoia -B "$track";;# 2> "$home2"/cddoit/log/$logid.cdcopy.cddoit.log;;
			2) cdparanoia -Y -B "$track";;#  2> "$home2"/cddoit/log/$logid.cdcopy.cddoit.log;;
			3) cdparanoia -Z -B "$track";;#  2> "$home2"/cddoit/log/$logid.cdcopy.cddoit.log;;
		esac;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
		if [ "$speed" = "" ]
		then
			cdrecord -v -nofix -pad -audio *.wav | tee -a "$home2"/cddoit/log/$logid.cdcopy.cddoit.log;
		else
			cdrecord -v speed=$speed -nofix -pad -audio *.wav | tee -a "$home2"/cddoit/log/$logid.cdcopy.cddoit.log;
		fi
		rm -f *.wav;
		track=`expr ${track} + 1`;
	done
	# closing the audio CD
	cdrecord -v -eject -fix;
	DirectCopyMulti="";
else
	while [ "$track" -le "$numtracks" ];
	do
		case $type in
			1) cdparanoia -B "$track";;# 2> "$home2"/cddoit/log/$logid.cdcopy.cddoit.log;;
			2) cdparanoia -Y -B "$track";;#  2> "$home2"/cddoit/log/$logid.cdcopy.cddoit.log;;
			3) cdparanoia -Z -B "$track";;#  2> "$home2"/cddoit/log/$logid.cdcopy.cddoit.log;;
		esac;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
		track=`expr ${track} + 1`;
	done
	if [ "$speed" = "" ]
	then
		if [ "$dao" = "n" ]
		then
			cdrecord -v -eject -pad -audio *.wav | tee -a "$home2"/cddoit/log/$logid.cdcopy.cddoit.log;
		else
			cdrecord -v -dao -eject -shorttrack -pad -audio *.wav | tee -a "$home2"/cddoit/log/$logid.cdcopy.cddoit.log;
		fi
	else
		if [ "$dao" = "n" ]
		then
			cdrecord -v -eject speed=$speed -pad -audio *.wav | tee -a "$home2"/cddoit/log/$logid.cdcopy.cddoit.log;
		else
			cdrecord -v -dao -eject speed=$speed -shorttrack -pad -audio *.wav | tee -a "$home2"/cddoit/log/$logid.cdcopy.cddoit.log;
		fi
	fi
fi
# The LOG copy
if [ "$log" != "y" ] && [ "$log" != "Y" ]
then
	rm -f "$home2"/cddoit/log/$logid.cdcopy.cddoit.log;
else
	echo "";
	echo "";
	echo "The CD copy log file is: $logid.cdcopy.cddoit.log";
	echo "                     in: "$home2"/cddoit/log";
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 'mount /dev/cdrom /mnt/cdrom; mkisofs -R -J -f /mnt/cdrom | cdrecord -v - ; umount /dev/cdrom';;  # onthefly copy
		9) su -c 'mount /dev/cdrom /mnt/cdrom; mkisofs -R -J -f /mnt/cdrom | cdrecord -v -dummy - ; umount /dev/cdrom';;   # 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 [ "$archwav" = "*" ]   # copy all files from the directory in multisession
then
	for wavfile in *.wav
	do
		if [ "$speed" = "" ]
		then
			cdrecord -v -eject -nofix -pad -audio "$wavfile";
		else
			cdrecord -v -eject speed=$speed -nofix -pad -audio "$wavfile";
		fi
		echo "";
		echo "";
	done
else
	if [ "$speed" = "" ]
	then
		cdrecord -v -eject -nofix -pad -audio "$archwav";
	else
		cdrecord -v -eject speed=$speed -nofix -pad -audio "$archwav";
	fi
fi';;
		13) su -c '
if [ "$archwav" = "*" ]   # copy all files from the directory in multisession
then
	for wavfile in *.wav
	do
		if [ "$speed" = "" ]
		then
			cdrecord -v -eject -nofix -pad -dummy -audio "$wavfile";
		else
			cdrecord -v -eject speed=$speed -nofix -pad -dummy -audio "$wavfile";
		fi
		echo "";
		echo "";
	done
else
	if [ "$speed" = "" ]
	then
		cdrecord -v -eject -nofix -pad -dummy -audio "$archwav";
	else
		cdrecord -v -eject speed=$speed -nofix -pad -dummy -audio "$archwav";
	fi
fi';;
		14) su -c '
cdparanoia -Q 2> $home2/cddoit/.cdnumtracks.cddoit;
if [ "$?" = "1" ]
then
	PressAnyKey;
	return 1;
fi
numtracks=`cat $home2/cddoit/.cdnumtracks.cddoit | grep -1 "TOTAL" | grep -v "(" | cut -b -3`;
rm -f $home2/cddoit/.cdnumtracks.cddoit;
echo " " ;
echo " " ;
echo "Total number of audio tracks in the CD: $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 [ENTER, Maximum quality]: " ;
read type;
if [ "$type" = "" ]
then
	type="1";
fi
echo " ";
echo -n "Enter speed of copy (ENTER, Default speed): " ;
read speed;
echo " " ;
echo "DAO: The audio tracks are recorded without 4 seconds between us. (Default)";
echo "     If your CD-Recorder can record in DAO mode (is very possible) press ENTER.";
echo -n "Do you like a DAO recording? [y(ENTER)/n]: ";
read dao;
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;
	if [ "$?" = "1" ]
	then
		PressAnyKey;
		return 1;
	fi
	track=`expr ${track} + 1`;
done
if [ "$speed" = "" ]
then
	if [ "$dao" = "n" ]
	then
		cdrecord -v -eject -dummy -pad -audio *.wav;
	else
		cdrecord -v -dao -eject -dummy -shorttrack -pad -audio *.wav;
	fi	
else
	if [ "$dao" = "n" ]
	then
		cdrecord -v -eject -dummy speed=$speed -pad -audio *.wav;
	else
		cdrecord -v -dao -eject -dummy speed=$speed -shorttrack -pad -audio *.wav;
	fi
fi';;
	esac;
	if [ "$?" = "1" ]   # if SU return an error code, CopyCD return 1
	then
		return 1;
	fi
}


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

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

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

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

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

CreateDirectory () {
	while true;
	do
		echo " " ;
		echo " " ;
		echo "Directory creation:" ;
		echo "Enter directory name (without PATH)" ;
		echo -n "where the files will be stored [0: Exit]: "
		read nomdir;
		if [ "$nomdir" = "0" ] || [ "$nomdir" = "" ]
		then
			return 1;
		fi
		if [ ! -d "$HOME/cddoit/$nomdir" ]
		then
			echo "" ;
			mkdir --verbose "$HOME/cddoit/$nomdir" ;
			cd "$HOME/cddoit/$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 the conversion the original WAV files are deleted
# arguments:
#	${1} MP3 quality -Kb/seg-
#	${2} the original file to convert
#    ${3} the output file (optional)
#    ${4} flag: the original WAV file will be removed after the conversion

	echo "Init MP3 conversion..." ;
	case ${1} in
		1) bladeenc ${4} -br 128 -crc "${2}" "${3}";;
		2) bladeenc ${4} -br 320 -crc "${2}" "${3}";;
	esac;
	echo "" ;
	echo "MP3 conversion finished." ;
}


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

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

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

GetWAVfromSeveralCD () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Get WAV files from several Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo "" ;
	echo "" ;
	echo "NOTE: The extraction secuence will be the audio tracks secuence in the copy CD." ;
	numtrack=1;
	# count the number of audio tracks in the directory
	TracksInDir=`ls -l *.wav | wc -l`;
	if [ "$TracksInDir" -ne "0" ]
	then
		echo "" ;
		echo "" ;
		echo "WARNING: There are $TracksInDir WAV files in the directory.";
		echo -n "         Do you wish get the next track with the `expr $TracksInDir + 1`th number? [y(ENTER)/n] ";
		read opc;
		if [ "$opc" != "n" ] || [ "$opc" != "N" ]
		then
			numtrack=`expr $TracksInDir + 1`;
		fi
	fi
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Get WAV files from several Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo "Insert Audio CD";
	echo -n "and enter the CD track number [0: Exit]: ";
	read track;
	if [ "$track" = "0" ] || [ "$track" = "" ]
	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;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
		echo " " ;
		if [ "$numtrack" -lt "10" ]
		then
			mv track*."$nametrack".wav 0$numtrack-"$nametrack".wav;
		else
			mv track*."$nametrack".wav $numtrack-"$nametrack".wav;
		fi
		numtrack=`expr $numtrack + 1`;
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Get WAV files from several Audio-CD" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GetSizeInMB;
		secs=0;
		GetWavSecsDir;
		echo "Current duration in Minutes (+-): $(($secs / 60)) Minutes";
		echo "                    Seconds (exact): $secs Seconds";
		echo " " ;
		echo "NOTE:    Audio CD 74 minutes are $((74 * 60)) Seconds";
		echo "         Audio CD 80 minutes are $((80 * 60)) Seconds";
		echo " " ;
		if [ "$secs" -gt "$((74 * 60))" ]
		then
			echo "WARNING: You are rippering over 74 minutes now!";
		fi
		if [ "$secs" -gt "$((80 * 60))" ]
		then
			echo "WARNING: You are rippering over 80 minutes now!!!";
			echo "         Very possible Out of CD Space Error in your CD copy!" ;
			echo "         Try to delete extra WAV files."
		fi
		echo " " ;
		echo " " ;
		echo " " ;
		echo " " ;
		echo "Enter a new CD track number or";
		echo -n "insert new Audio CD and enter the CD track number [0: Exit]: ";
		read track;
		if [ "$track" = "0" ] || [ "$track" = "" ]
		then
			break;
		fi
	done
	echo "";
	echo -n "WAV files from Audio-CD are found in: " ;
	pwd;
	echo "";
	echo "";
	echo -n "Do you like perform the WAV to CD copy now? [y/n(ENTER)]: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		while true;
		do
			CopyCD 1;
			if [ "$?" = "1" ] # CopyCD error (possible SU error)
			then
				echo "";
				echo "ERROR. CD-Copy could not be started.";
				echo "       Possible incorrect ROOT password.";
				Beep;
				echo "";
				echo -n "Re-enter the password again? [y/n]: ";
				read opc;
				if [ "$opc" != "y" ]
				then
					break;
				fi
			else
				break;
			fi
		done
	fi
	return 0;
}

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

GetMP3fromSeveralCD () {

	del="-del";
	empty="";

	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Get MP3 files from several Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo "" ;
	echo "" ;
	echo "NOTE: The extraction secuence will be the audio tracks secuence in the copy CD." ;
	numtrack=1;
	# count the number of audio tracks in the directory
	TracksInDir=`ls -l *.mp3 | wc -l`;
	if [ "$TracksInDir" -ne "0" ]
	then
		echo "" ;
		echo "" ;
		echo "WARNING: There are $TracksInDir MP3 files in the directory.";
		echo -n "         Do you wish get the next track with the `expr $TracksInDir + 1`th number? [y(ENTER)/n] ";
		read opc;
		if [ "$opc" != "n" ] || [ "$opc" != "N" ]
		then
			numtrack=`expr $TracksInDir + 1`;
		fi
	fi
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Get MP3 files from several Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "Insert Audio CD";
	echo -n "and enter the CD track number [0: Exit]: ";
	read track;
	if [ "$track" = "0" ] || [ "$track" = "" ]
	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;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
		if [ "$numtrack" -lt "10" ]
		then
			mv track*."$nametrack".wav 0$numtrack-"$nametrack".wav;
		else
			mv track*."$nametrack".wav $numtrack-"$nametrack".wav;
		fi
		numtrack=`expr $numtrack + 1`;
		Beep;
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Get MP3 files from several Audio-CD" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GetSizeInMB;
		echo " " ;
		echo "Enter a new CD track number or";
		echo -n "insert new Audio CD and enter the CD track number [0: Exit]: ";
		read track;
		if [ "$track" = "0" ] || [ "$track" = "" ]
		then
			break;
		fi
	done
	Beep;
	echo "Tracks selection finished." ;
	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 "";
	for wavfile in *.wav;
	do
		WAV2MP3Conversion $value "$wavfile" $empty $del;
	done;
	echo " " ;
	echo -n "MP3 files from Audio-CD are found in: " ;
	pwd;
	PressAnyKey;
	return ;
}


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

DelDir () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Delete a CDDOIT 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(ENTER)]: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		echo "";
		rm -rvf "$PWD";
		# creating CDDOIT standard temporary files
		if [ ! -d "$HOME/cddoit/cdaudio" ]
		then
			mkdir "$HOME/cddoit/cdaudio";
		fi
		if [ ! -d "$HOME/cddoit/cddata" ]
		then
			mkdir "$HOME/cddoit/cddata";
		fi
		if [ ! -d "$HOME/cddoit/log" ]
		then
			mkdir "$HOME/cddoit/log";
		fi
		PressAnyKey;
	fi
	return;
}


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

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

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

PlayWAV () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: 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" ] || [ "$archv" = "" ]
		then
			return;
		fi
		if [ "$archv" = "*" ]
		then
			for archv in *.wav;
			do
				clear;
				echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
				echo "CDDOIT: Playing WAV files" ;
				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
			clear;
			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
			echo "CDDOIT: Playing WAV files" ;
			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
			echo " " ;
			echo " " ;
			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 "CDDOIT: Play MP3 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" ] || [ "$archv" = "" ]
		then
			return;
		fi
		if [ "$archv" = "*" ]
		then
			for archv in *.mp3;
			do
				clear;
				echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
				echo "CDDOIT: Play MP3 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 "CDDOIT: Convert WAV files to MP3 format" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GetDirWavTracks;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		DirDest=$PWD;
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		DirOrg=$PWD;
		echo " " ;
		echo " " ;
		echo -n "Select the file [*: All, 0: Exit]: " ;
		read archvwav;
		if [ "$archvwav" = "0" ] || [ "$archvwav" = "" ]
		then
			return;
		fi
		echo "" ;
		echo "" ;
		echo -n "Do you wish to remove the original WAV files after the conversion? [y/n]: ";
		read opc;
		if [ "$opc" = "y" ]
		then
			DelWav="-del";
		else
			DelWav="";
		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
		cd "$DirDest";
		echo " " ;
		echo " " ;
		if [ "$archvwav" = "*" ]
		then
			cd "$DirOrg";
			for archv in *.wav;
			do
				WAV2MP3Conversion $value "$DirOrg/$archv" "$DirDest/$archv.mp3" "$DelWav";
			done ;
			break;
		else
			if [ -f "$DirDest/$archvwav.mp3" ]
			then
				Beep;
				echo -n "WARNING: ";
				echo -n "$archvwav";
				echo "  was converted before.";
				PressAnyKey;
			else
				if [ ! -f "$DirOrg/$archvwav" ]
				then
					Beep;
					echo "ERROR: File not found.";
					PressAnyKey;
				else
					WAV2MP3Conversion $value "$DirOrg/$archvwav" "$DirDest/$archvwav.mp3" "$DelWav";
					break;
				fi
			fi
		fi
	done
	echo " " ;
	echo " " ;
	echo -n "The MP3 files are found in: " ;
	echo "$DirDest";
	echo "" ;
	echo "" ;
	echo -n "Do you wish to rename the MP3 tracks? [y/n]: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		RenameMP3ListTracks;
	fi
	PressAnyKey;
	return;
}


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

MP3toWAV () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Convert MP3 files to WAV format" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GetDirWavTracks;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		DirDest=$PWD;
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		while true;
		do
			echo " " ;
			echo " " ;
			echo -n "Select the file [*: All, 0: Exit]: " ;
			read archvmp3;
			if [ "$archvmp3" = "0" ] || [ "$archvmp3" = "" ]
			then
				return;
			fi
			echo "" ;
			echo "" ;
			echo -n "Do you wish to remove the original MP3 files after the conversion? [y/n]: ";
			read opc;
			echo " " ;
			echo " " ;
			if [ "$archvmp3" = "*" ]
			then
				for archv in *.mp3;
				do
					mpg123 -s -r 44100 "$archv" > "$DirDest/$archv.raw" ;
					sox -t raw -r 44100 -c 2 -w -s "$DirDest/$archv.raw"  -r 44100 -c 2 -t wav -w -s "$DirDest/$archv.wav" ;
					rm -f "$DirDest/$archv.raw" ;
					if [ "$opc" = "y" ]
					then
						rm -f "$archv" ; # delete the MP3 file
					fi
				done ;
			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" > "$DirDest/$archvmp3.raw" ;
						sox -t raw -r 44100 -c 2 -w -s "$DirDest/$archvmp3.raw"  -r 44100 -c 2 -t wav -w -s "$DirDest/$archvmp3.wav" ;
						rm -f "$DirDest/$archvmp3.raw" ;
						if [ "$opc" = "y" ]
						then
							rm -f "$archvmp3" ; # delete the MP3 file
						fi
					fi
				fi
			fi
			echo " " ;
			echo " " ;
			echo "Conversin finished." ;
			GetSizeInMB "$DirDest";
			Beep;
			PressAnyKey;
			clear ;
			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
			echo "CDDOIT: Convert MP3 files to WAV format" ;
			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
			echo " " ;
			echo " " ;
			echo "Select again? -The source and target directories will not changed-" ;
			echo " " ;
			ls -Cm --color;
		done
	done
	echo " " ;
	echo " " ;
	echo -n "The WAV files are found in: " ;
	echo "$DirDest";
	PressAnyKey;
	return;
}

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

ConvertCdrCopyFormat () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: 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:" ;
	echo "  *****   In big files this action is going to take a long time." ;
	echo " ** | **  Some audio formats are not compatible in some conversions." ;
	echo " ** 0 **  The final quality sound from poor quality formats maybe" ;
	echo "  *****   not good." ;
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo " " ;
	echo " " ;
	echo -n "Select the file [0: Exit]: " ;
	read archv;
	if [ "$archv" = "0" ] || [ "$archv" = "" ]
	then
		return;
	fi
	clear;
	echo "ENTER THE AUDIO PARAMETERS OF THE ORIGINAL AUDIO FILE:" ;
	echo "====================================================== " ;
	echo " " ;
	echo "\
1. 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.
       avr      Audio Visual Research
       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.
       sph      SPHERE  (SPeech HEader Resources)
       smp      Turtle Beach SampleVision files.
       snd      Under DOS same as the sndt format
                Under all other platforms it is the same as the .au format.
       sndt     SoundTool files. Older DOS file format.
       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, al, sl
                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', 'ulaw' (byte),"alaw" (byte),
                and "signed  long".
       auto     This is a ``meta-type'' format.
";
	echo "-You can select & paste-";
	echo -n "Enter audio format [0: Exit]: " ;
	read format;
	if [ "$format" = "0" ] || [ "$format" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo -n "2. Enter the original sample rate (E.g: 44101 or 8000) [0: Exit]: " ;
	read rate;
	if [ "$rate" = "0" ] || [ "$rate" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "\
3. 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" ] || [ "$bits" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "\
4. 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" ] || [ "$channel" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo -n "Press ENTER 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 "CDDOIT: 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/cddoit";
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: View contents of all CDDOIT directories" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo "Press 'q' to stop." ;
	echo "" ;
	echo "____________________________________________________________________________" ;
	pwd;
	echo "" ;
	ls -Rhlm |more;
	PressAnyKey;
	return ;
}

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

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

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

InfoAudioCd () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: View Audio-CD information" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetOriginalCD;
	cdparanoia -Q;
	echo "" ;
	echo "" ;
	echo -n "Do you wish save this information in a file? [y/n]: " ;
	read save;
	if [ "$save" = "y" ]
	then
		echo "" ;
		echo -n "Enter file name: " ;
		read file;
		cdparanoia -Q 2> "$file"-cdinfo.txt;
		echo "" ;
		echo "" ;
		echo -n "$file-cdinfo.txt was saved in ";
		pwd;
	fi
	PressAnyKey;
	return ;
}

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

ViewSizeDir () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: 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           |" ;
	echo "       |-----------------------------------------|" ;
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	PressAnyKey;
	return ;
}

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

AudioDataCD () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "CDDOIT: Audio+Data CD copy" ;
	else
		echo "CDDOIT: 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 5)";
	else
		GetCDRecordable;
		while true;
		do
			if [ "${1}" = "1" ]	# real copy (no dummy)
			then
				CopyCD 10;
			else
				CopyCD 11;
			fi	
			if [ "$?" = "1" ] # CopyCD error (possible SU error)
			then
				echo "";
				echo "ERROR. CD-Copy could not be started.";
				echo "       Possible incorrect ROOT password.";
				Beep;
				echo "";
				echo -n "Re-enter the password again? [y/n]: ";
				read opc;
				if [ "$opc" != "y" ]
				then
					break;
				fi
			else
				break;
			fi
		done
	fi
	PressAnyKey;
	return 0;
}

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

AboutCDDOIT () {
clear;
echo "\
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
About CDDOIT
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Version 1.5
Author: Jose L. Diaz.
April/2003

Homepage: http://www.geocities.com/cddoit/index.html

This is free software.
Only, I would like to know in many countries of the world CDDOIT is being
used, for that reason would be thankful to you that you sent me a mail
(cddoit@yahoo.com) indicating only your country and city.
All mails will be replied when new versions appears.
Thanks in advance.

I am from Madrid, Spain.

Report bugs or suggestions to: cddoit@yahoo.com
This software comes with NO warranty of any kind. Use at your own risk.";

PressAnyKey;
return;
}

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

MountDataImage () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: 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 "WARNING: You can view ONLY no-multisession data image files." ;
			echo "         In multisession data images this option fail." ;
			echo "         In this case press ENTER to exit." ;
			echo "" ;
			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 "CDDOIT: 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 "CDDOIT: 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 "You must enter the values of your CR-R Recorder, maximum speed," ;
	echo "recording and buffer, if you know it. Otherwise enter e.g. values." ;
	echo "" ;
	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 CD-R Recorder device view above [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, e.g. 4m: ";
read fifosize;
echo "" ;
echo "" ;
echo -e "\a";
echo -n "Modify the /etc/cdrecord.conf file. Are you sure? [y/n(ENTER)] : ";
read opc;
if [ "$opc" = "y" ]
then
	mv /etc/cdrecord.conf /etc/cdrecord.conf.old ;
	echo "\
#ident @(#)cdrecord.dfl	Copyr. 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 CDDOIT
#***********************************
" > /etc/cdrecord.conf ;
		echo "" ;
		echo "/etc/cdrecord.conf was changed.";
		echo "The original file was saved to /etc/cdrecord.conf.old";
else
	echo "" ;
	echo "/etc/cdrecord.conf NOT changed.";
	
fi';
	PressAnyKey;
	return;
}

#******************************************************************************
	
MultiAudio () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "12" ]	# real copy (no dummy)
	then
		echo "CDDOIT: Multisession audio CD-R copy" ;
	else
		echo "CDDOIT: Multisession audio CD-R DUMMY copy" ;
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	track=1;
	while true;
	do
		echo " " ;
		echo -n "Select the file [0: Exit, *: All files from the directory]: " ;
		read archwav;
		if [ "$archwav" = "0" ] || [ "$archwav" = "" ]
		then
			return;
		fi
		export archwav;
		echo " " ;
		echo -n "Enter speed of copy (ENTER, Default speed): " ;
		read speed;
		export speed;
		while true;
		do
			if [ "$archwav" = "*" ]
			then
				echo "";
				echo "WARNING: During the CD copy the CD-Recorder ejects and reload";
				echo "         the audio CD several times. Don\'t Worry.";
				echo "";
			fi
			CopyCD ${1};
			if [ "$?" = "1" ] # CopyCD error (possible SU error)
			then
				echo "";
				echo "ERROR. CD-Copy could not be started.";
				echo "       Possible incorrect ROOT password.";
				Beep;
				echo "";
				echo -n "Re-enter the password again? [y/n]: ";
				read opc;
				if [ "$opc" != "y" ]
				then
					break;
				fi
			else
				break;
			fi
		done
		Beep;
		if [ "$archwav" != "*" ] # only for selections file per file
		then
			echo " " ;
			echo " " ;
			echo -n "Select new file? [y/n]: ";
			read opc;
			if [ "$opc" = "y" ]
			then
				if [ -f "$PWD"/cdtracklist.txt ]
				then
					rm -f "$PWD"/cdtracklist.txt;
				fi
				echo $track."$archwav" >> "$PWD"/cdtracklist.txt;
				track=`expr ${track} + 1`;
				echo "";
				echo "The audio files:";
				echo "";
				ls -Cm --color *;
				echo "";
				echo "Insert again the CD-R and select the audio file.";
			else
				track=`expr ${track} + 1`;
				echo $track."$archwav" >> "$PWD"/cdtracklist.txt;
				echo "The tracks written to CD-R in this last session are:";
				echo "";
				cat "$PWD"/cdtracklist.txt;
				echo "";
				echo "";
				echo -n "Also, the track list are in the file: ";
				echo "$PWD"/cdtracklist.txt;
				break;
			fi
		else
			echo "";
			echo "";
			echo "All WAV files from the directory were copied.";
			echo "";
		fi
	done
	echo "";
	echo "REMEMBER: After complete all recordings in the CD-R you must to close it.";
	echo "          See menu AUDIO CD-R, option n 9.";
	echo "";
	echo -n "Do you wish close the audio CD now? [y/n(ENTER)]: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		CloseMultiAudio;
	else
		PressAnyKey;
		return;
	fi
}

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

CloseMultiAudio () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Close multisession audio CD-R" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetOriginalCD;
	echo "";
	echo "";
	echo "This operation must be performed under ROOT. Enter the password.";
	su -c 'cdrecord -v -eject -fix; echo ""; echo "The audio CD is closed."';
	Beep;
	PressAnyKey;
	return;
}


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

ExitCddoit () {
	clear;
	exit 0;
}

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


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


menucdrewritable () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: CD REWRITABLE ::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Blank all the CD -Slow-";
	echo "    2. Blank all the CD -Fast-";
	echo "    3. Forced blank";
	echo "    4. Unclose last session";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) CdrwBlankAllSlow;;
		2) CdrwBlankAllFast;;
		3) CdrwBlankForced;;
		4) CdrwUncloseSession;;
	esac;
done
}

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

menuaudiocd () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: AUDIO CD-R :::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Direct Audio CD copy to CD-R (Get WAV files and copy)";
	echo "    2. Direct Audio CD DUMMY copy to CD-R";
	echo "    3. WAV files to CD-R copy";
	echo "    4. MP3 files to CD-R copy";
	echo "    5. WAV files to CD-R DUMMY copy";
	echo "    6. MP3 files to CD-R DUMMY copy";
	echo "    7. Multisession audio CD-R copy";
	echo "    8. Multisession audio CD-R DUMMY copy";
	echo "    9. Close a multisession audio CD-R";
	echo "   10. Direct Audio CD copy to CD-R in Multisession";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) AudioDirectCopy 1;;
		2) AudioDirectCopy 2;; # dummy
		3) AudioCopy 1;;
		4) MP3toCD 1;;
		5) AudioCopy 4;;	# dummy
		6) MP3toCD 4;;	# dummy
		7) MultiAudio 12;;
		8) MultiAudio 13;; #dummy
		9) CloseMultiAudio;;
		10) AudioDirectCopyMultisession;;
	esac;
done
}

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

menudatacd () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: DATA CD-R ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Data-CD direct copy to CD-R (Create data image file and copy)";
	echo "    2. Data-CD direct dummy copy to CD-R";
	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
		"") break;;
		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 "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	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
		"") break;;
		0) break;;
		1) AudioDataCD 1;;
		2) AudioDataCD 2;;
	esac;
done
}

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

menuaudioconversionprog () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :: AUDIO ::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: Audio conversion programs :::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Program an audio conversion";
	echo "    2. Delete an audio conversion program";
	echo "    3. View audio conversion programs";
	echo "    4. Cancel an audio conversion program already started";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) ConvertBetweenFormats 2;;
		2) DelProgramRecord 2;;
		3) ViewProgramRecords 2;;
		4) CancelProgramRecordStarted;;
	esac;
done
}


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

menuaudio5 () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :: AUDIO ::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: Audio recording programs :::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Program an audio recording";
	echo "    2. Delete an audio recording program";
	echo "    3. View audio recording programs";
	echo "    4. Cancel an audio recording program already started";
	echo "    5. Sleeptimer recording";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) ProgramRecord;;
		2) DelProgramRecord;;
		3) ViewProgramRecords;;
		4) CancelProgramRecordStarted;;
		5) SleepTimerRecord;;
	esac;
done
}


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

menuaudio4 () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :: AUDIO ::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: Audio conversions ::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Convert MP3 files to WAV format";
	echo "    2. Convert WAV files to MP3 format";
	echo "    3. Convert 44.101 Hz to 44.000 Hz rate in WAV files";
	echo "    4. Convert audio file formats to CD-R copy file format";
	echo "    5. Convert between audio file formats";
	echo "    6. Audio conversion programs";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) MP3toWAV;;
		2) WAVtoMP3;;
		3) Convert44101to44100;;
		4) ConvertCdrCopyFormat;;
		5) ConvertBetweenFormats 1;;
		6) menuaudioconversionprog;;
	esac;
done
}


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

menuaudio3 () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :: AUDIO ::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: Play audio files :::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Play WAV files";
	echo "    2. Play MP3 files";
	echo "    3. Play many audio files";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) PlayWAV;;
		2) PlayMP3;;
		3) PlayManyFormats;;
	esac;
done
}


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

menuaudio2 () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :: AUDIO ::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: Record audio :::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Record audio in WAV format [CD copy format]";
	echo "    2. Record audio in WAV format [44.101 Hz]";
	echo "    3. Record audio in specific formats";
	echo "    4. Audio recording programs";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) AudioRecord 1;;
		2) AudioRecord 2;;
		3) AudioRecordSpecificFormat;;
		4) menuaudio5;;
	esac;
done
}


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

menuaudio1 () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :: AUDIO ::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: Get audio files from Audio-CD ::::::::::::::::::::::::::::::::::::::";
	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. Get the whole Audio-CD in a single audio file";
	echo "    6. Get RAW files from Audio-CD";
	echo "    7. Get AIFF files from Audio-CD";
	echo "    8. Get WAV files when rippering fails";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) GetWAVfromCD;;
		2) GetMP3fromCD;;
		3) GetWAVfromSeveralCD;;
		4) GetMP3fromSeveralCD;;
		5) GetWholeCDSingleFile;;
		6) GetRAWfromCD;;
		7) GetAIFFfromCD;;
		8) RecordCDAudioTracks;;
	esac;
done
}

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

menuaudio () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: AUDIO ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Get audio files from Audio-CD";
	echo "    2. Record audio";
	echo "    3. Play audio files";
	echo "    4. Audio conversions";
	echo "    5. Adjust max volume in audio files";
	echo "    6. CD Player";
	echo "    7. Noise reduction";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) menuaudio1;;
		2) menuaudio2;;
		3) menuaudio3;;
		4) menuaudio4;;
		5) normalize;;
		6) CDplayer;;
		7) denoise;;
	esac;
done
}

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

menuothers () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :: OTHERS :::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "    1. View contents of all CDDOIT directories";
	echo "    2. View size of a directory in MB";
	echo "    3. View SCSI devices for CDRECORD";
	echo "    4. Delete a CDDOIT directory";
	echo "    5. Delete files of CDDOIT temporary directories [AUDIOCD & DATACD]";
	echo "    6. Delete ALL CDDOIT 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 "   11. Rename the MP3 file names in a directory";
	echo "   12. Rename the audio file names in a directory";
	echo "   13. Multimedia kernel modules manager";
	echo "   14. Get CD Recorder information";
	echo "   15. Clear the log files";
	echo "   16. Create a new CDDOIT directory (Empty)";
	echo "   17. Audio mixer [Aumix]";
	echo "   18. Get total time duration from WAV files";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) ViewAllDir;;
		2) ViewSizeDir;;
		3) Scanbus;;
		4) DelDir;;
		5) DelTemp;;
		6) DelAll;;
		7) FreeSizeHD;;
		8) InfoAudioCd;;
		9) CreateLoopDev;;
		10) ConfCdrecord;;
		11) RenameMP3ListTracks;;
		12) RenameAudioListTracks;;
		13) ModulesManager;;
		14) GetCdRecorderInfo;;
		15) ClearLogFiles;;
		16) CreateCDDOITDir;;
		17) aumix;;
		18) GetWavTime;;
	esac;
done
}

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

menudata () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: DATA :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Create data image file";
	echo "    2. Create data image file for Multisession copy";
	echo "    3. Mount/View data image";
	echo "    4. Create a 'El Torito' image file -Bootable CD-";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) GetImage 1;;
		2) GetImage 2;;
		3) MountDataImage;;
		4) CreateBootImage 1;;
	esac;
done
}


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

CreateDirByDefault;
while true;
do
	clear;
	echo "=======================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::: By Jose L. Diaz";
	echo "=======================================================================";
	echo "    CD Creation & Sound                                    Version: 1.5";
	echo "";
	echo "";
	echo "";
	echo "    1. Audio CD";
	echo "    2. Data CD";
	echo "    3. Audio+Data CD";
	echo "    4. Audio";
	echo "    5. Data" ;
	echo "    6. CD ReWritables";
	echo "    7. Others";
	echo "    8. About CDDOIT" ;
	echo "" ;
	echo "    0. Exit CDDOIT" ;
	echo "" ;
	echo "" ;
	echo -n "Choose option: ";
	read opc;
	case $opc in
		0) ExitCddoit;;
		1) menuaudiocd;;
		2) menudatacd;;
		3) menumixcd;;
		4) menuaudio;;
		5) menudata;;
		6) menucdrewritable;;
		7) menuothers;;
		8) AboutCDDOIT;;
	esac;
done
