// // llSoundDisplay.MEL // ////////////////////////// // // Maya script file // ////////////////////////// // // Author : Lluís Llobera // (lluisllobera@gmail.com) // // Creation date : 21/XI/2005 // UPDATE 1.1 : 22/XI/2005 // UPDATE 1.2 : 15/XII/2005 // UPDATE 1.21 : 23/XII/2005 // UPDATE 1.22 : 14/XI/2006 // // Main procedure : type "llSoundDisplay" in the Command Line or Script Editor // ////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // This script will generate a small window with a textField and two "ON" and "OFF" buttons. The textField can be // clicked on to select the audio that the user wants to display in the time line, and the "ON" and "OFF" buttons // can be used further on to enable or disable that audio. // // UPDATE 1.1 // Replaced the script's usage of the "setSoundDisplay" command for the more correct use of the // timeControl command. It turned out that version 1.0 got errors when the user had not manually // toggled the sound's visibility status in the timeLine. D'oh .. :-) // // UPDATE 1.2 // Now the buttons and textField update when a new file is opened. // // UPDATE 1.21 // After pressing the "ON" / "OFF" buttons, the script makes Maya focus on the last listed // model panel. I found this would be a cool feature, because it was a little frustrating that // the focus remained on the window .. // // UPDATE 1.22 // Fixed a small bug. Also, changed the "sel" button into "edit"; now, when clicking on it, // the AE will pop up displaying the attributes for the currently displayed sound. // // // Enjoy! // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////// // llSDWChangeTextButton // ////////////////////////////////// // // Enables / disables the "edit" text button // // // <-- llSoundDisplay // ///////////////////////////////// global proc llSDWChangeTextButton () { $CURRENTAUDIO = `textField -q -tx llSDWText` ; if ($CURRENTAUDIO == "( none )") button -e -en 0 llSDWTextButton ; else button -e -en 1 llSDWTextButton ; } ; // global proc llSDWChangeTextButton ////////////////////////////////// // llSDWAEAudio // ////////////////////////////////// // // Shows the AE for the currently displayed audio // // // <-- llSoundDisplay // ///////////////////////////////// global proc llSDWAEAudio () { $CURRENTAUDIO = `textField -q -tx llSDWText` ; if ($CURRENTAUDIO != "( none )") showEditor $CURRENTAUDIO ; } ; // global proc llSDDWSelPressed ////////////////////////////////// // llSDWSetFocusOnModelPanel // ////////////////////////////////// // // Sets the focus on the last found model panel // // <-- llSDWOnButtonPressed // <-- llSDWOffButtonPressed // ///////////////////////////////// global proc llSDWSetFocusOnModelPanel () { string $PANEL = `getPanel -wf` ; setFocus $PANEL ; } ; // global proc llSDWSetFocusOnModelPanel ////////////////////////////////// // llSDWUpdate // ////////////////////////////////// // // Investigates the scene sound properties, // then accordingly updates the window // // <-- llSoundDisplayWindow // --> llSDWOnButtonPressed // --> llSDWOffButtonPressed // ///////////////////////////////// global proc llSDWUpdate () { global string $gPlayBackSlider ; string $CURRENTAUDIO = `timeControl -q -s $gPlayBackSlider` ; string $AUDIOS[] = `ls -type audio` ; if ($CURRENTAUDIO == "") if (`size $AUDIOS` > 0) $CURRENTAUDIO = $AUDIOS[0] ; else $CURRENTAUDIO = "( none )" ; textField -e -tx $CURRENTAUDIO llSDWText ; if ($CURRENTAUDIO == "( none )") { textField -e -font "obliqueLabelFont" llSDWText ; llSDWOffButtonPressed ; } // if else { textField -e -font "plainLabelFont" llSDWText ; if (`timeControl -q -ds $gPlayBackSlider`) llSDWOnButtonPressed ; else llSDWOffButtonPressed ; } ; // else } ; // global proc llSDWUpdate ////////////////////////////////// // llSDWChangeButtonColors // ////////////////////////////////// // // Checks if any audio is displayed, then // changes the color of the ON / OFF buttons // // <-- llSoundDisplayWindow // <-- llSDWOnButtonPressed // <-- llSDWOffButtonPressed // --> llSDWChangeTextButton // ///////////////////////////////// global proc llSDWChangeButtonColors () { vector $COLORS[] = { << 0.6 , 1.0 , 0.6 >> , // ON enabled << 0.6 , 0.75 , 0.6 >> , // ON disabled << 1.0 , 0.6 , 0.6 >> , // OFF enabled << 0.75 , 0.6 , 0.6 >> } ; // OFF disabled global string $gPlayBackSlider ; button -e -vis 0 llSDWOnButton ; button -e -vis 0 llSDWOffButton ; if (`timeControl -q -s $gPlayBackSlider` == "") { eval ("button -e -bgc " + $COLORS[1] + " llSDWOnButton") ; eval ("button -e -bgc " + $COLORS[2] + " llSDWOffButton") ; } else { eval ("button -e -bgc " + $COLORS[0] + " llSDWOnButton") ; eval ("button -e -bgc " + $COLORS[3] + " llSDWOffButton") ; } ; // else button -e -vis 1 llSDWOnButton ; button -e -vis 1 llSDWOffButton ; } ; // global proc llSDWChangeButtonColors ////////////////////////////////// // llSDWOnButtonPressed // ////////////////////////////////// // // "On" button was pressed. Get the audio name in llSDWText // and display it in the timeLine. // // <-- llSoundDisplayWindow // --> llSDWChangeButtonColors // --> llSDWSetFocusOnModelPanel // ///////////////////////////////// global proc llSDWOnButtonPressed () { global string $gPlayBackSlider ; string $AUDIOS[] = `ls -type audio` ; int $ERROR = 1 ; string $AUDIO = `textField -q -tx llSDWText` ; if ($AUDIO != "( none )") for ($ELEMENT in $AUDIOS) if ($ELEMENT == $AUDIO) { timeControl -e -ds 1 -es -s $AUDIO $gPlayBackSlider ; $ERROR = 0 ; } ; if ($ERROR) if ($AUDIO == "") error ("specify an audio node") ; else error ("specified audio does not exist : " + $AUDIO) ; llSDWChangeButtonColors ; llSDWSetFocusOnModelPanel ; } ; // global proc llSDWOnButtonPressed ////////////////////////////////// // llSDWOffButtonPressed // ////////////////////////////////// // // "Off" button was pressed. Get the audio name in the timeLine, // and then just hide it. // // <-- llSoundDisplayWindow // --> llSDWChangeButtonColors // --> llSDWSetFocusOnModelPanel // ///////////////////////////////// global proc llSDWOffButtonPressed () { global string $gPlayBackSlider ; timeControl -e -ds 0 $gPlayBackSlider ; llSDWChangeButtonColors ; llSDWSetFocusOnModelPanel ; } ; // global proc llSDWOffButtonPressed ////////////////////////////////// // llSDWBuildTextList // ////////////////////////////////// // // Clean the old menuList, // get the names of the audios and build the // new menuItems with their command. // // <-- llSoundDisplayWindow // ///////////////////////////////// global proc llSDWBuildTextList (string $TYPE) { string $LIST ; if ($TYPE == "text") $LIST = "llSDWTextTextList" ; else $LIST = "llSDWTextButtonList" ; eval ("popupMenu -e -dai " + $LIST) ; string $AUDIOS[] = `ls -type audio` ; if (`size $AUDIOS` > 0) for ($AUDIO in $AUDIOS) menuItem -l $AUDIO -p $LIST -c ("textField -e -font \"plainLabelFont\" -tx \"" + $AUDIO + "\" llSDWText ; llSDWOnButtonPressed ; llSDWChangeTextButton ;") ; else menuItem -en 0 -p $LIST -l "no audio nodes in the scene" ; } ; // global proc llSDWBuildTextList ////////////////////////////////// // llSoundDisplay // ////////////////////////////////// // // MAIN PROC // Creates the main window. // // --> llSDWBuildTextList // --> llSDWOnButtonPressed // --> llSDWOffButtonPressed // --> llSDWChangeButtonColors // --> llSDWAEAudio // ///////////////////////////////// global proc llSoundDisplay () { // variables string $VERSION = "1.22" ; int $WIDTH = 160 ; int $HEIGHT = 75 ; // window creation if (`window -ex llSoundDisplayWindow`) deleteUI llSoundDisplayWindow ; window -title ("llSoundDisplay v" + $VERSION) llSoundDisplayWindow ; string $LAYOUT = `formLayout -numberOfDivisions 100` ; string $LAYOUT1 = `formLayout -numberOfDivisions 100` ; textField -ed 0 -p $LAYOUT1 llSDWText ; popupMenu -button 1 llSDWTextTextList ; popupMenu -e -pmc ("llSDWBuildTextList \"text\"") llSDWTextTextList ; button -en 0 -l "edit" -c llSDWAEAudio llSDWTextButton ; string $LAYOUT2 = `formLayout -numberOfDivisions 100 -p $LAYOUT` ; button -l "ON" -bgc 0.6 0.75 0.6 -p $LAYOUT2 -c llSDWOnButtonPressed llSDWOnButton ; button -l "OFF" -bgc 0.75 0.6 0.6 -p $LAYOUT2 -c llSDWOffButtonPressed llSDWOffButton ; formLayout -e -attachForm $LAYOUT1 "top" 1 -attachNone $LAYOUT1 "bottom" -attachForm $LAYOUT1 "left" 1 -attachForm $LAYOUT1 "right" 1 -attachControl $LAYOUT2 "top" 2 $LAYOUT1 -attachForm $LAYOUT2 "bottom" 1 -attachForm $LAYOUT2 "left" 2 -attachForm $LAYOUT2 "right" 2 $LAYOUT ; formLayout -e -attachForm llSDWText "top" 1 -attachForm llSDWText "bottom" 1 -attachForm llSDWText "left" 1 -attachControl llSDWText "right" 1 llSDWTextButton -attachForm llSDWTextButton "top" 1 -attachForm llSDWTextButton "bottom" 1 -attachNone llSDWTextButton "left" -attachForm llSDWTextButton "right" 1 $LAYOUT1 ; formLayout -e -attachForm llSDWOnButton "top" 1 -attachForm llSDWOnButton "bottom" 1 -attachForm llSDWOnButton "left" 5 -attachPosition llSDWOnButton "right" 0 48 -attachForm llSDWOffButton "top" 1 -attachForm llSDWOffButton "bottom" 1 -attachPosition llSDWOffButton "left" 0 52 -attachForm llSDWOffButton "right" 5 $LAYOUT2 ; llSDWUpdate ; llSDWChangeButtonColors ; llSDWChangeTextButton ; window -e -tb 1 -minimizeButton 0 -maximizeButton 0 -wh $WIDTH $HEIGHT llSoundDisplayWindow ; showWindow llSoundDisplayWindow ; scriptJob -p llSoundDisplayWindow -event deleteAll llSDWUpdate ; } ; // global proc llSoundDisplay ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // EoS llSoundDisplay // /////////////////////////////////////////////////////////////////////////////////////////////////////////////