// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // // Creation Date: November 9, 2017 // // Description: // This is a helper script to perform the butterworth command // using the various options that have been set // // Input Arguments: // int action 0 - just execute the command // 1 - show the option box dialog // 2 - return the drag command // // Return Value: // None. // proc setOptionVars (int $forceFactorySettings) { keySetOptionBoxCommon( { "butterworth", "unknown", "setOptionVars", $forceFactorySettings } ); // Override default WhichRange to 4 (Selection) // time range: 1: all, 2: playbackRange, 3: start/end, 4: selection if( $forceFactorySettings || !`optionVar -exists butterworthWhichRange` ) { optionVar -intValue butterworthWhichRange 4; } // cutoffFrequency // if ($forceFactorySettings || !`optionVar -exists butterworthCutoffFrequency`) { optionVar -floatValue butterworthCutoffFrequency 7.0; } // samplingRate // if ($forceFactorySettings || !`optionVar -exists butterworthSamplingRate`) { optionVar -floatValue butterworthSamplingRate 30.0; } // keepKeysOnFrame // if ($forceFactorySettings || !`optionVar -exists butterworthKeepKeysOnFrame`) { optionVar -intValue butterworthKeepKeysOnFrame 1; } // preserveKeyTangent // keySetOptionPreserveTangents( {"butterworth", "setOptionVars", $forceFactorySettings} ); } global proc butterworthSetup (string $parent, string $selectionConnection, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars ($forceFactorySettings); setParent $parent; keySetOptionBoxCommon( { "butterworth", $selectionConnection, "setup", 0 } ); // cutoffFrequency // float $cutoffFrequency = `optionVar -query butterworthCutoffFrequency`; floatSliderGrp -edit -value $cutoffFrequency butterworthCutoffFrequency; // samplingRate // float $samplingRate = `optionVar -query butterworthSamplingRate`; floatSliderGrp -edit -value $samplingRate butterworthSamplingRate; // keepKeysOnFrame // int $keepKeysOnFrame = `optionVar -query butterworthKeepKeysOnFrame`; checkBoxGrp -edit -value1 $keepKeysOnFrame butterworthKeepKeysOnFrame; // preserveKeyTangent // keySetOptionPreserveTangents( {"butterworth", "setup"} ); butterworthWidgetsEnable ($selectionConnection); } global proc butterworthCallback( string $parent, int $doIt, string $selectionConnection, int $performAction ) { setParent $parent; keySetOptionBoxCommon( { "butterworth", $selectionConnection, "callback" } ); // cutoffFrequency // optionVar -floatValue butterworthCutoffFrequency `floatSliderGrp -query -value butterworthCutoffFrequency`; // samplingRate // optionVar -floatValue butterworthSamplingRate `floatSliderGrp -query -value butterworthSamplingRate`; // keepKeysOnFrame // optionVar -intValue butterworthKeepKeysOnFrame `checkBoxGrp -query -value1 butterworthKeepKeysOnFrame`; // preserveKeyTangent // keySetOptionPreserveTangents( {"butterworth", "callback"} ); if( $doIt ) { if( butterworthPreviewToolActive() ) { CompleteCurrentTool(); } else { performButterworth( $performAction, $selectionConnection); string $tmpCmd = "performButterworth "; $tmpCmd += "\"" + $performAction + "\", "; $tmpCmd += "\"" + $selectionConnection + "\""; addToRecentCommandQueue $tmpCmd "Butterworth"; } } } // Interactive preview support global proc int butterworthPreviewToolActive() // // Description: // Returns 1 if the preview tool is active, 0 otherwise. // { string $tool = filterButterworthTool(); return (`currentCtx` == $tool); } global proc butterworthPreviewInit( int $state ) // // Description: // Initialize/uninitialize the preview tool depending // on $state. This initialization is responsible for // installing change callbacks on the widgets to invoke // the ($cmd + "PreviewUpdate") callback and update UI // enable states. // { keySetOptionPreviewInit( "butterworth", $state ); string $cb = ""; if( $state ) { $cb = "butterworthPreviewUpdate"; } // Check for existence of UI widgets before updating in case this is invoked // during optionBox UI deletion. if( `floatSliderGrp -ex butterworthCutoffFrequency` ) { floatSliderGrp -e -dragCommand $cb -changeCommand $cb butterworthCutoffFrequency; } if( `floatSliderGrp -ex butterworthSamplingRate` ) { floatSliderGrp -e -dragCommand $cb -changeCommand $cb butterworthSamplingRate; } if( `checkBoxGrp -ex butterworthKeepKeysOnFrame` ) { checkBoxGrp -e -cc1 $cb butterworthKeepKeysOnFrame; } keySetOptionPreserveTangents( {"butterworth", "previewInit", $cb} ); string $applyBtn = getOptionBoxApplyBtn(); int $applyEnable = !$state; button -e -enable $applyEnable $applyBtn; } global proc butterworthPreviewEnable() // // Description: // This callback is invoked when the preview option widget // is checked on. Initialize the preview tool and set it // as the active tool context. // { butterworthPreviewInit(1); butterworthPreviewUpdate(); // Enable filterButterworthCtx string $tool = filterButterworthTool(); if( `currentCtx` != $tool ) { setToolTo $tool; } } global proc butterworthPreviewUpdate() // // Description: // This callback is invoked when preview relevant widget // values change. This update call is responsible for // updating the tool context with the tool parameters. // { string $tool = filterButterworthTool(); // Update the optionVars global string $gOptionBox; butterworthCallback( $gOptionBox, false, "", 0 ); // Update filterButterworthCtx from optionVars int $whichRange = `optionVar -q butterworthWhichRange`; string $range = `optionVar -q butterworthRange`; float $startTime = `playbackOptions -q -min`; float $endTime = `playbackOptions -q -max`; int $selectedKeys = 0; float $cutoff = `optionVar -q butterworthCutoffFrequency`; float $rate = `optionVar -q butterworthSamplingRate`; int $keysOnFrame = `optionVar -q butterworthKeepKeysOnFrame`; if( $whichRange == 4 ) { $selectedKeys = 1; } else if( $whichRange > 2 ) { string $buff[]; tokenize $range ":" $buff; $startTime = $buff[0]; $endTime = $buff[1]; } int $preserveTangents[] = keySetOptionPreserveTangents( {"butterworth", "queryOptionVars"} ); int $preserveFixed = $preserveTangents[0]; int $preserveLinear = $preserveTangents[1]; int $preserveFlat = $preserveTangents[2]; int $preserveSmooth = $preserveTangents[3]; int $preserveStep = $preserveTangents[4]; int $preserveClamped = $preserveTangents[5]; int $preservePlateau = $preserveTangents[6]; int $preserveStepNext = $preserveTangents[7]; int $preserveAuto = $preserveTangents[8]; string $cmd = "filterButterworthCtx -e"; $cmd += " -startTime "; $cmd += $startTime; $cmd += " -endTime "; $cmd += $endTime; $cmd += " -selectedKeys "; $cmd += $selectedKeys; $cmd += " -cutoffFrequency "; $cmd += $cutoff; $cmd += " -samplingRate "; $cmd += $rate; $cmd += " -keepKeysOnFrame "; $cmd += $keysOnFrame; if( $preserveFixed ) { $cmd += " -preserveKeyTangent \"fixed\""; } if( $preserveLinear ) { $cmd += " -preserveKeyTangent \"linear\""; } if( $preserveFlat ) { $cmd += " -preserveKeyTangent \"flat\""; } if( $preserveSmooth ) { $cmd += " -preserveKeyTangent \"smooth\""; } if( $preserveStep ) { $cmd += " -preserveKeyTangent \"step\""; } if( $preserveClamped ) { $cmd += " -preserveKeyTangent \"clamped\""; } if( $preservePlateau ) { $cmd += " -preserveKeyTangent \"plateau\""; } if( $preserveStepNext ) { $cmd += " -preserveKeyTangent \"stepnext\""; } if( $preserveAuto ) { $cmd += " -preserveKeyTangent \"auto\""; } $cmd += (" " + $tool); eval($cmd); } global proc butterworthPreviewDisable() // // Description: // This callback is invoked when the preview option widget // is checked off. Uninitialize the preview tool and cancel // the tool context. // { string $tool = filterButterworthTool(); if( `currentCtx` == $tool ) { escapeCurrentTool(); } butterworthPreviewInit(0); } // Widgets global proc butterworthWidgetsEnable(string $selectionConnection) { keySetOptionBoxCommon( { "butterworth", $selectionConnection, "enable" } ); int $previewActive = butterworthPreviewToolActive(); string $applyBtn = getOptionBoxApplyBtn(); int $applyEnable = !$previewActive; button -e -enable $applyEnable $applyBtn; } proc string butterworthWidgets( string $tabLayout, string $selectionConnection ) { setParent $tabLayout; string $tabForm = `columnLayout -adjustableColumn true`; keySetOptionBoxCommon( { "butterworth", $selectionConnection, "widgets", 1, 0, 1, 1, 1, 1 } ); floatSliderGrp -label (uiRes("m_performButterworth.kCutoffFrequency")) -precision 2 -field true -minValue 0.1 -maxValue 30 -fieldMinValue 0.01 -fieldMaxValue 1000 -value 7.0 -step 0.1 -sliderStep 0.1 -fieldStep 0.1 -ann (uiRes("m_performButterworth.kCutoffFrequencyAnnotation")) butterworthCutoffFrequency; floatSliderGrp -label (uiRes("m_performButterworth.kSamplingRate")) -precision 2 -field true -minValue 1.0 -maxValue 100 -fieldMinValue 1.0 -fieldMaxValue 1000 -value 30.0 -step 1.0 -sliderStep 1.0 -fieldStep 1.0 -ann (uiRes("m_performButterworth.kSamplingRateAnnotation")) butterworthSamplingRate; checkBoxGrp -label (uiRes("m_performButterworth.kKeepKeysOnFrame")) -value1 1 -ann (uiRes("m_performButterworth.kKeepKeysOnFrameAnnotation")) butterworthKeepKeysOnFrame; keySetOptionPreserveTangents( {"butterworth", "widgets"} ); int $previewActive = butterworthPreviewToolActive(); butterworthPreviewInit($previewActive); return $tabForm; } global proc butterworthDoSelectionChanged(string $selectionConnection) // // Description: // Since timeRange is irrelevant when there are // picked keyframes, collapse the timeRange // when there are. (This is hooked in to a SelectionChanged // trigger.) // { keySetOptionBoxCommon( { "butterworth", $selectionConnection, "selectionChanged" } ); butterworthWidgetsEnable ($selectionConnection); } proc butterworthOptions( string $selectionConnection, int $performAction ) { // Customisation options // // Name of the command for this option box (think of it as the base class) string $commandName = "butterworth"; // Title for the option box window string $optionBoxTitle = (uiRes("m_performButterworth.kButterworthCurveOptions")); // Title for the apply button string $applyTitle = (uiRes("m_performButterworth.kApplyAndClose")); // Build the option box "methods" // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); // Build the window, with a tab layout // string $widgetList[] = `getStandardWindow $optionBoxTitle 0 "noOptions"`; setUITemplate -pushTemplate DefaultTemplate; // Make the form invisible while we create the widgets in the window // formLayout -e -vis false $widgetList[1]; // Attach each tab // butterworthWidgets $widgetList[2] $selectionConnection; // Attach the standard buttons // string $buttonList[] = `addStandardButtons $commandName $applyTitle $widgetList[1] $widgetList[2] "noOptions"`; // attach commands to the standard buttons // // Save // button -e -c ($callback + " " + $widgetList[0] + " false \"\" " + $performAction + "; hideOptionBox()") $buttonList[3]; // Close // button -edit -label (uiRes("m_performButterworth.kCancel")) -command ("butterworthPreviewDisable; hideOptionBox") $buttonList[2]; // Reset // button -edit -command ($setup + " " + $widgetList[0] + " " + $selectionConnection + " true") $buttonList[1]; // Do It // button -edit -command ($callback + " " + $widgetList[0] + " true \"" + $selectionConnection + "\"" + $performAction) $buttonList[0]; // Preview close callback keySetOptionPreviewOnClose( "butterworthPreviewDisable" ); // Make the form layout visible so we can see what we built, and // reset the template // formLayout -e -vis true $widgetList[1]; setUITemplate -popTemplate; // Customize the 'Help' menu item text. // This is called from 3 different places so look at the selection // connection to try to figure out which one. // if (match ("graphEditor", $selectionConnection) != "") { setOptionBoxHelpTag( "GraphButterworthCurve" ); } else if (match ("dopeSheet", $selectionConnection) != "") { setOptionBoxHelpTag( "DopeButterworthCurve" ); } else { setOptionBoxHelpTag( "" ); } // Call the setup "method" to fill in the current settings // eval (($setup + " " + $widgetList[0] + " " + $selectionConnection + " false")); showOptionBox(); showWindow $widgetList[0]; butterworthDoSelectionChanged($selectionConnection); scriptJob -protected -event "SelectionChanged" ("butterworthDoSelectionChanged " + $selectionConnection) -parent $widgetList[2]; } proc string assembleCmd( string $selectionConnection, string $options ) { int $preserveTangents[] = keySetOptionPreserveTangents( {"butterworth", "queryOptionVars"} ); int $preserveFixed = $preserveTangents[0]; int $preserveLinear = $preserveTangents[1]; int $preserveFlat = $preserveTangents[2]; int $preserveSmooth = $preserveTangents[3]; int $preserveStep = $preserveTangents[4]; int $preserveClamped = $preserveTangents[5]; int $preservePlateau = $preserveTangents[6]; int $preserveStepNext = $preserveTangents[7]; int $preserveAuto = $preserveTangents[8]; string $cmd = "doButterworthArgList 1 { " + "\"" + `optionVar -q butterworthWhichRange` + "\"" + ",\"" + `optionVar -q butterworthRange` + "\"" + ",\"" + `optionVar -q butterworthCutoffFrequency` + "\"" + ",\"" + `optionVar -q butterworthSamplingRate` + "\"" + ",\"" + `optionVar -q butterworthKeepKeysOnFrame` + "\"" + ",\"" + $preserveFixed + "\"" + ",\"" + $preserveLinear + "\"" + ",\"" + $preserveFlat + "\"" + ",\"" + $preserveSmooth + "\"" + ",\"" + $preserveStep + "\"" + ",\"" + $preserveClamped + "\"" + ",\"" + $preservePlateau + "\"" + ",\"" + $preserveStepNext + "\"" + ",\"" + $preserveAuto + "\"" + ",\"" + $selectionConnection + "\"" + ",\"" + $options + "\"" + " };"; return $cmd; } // The action variable means // 0 - do the command // 1 - show the option box // 2 - return the drag command // 3 - do the command (bufferCurve version) // 4 - show the option box (bufferCurve version) // 5 - return the drag command (bufferCurve version) global proc string performButterworth( int $action, string $selectionConnection ) { string $cmd = ""; switch( $action ) { case 0: setOptionVars( false ); $cmd = assembleCmd( $selectionConnection, "noOptions" ); eval( $cmd ); break; case 1: butterworthOptions( $selectionConnection, 0 ); break; case 2: setOptionVars( false ); $cmd = assembleCmd( $selectionConnection, "noOptions" ); break; case 3: setOptionVars( false ); $cmd = assembleCmd( $selectionConnection, "bufferCurve" ); eval( $cmd ); break; case 4: butterworthOptions( $selectionConnection, 3 ); break; case 5: setOptionVars( false ); $cmd = assembleCmd( $selectionConnection, "bufferCurve" ); break; } return ($cmd); }