#!/usr/bin/env bash
encodeFile::vorbis() {
	oggencopts=(${ionice}oggenc -Q -q ${destinationquality[$destination]})
	[ -n "$albumartist" ] && oggencopts+=(-c "ALBUMARTIST=$albumartist")
	[ -n "$album"	] && oggencopts+=(-l "$album")
	[ -n "$artist"	] && oggencopts+=(-a "$artist")
	[ -n "$composer" ] && oggencopts+=(-c "COMPOSER=$composer")
	[ -n "$disc"	] && oggencopts+=(-c "DISCNUMBER=$disc")
	[ -n "$genre"	] && oggencopts+=(-G "$genre")
	[ -n "$performer" ] && oggencopts+=(-c "PERFORMER=$performer")
	[ -n "$releasecountry" ] \
		&& oggencopts+=(-c "RELEASECOUNTRY=$releasecountry")
	[ -n "$replaygain_alb" ] \
		&& oggencopts+=(-c "REPLAYGAIN_ALBUM_GAIN=$replaygain_alb")
	[ -n "$replaygain_trk" ] \
		&& oggencopts+=(-c "REPLAYGAIN_TRACK_GAIN=$replaygain_trk")
	[ -n "$title"	] && oggencopts+=(-t "$title")
	[ -n "$track"	] && oggencopts+=(-N "$track")
	[ -n "$year"	] && oggencopts+=(-d "$year")
	oggencopts+=(-o "${destinationpath[$destination]}/$destdir/$destfile.ogg" "$tempdir/$tmpfile.wav")
	encodetaskid=$(
		Insert tasks <<-EOInsert
			key		${fileid}oggenc$destination
			requires	${soxtaskid:-$decodetaskid}
			fileid		$destfileid
			filename	$destdir/$destfile.ogg
			$(
				for key in ${!oggencopts[@]}
				do
					cleanedopts="${oggencopts[key]//\&/\\\&}"
					cleanedopts="${cleanedopts//\[/\\[}"
					cleanedopts="${cleanedopts//\]/\\]}"
					cleanedopts="${cleanedopts//\{/\\{}"
					cleanedopts="${cleanedopts//\}/\\\}}"
					echo "cmd_arg$key ${oggencopts[key]}"
				done
			)
			source_file	$fileid
			status		0
			rename_pattern	${destinationrenamepath[$destination]}/${destinationrename[$destination]}
			fat32compat	${destinationfat32compat["$destination"]}
			ascii		${destinationascii["$destination"]}
		EOInsert
	)
	parent_required=$(
		Select tasks required_by			\
			<<<"id = ${soxtaskid:-$decodetaskid}"
	)
	Update tasks required_by $((++parent_required))	\
		<<<"id = ${soxtaskid:-$decodetaskid}"
	progressSpin
	soxtaskid=''
}
