//***************************************************************************************************
//
//written by jonathan paton on or around nov/5/07
//turns audio files selected in the trax editor into XML file with pertinient infoprmation
//inserted according to guide lines for in game audio XMLs
//
//INSTRUCTIONS:
//
//Open a new file.
//Save the new file with whatever naming convention is appropriate for your work, maybe something like “cutsceneName” + “_fxAudio”.
//Reference the cut-scene you are working on into that file.
//Import the audio clips you need into the Trax Editor.
//(If you need duplicates of any file made turn off the reference before making copies as
//It will go much faster.)
//Place the audio clips where you would like in the Trax Editor.
//Selected the audio clips you need to add to the XML.
//Run the script.
//An XML with the name of the Maya scene will be saved in the same folder as the Maya scene.
//
//things that could go wrong:
//you could have more then audio files selected (like a poly or something)
//you may not have saved the file -- this will generate an error message
//you may not have anything selected -- this will generate an error message
//file you want to write to is open (this actaully won't cause any problems but it may be confusing
//and increase user error)
//
//***************************************************************************************************
global proc fxAudioToXML()
{
//collect select audio clips into an array
string $selectedAudioFileArray[] = `ls -sl`;
int $arraySize = size($selectedAudioFileArray);
if ($arraySize < 1)
{
error("Please select an audio clip");
}else{
//array that will be printed out
printXML($selectedAudioFileArray);
}
}
//this proceedure takes the array with the selected audio clips in it and
//sends it through a for loop and sends each of its elements to another
//proceedure that returns the needed information which this proceedure then
//prints to a file on the local directory
proc printXML(string $selectedAudioFileArray[])
{
string $arrayPrint[]; //array that will be printed
string $arrayTemp[]; //temp array
//sends out each element of the array to have information gotten for it
//then appends it to existing array
for ( $currentAudioFileName in $selectedAudioFileArray)
{
$arrayTemp = getAudioFileNames($currentAudioFileName);
appendStringArray($arrayPrint, $arrayTemp, 5);
}
//put array into string to print
string $printMe = stringArrayToString($arrayPrint, "");
//get path and file name for current scene
string $pathAndFileNameArray[] = `getFilePath`;
//put into strings
string $filePathString = $pathAndFileNameArray[0];
string $fileNameString = $pathAndFileNameArray[1];
//creates a file with the correct name to be appended later
$fileName = ($filePathString + ("/")+ $fileNameString + (".xml") );
$fileId=`fopen $fileName "w"`;
fprint $fileId ($filePathString + ("/")+ $fileNameString + (".xml") + "\n \n" );
//flush buffer
fflush $fileId;
//close file
fclose $fileId;
int $arraySize = size($selectedAudioFileArray);
int $count = 0;
//this loop writes information for the selected audio clips into a file that's already been opened
//each audio file has 4 elements of information pertaining to it so this loop cycles through once for
//every single element
do{
string $mayaAudioFileName = $arrayPrint[$count];
string $pathAfterSound = $arrayPrint[($count + 1)];
float $startTime = $arrayPrint[($count + 2)];
string $episodeNumOrGlobal = $arrayPrint[($count + 3)];
string $audioFileName = $arrayPrint[($count + 4)];
string $printMe = ("\n") +
("\n") +
("\n")) +
(" \n")) +
(" \n") +
(" \n \n");
$fileName = ($filePathString + ("/")+ $fileNameString + (".xml") );
$fileId=`fopen $fileName "a"`;
fprint $fileId $printMe;
fflush $fileId;
fclose $fileId;
$count = ($count + 5);
}while($count < ($arraySize * 5));
//lets user know where file was printed to
print ($filePathString + ("/")+ $fileNameString + (".xml") );
}
//this proceedure take an element of an array from a for loop and gets pertinent information
//form it; start time, length, name and location and return an array to be appended to an existing
//array
proc string[] getAudioFileNames(string $currentAudioFileName)
{
float $timeplaceInt = ((`getAttr (($currentAudioFileName) + (".offset"))`) / 30);
float $audioLength = `sound -q -length $currentAudioFileName`;
string $filePath = (`getAttr (($currentAudioFileName) + (".") + ("filename"))`);
//this next bunch removes the name of the audio file from the path
string $tempStringArray[] = stringToStringArray($filePath, "/");
$tempStringArray[(size($tempStringArray) - 1)] = "";
string $filePathSansAudio = stringArrayToString($tempStringArray, "/");
//get an array of the path w/o "/" in it and send it to a proceedure that
//will parse the array for ep01, ep02 or global (global is any array without ep01
//or ep02...
string $filePathArray[] = stringToStringArray($filePath, "/");
string $epOrGlobalString = `getEpFromPath($filePathArray)`;
//these next few commands will extract the file typr feom the name of the audio clip
//in the path
string $audioNoFileType = $filePathArray[((`size($filePathArray)`) - 1)];
string $filesTypeArray[] = stringToStringArray($audioNoFileType, ".");
string $audioFileName = $filesTypeArray[0];
//string array to pass all needed iformation about audio clip back
$infoArray[0] = $currentAudioFileName;
$infoArray[1] = $filePathSansAudio;
$infoArray[2] = $timeplaceInt;
$infoArray[3] = $epOrGlobalString;
$infoArray[4] = $audioFileName;
//not in use now
//$infoArray[5] = (("length: ") + ($audioLength) + (";\n"));
return $infoArray;
}
//this proceedure return an array whose first element is the path for the Maya scene
//with the name of the maya file removed and whose second element is the name of the
//Maya file w/o the extention
proc string[] getFilePath()
{
//path where Maya scene is located
string $filePath = `file -q -sceneName`;
if ($filePath == "")
{
error "save your file butthead";
}
//change string to string array w/o "/"
string $filePathArray[] = stringToStringArray($filePath, "/");
//get size of array
int $pathArraySize = size($filePathArray);
//get the name of the Maya file
string $currentFileName = $filePathArray[($pathArraySize - 1)];
//array used to hold elements that will become path w/o file name
string $pathBackToString[];
//for testing
clear $pathBackToString;
//test number for loop
int $count = 0;
//feeds original array back to temp array but leaves off last elemant
do{
$pathBackToString[$count] = $filePathArray[$count];
$count++;
}
while ($count < ($pathArraySize - 1));
//turns path array back to string
string $filePathString = stringArrayToString($pathBackToString, "/");
//remove the extention from the Maya file name
string $filePathNameArray[] = stringToStringArray($currentFileName, ".");
string $pathAndNameArray[];
$pathAndNameArray[0] = $filePathString;
$pathAndNameArray[1] = $filePathNameArray[0];
return $pathAndNameArray;
}
//takes a path that has been converted to an array with the "\" removed and
//determines if its from ep01, ep02 or global, returns the location
proc string getEpFromPath(string $filePathArray[])
{
string $whatAmI;
for($currentElement in $filePathArray)
{
if ($currentElement == "ep01")
{
$whatAmI = "ep01";
break;
}
else if ($currentElement == "ep02")
{
$whatAmI = "ep02";
break;
}
else
{
$whatAmI = "global";
}
}
return $whatAmI;
}