@echo off
setlocal enabledelayedexpansion

set basename_input=%~n1
set segmentdir=%basename_input%_segments
set segmentconvdir=%basename_input%_segments_converted

if not exist %segmentdir%\ mkdir %segmentdir%\
if not exist %segmentconvdir%\ mkdir %segmentconvdir%\

:: Make thepark segments
toolsbin\ffmpeg -i %1 -f segment -segment_time 5 -c:a copy "%segmentdir%\thepark_%%03d.wav"

if exist temp_list.txt del temp_list.txt

for /f %%f in ('dir /s /b %segmentdir%\*.wav') do (
	set basename=%%~nf
	toolsbin\sx_2002 -ps2stream -eaxa_blk -v4 %%f ="%segmentconvdir%\!basename!.asf"
	echo %segmentconvdir%\!basename!.asf >> temp_list.txt
)

:: Make the mus file
toolsbin\mkmus temp_list.txt zThePark.mus


::toolsbin\chimp -v3 -align=4 tpsegments_converted\*.asf -=zThePark.mus

::copy /b tpsegments_converted\*.asf zThePark.mus


:: temp list no longer needed
if exist temp_list.txt del temp_list.txt

endlocal