No internet connection
  1. Home
  2. How to

Script that extends each clip in selection by one frame on the head and tail, then applies a two frame fade in and fade out?

By AMPM101 @AMPM101
    2023-07-21 01:59:08.871Z

    For easy BG editing -- just looking to make a selection of checkerboarded clips and have the script take care of extending and fading.

    Solved in post #5, click to view
    • 4 replies
    1. O

      Built 2 ways.

      1. AAMPM101 @AMPM101
          2023-07-21 15:24:31.234Z

          This is great. However it uses batch fades -- is there a version that uses an exact 2 frame fade in and fade out? It would probably have to go clip by clip and extend, then move the cursor two frames, fade-in, tab to the end, move the cursor two frames in, fade-out, move to next clip, etc.

          Also, the replies at the bottom of the above suggest the script no longer works in the latest versions of PT?

          1. I don't have PT right now (left the ilok at work) but try this... it's basically @samuel_henriques script except it tries to use set selection instead of batch fade for the fades. 100% untested...

            /**
            * @param {number} extendFrames
            */
            function tirmAndFade(extendFrames) {
                const frameRate = 23.976
                const sampleRate = 48000
                const extendAmount = sampleRate / frameRate * extendFrames
                const currentSelection = sf.ui.proTools.selectionGetInSamples()
            
                sf.ui.proTools.selectionSetInSamples({
                    selectionStart: +currentSelection.selectionStart - extendAmount,
                    selectionEnd: +currentSelection.selectionEnd + extendAmount,
                });
            
                sf.ui.proTools.menuClick({ menuPath: ["Edit", "Trim Clip", "To Fill Selection"] });
            
            
                sf.ui.proTools.selectionSetInSamples({
                    selectionStart: +currentSelection.selectionStart + extendAmount,
                    selectionLength: 0,
                })
            
                sf.keyboard.press({ keys: "d" });
                sf.wait({ intervalMs: 50 })
            
                sf.ui.proTools.selectionSetInSamples({
                    selectionStart: +currentSelection.selectionEnd - extendAmount,
                    selectionLength: 0,
                })
            
                sf.keyboard.press({ keys: "g" });
                sf.wait({ intervalMs: 50 })
            
            };
            
            
            
            function main() {
            
                sf.ui.proTools.appActivateMainWindow();
            
                sf.ui.proTools.invalidate();
            
                //Get selected tracks
                const originalTracks = sf.ui.proTools.selectedTrackNames;
            
                //Do for each track.
                sf.ui.proTools.selectedTracks.trackHeaders.slice().map(track => {
            
                    //Select track
                    track.trackSelect();
            
                    //Scroll track into View
                    track.trackScrollToView();
            
                    //Do for each clip on Track
                    sf.ui.proTools.clipDoForEachSelectedClip({
                        action: () => {
                            tirmAndFade(1);
                        },
                        onError: "Continue",
                    });
                });
            
                //Restore previously selected tracks
                sf.ui.proTools.trackSelectByName({ names: originalTracks });
            
            };
            
            
            main();
            
            1. samuel henriques @samuel_henriques
                2023-07-27 09:26:20.939Z2023-07-27 12:24:01.057Z

                here's a slightly more stable/faster trimAndFade function.
                @AMPM101, either of these scripts will extend by the length you set at line 59 trimAndFade(1) and make a fade of twice the length.
                that means you'll get this, with both fades equal.

                If you want one frame extension and one frame fade,

                you can remove + extendAmount on line 19 and - extendAmount on line 27 on Owen's script.
                Or if you want the function I updated, remove the same but on lines 18 and 19.
                Remember to set your frame rate and sampleRate so you get the correct frame length.

                /**
                * @param {number} extendFrames
                */
                function tirmAndFade(extendFrames) {
                    const frameRate = 23.976
                    const sampleRate = 48000
                    const extendAmount = sampleRate / frameRate * extendFrames
                    const currentSelection = sf.ui.proTools.selectionGetInSamples()
                
                    sf.ui.proTools.selectionSetInSamples({
                        selectionStart: +currentSelection.selectionStart - extendAmount,
                        selectionEnd: +currentSelection.selectionEnd + extendAmount,
                    });
                
                    sf.ui.proTools.menuClick({ menuPath: ["Edit", "Trim Clip", "To Fill Selection"] });
                
                    sf.ui.proTools.selectionSetInSamples({
                        selectionStart: +currentSelection.selectionStart + extendAmount,
                        selectionEnd: +currentSelection.selectionEnd - extendAmount,
                    });
                
                    sf.ui.proTools.menuClick({ menuPath: ["Edit", "Fades", "Fade to Start"] });
                    sf.ui.proTools.menuClick({ menuPath: ["Edit", "Fades", "Fade to End"] });
                };
                
                
                
                function main() {
                
                    sf.ui.proTools.appActivateMainWindow();
                
                    sf.ui.proTools.invalidate();
                
                    //Get selected tracks
                    const originalTracks = sf.ui.proTools.selectedTrackNames;
                
                    //Do for each track.
                    sf.ui.proTools.selectedTracks.trackHeaders.slice().map(track => {
                
                        //Select track
                        track.trackSelect();
                
                        //Scroll track into View
                        track.trackScrollToView();
                
                        //Do for each clip on Track
                        sf.ui.proTools.clipDoForEachSelectedClip({
                            action: () => {
                                tirmAndFade(1);
                            },
                            onError: "Continue",
                        });
                    });
                
                    //Restore previously selected tracks
                    sf.ui.proTools.trackSelectByName({ names: originalTracks });
                
                };
                
                
                main();
                
                Reply3 LikesSolution