@ECHO OFF
SET _outfile="%~dpn1 (noncompliant).cue"
IF EXIST %_outfile% (
ECHO "%~n1 (noncompliant).cue"
ECHO already exists!
ECHO.
ECHO Press any key to end . . .
PAUSE>nul
GOTO end
)
SET _tempfile=%TEMP%\~cueconv.tmp
IF EXIST %_tempfile% DEL %_tempfile%
SET _track=
SET _line=
SET _skip=
SET _index=
SET _header=1
IF "%~1" == "" GOTO end
GOTO start
:get_next_line
SET /A _line+=1
SET _skip=skip=%_line%
:start
FOR /F "usebackq tokens=1,2* %_skip%" %%X IN (%1) DO (
SET _x=%%X
SET _y=%%Y
SET _z=%%Z
GOTO generate_cue
)
GOTO end
:generate_cue
IF "%_x%" == "FILE" GOTO file
IF "%_x%" == "TITLE" CALL :set_title
IF "%_x%" NEQ "INDEX" GOTO other
IF "%_y%" == "00" GOTO 00_index
IF "%_y%" == "01" GOTO 01_index
GOTO XX_index
:other
IF %_header% EQU 0 (
IF "%_x%" == "TRACK" (
SET _x= TRACK
) ELSE (
SET _x= %_x%
)
)
IF DEFINED _z (
ECHO %_x% %_y% %_z%>>%_tempfile%
GOTO get_next_line
)
IF DEFINED _y (
ECHO %_x% %_y%>>%_tempfile%
GOTO get_next_line
)
ECHO %_x%>>%_tempfile%
GOTO get_next_line
:file
IF %_header% == 0 GOTO error
TYPE %_tempfile%>%_outfile%
DEL %_tempfile%
SET _header=0
GOTO get_next_line
:set_title
IF DEFINED _z (
SET _title=%_y% %_z%
) ELSE (
SET _title=%_y%
)
GOTO :eof
:01_index
CALL :extract_index %_z%
SET /A _iframes=mm*4500+ss*75+ff
IF "%_index%" NEQ "0" (
CALL :set_file %_title%
TYPE %_tempfile%>>%_outfile%
DEL %_tempfile%
ECHO INDEX 01 00:00:00>>%_outfile%
)
SET _index=
GOTO get_next_line
:00_index
IF "%_z%" == "00:00:00" GOTO get_pregap
SET _index=0
CALL :extract_index %_z%
SET /A _igap=mm*4500+ss*75+ff - _iframes
CALL :format_index %_igap%
ECHO INDEX %_y% %mm%:%ss%:%ff%>>%_tempfile%
TYPE %_tempfile%>>%_outfile%
DEL %_tempfile%
CALL :set_file %_title%
ECHO INDEX 01 00:00:00>>%_outfile%
GOTO get_next_line
:XX_index
CALL :extract_index %_z%
SET /A _igap=mm*4500+ss*75+ff - _iframes
CALL :format_index %_igap%
ECHO INDEX %_y% %mm%:%ss%:%ff%>>%_outfile%
GOTO get_next_line
:set_file
SET /A _track+=1
SET tt=%_track%
IF %tt% LSS 10 (SET tt=0%tt%)
ECHO FILE "%tt% - %~1.wav" WAVE>>%_outfile%
GOTO :eof
:get_pregap
SET /A _advance=_line + 1
SET _skip=skip=%_advance%
FOR /F "usebackq tokens=1,2* %_skip%" %%X IN (%1) DO (
SET _x=%%X
SET _y=%%Y
SET _z=%%Z
GOTO got_pregap
)
:got_pregap
CALL :extract_index %_z%
SET /A _pregap=mm*4500+ss*75+ff
ECHO PREGAP %_z%>>%_tempfile%
GOTO get_next_line
:extract_index
SET _z=%1
IF %_z:~0,1% == 0 (
SET mm=%_z:~1,1%
) ELSE (
SET mm=%_z:~0,2%
)
IF %_z:~3,1% == 0 (
SET ss=%_z:~4,1%
) ELSE (
SET ss=%_z:~3,2%
)
IF %_z:~6,1% == 0 (
SET ff=%_z:~7,1%
) ELSE (
SET ff=%_z:~6,2%
)
GOTO :eof
:format_index
SET /A mm=%1/4500
SET /A ss=%1%%4500/75
SET /A ff=%1%%4500%%75
IF %mm% LSS 10 (SET mm=0%mm%)
IF %ss% LSS 10 (SET ss=0%ss%)
IF %ff% LSS 10 (SET ff=0%ff%)
GOTO :eof
:error
ECHO Input CUE is not of the single file variety!
ECHO.
ECHO Press any key to end . . .
PAUSE>nul
DEL %_outfile%
:end