No internet connection
  1. Home
  2. How to

How to create an "Apply Fade" option that would also extend the handles on both end of a Clip?

By @Ugosound
    2019-04-10 20:16:11.035Z2019-04-12 14:03:34.019Z

    I already have this command to create Fades:

    sf.ui.proTools.appActivate();
    
    sf.ui.proTools.getMenuItem('Edit', 'Fades', 'Create...').elementClick();
    
    var dlg = sf.ui.proTools.windows.whoseTitle.startsWith('Fade').first.elementWaitFor().element;
    dlg.buttons.whoseTitle.is('OK').first.elementClick();
    

    However, it does not "click OK" automatically.

    But I would like one that extend each clips by 5 Frames on both ends and then apply the fade to the handles length only.
    Here's a screenshot of the clip before the command and how it should look like after the command:

    Maybe even add another function that first that would 1) Trim the Clip to Selection, then 2) create the handles with Fades.

    Thank you!!

    Solved in post #9, click to view
    • 29 replies

    There are 29 replies. Estimated reading time: 17 minutes

    1. Thanks for posting, @Ugosound.

      For the clicking OK in your fade dialog, you need to make sure you wait for the right dialog. In your script, you're waiting for a window to pop up, whose title starts with "Fade". But in reality the window that pops up is called "Batch Fades", so that's the title you need to wait on:

      sf.ui.proTools.appActivate();
      
      sf.ui.proTools.getMenuItem('Edit', 'Fades', 'Create...').elementClick();
      
      var dlg = sf.ui.proTools.windows.whoseTitle.startsWith('Batch Fades').first.elementWaitFor().element;
      dlg.buttons.whoseTitle.is('OK').first.elementClick();
      
      1. In reply toUgosound:

        There are many ways to create fades on both sides of a clip in PT.

        One option (A) is to:

        1. Extend the clip by 5 frames on both sides
        2. Invoke the Batch Fades dialog and select a preset with the correct amount of milliseconds set on both sides, then hit OK

        Another option (B) is to:

        1. Invoke the Batch Fades dialog to create fades on both sides
        2. Use the keyboard to navigate to the first fade, extend it X times with Alt+numpad minus.
        3. Use the keyboard to navigate to the last fade, extend it X times with Cmd+numpad plus.

        IMO option A is better & faster if you can live with having to hard code a millisecond amount that corresponds (almost) to the number of frames needed. Option A also supports if you have loops inside of the selection you're trying to give fades on both sides.

        Option B is better if you can live without loop/intra-clip-edit support and that it's generally slower, however it will allow your fades to be frame accurate 5 frames for non 25fps situations where an even ms length for frames is impossible.

        I have some code for option A that I'm using here internally. I'd be happy to share if you can put it to some use.

        1. U@Ugosound
            2019-04-11 15:38:25.090Z2019-04-12 14:56:05.517Z

            Thank you Christian! @chrscheuer

            Yes, it would be great to see the code for option A!

            It would probably help me create similar ones as well. Looking forward seeing it!

            Also, I corrected the script to Batch Fade and added the "Trim Clip to Selection" Option first:

            sf.ui.proTools.appActivate();
            
            sf.ui.proTools.getMenuItem('Edit', 'Trim Clip', 'To Selection').elementClick();
            
            sf.ui.proTools.getMenuItem('Edit', 'Fades', 'Create...').elementClick();
            
            var dlg = sf.ui.proTools.windows.whoseTitle.startsWith('Batch Fades').first.elementWaitFor().element;
            dlg.buttons.whoseTitle.is('OK').first.elementClick();
            

            That works great, now the clip is being Trimmed first, then applies the fades and closes the window... Just need to add that milliseconds handle extension first!

            PS: How do I create that box to copy the script in the way you did there? If I copy and paste, it removes all the colors and makes it less "readable", so I took a screenshot of it, but then it is not possible for someone else to copy and paste it...

            1. You use 3 backticks (`) on their own line right after each other to denote start of script (and same after)

              1. You can check how I did if you click edit on your original question - I edited it to properly quote the script text :)

                1. I do it like this (modified here, original script longer):

                  function extendSelectionByTwoFramesOnEitherSide() {
                      sf.keyboard.press({ keys: 'alt+shift+numpad minus, alt+shift+numpad minus, cmd+shift+numpad plus, cmd+shift+numpad plus' });
                  }
                  
                  function trim() {
                      sf.ui.proTools.getMenuItem('Edit', 'Trim Clip', 'To Selection').elementClick();
                  }
                  
                  function createFade(presetNum) {
                      sf.ui.proTools.getMenuItem('Edit', 'Fades', 'Create...').elementClick();
                  
                      var win = sf.ui.proTools.windows.whoseTitle.is('Batch Fades').first.elementWaitFor({ timeout: 500 }, 'Could not find Batch Fades window').element;
                      win.buttons.whoseTitle.is('Fade Preset Toggle').allItems[presetNum - 1].elementClick({}, 'Could not click preset button');
                      win.buttons.getByTitle('OK').elementClick();
                  }
                  
                  extendSelectionByTwoFramesOnEitherSide();
                  trim();
                  createFade(1);
                  

                  Note I'm using the Batch Fades preset #1 to adjust settings. I've set the settings for Preset 1 like this:

                  1. I'm using 80 milliseconds here for a film with 25fps framerate (80 ms = 1 / 25 * 1000 * 2) for 2 frames. If you're on 23.976 and would like 5 frames, your milliseconds should be: ( 1 / 23.976 * 1000 * 5 = 208,54 ms ) or just put in 209 ms for a whole number.
                    You also need to change the extendSelectionByTwoFramesOnEitherSide function to extend the selection by 5 frames on each side if you want 5 frames.
                    Note this script requires a nudge setting of 1 frame.

                    1. Here's a longer version of the script that allows you to substitute the frame count for nudging AND that supports verifying to set the nudge value to 1 frame:

                      
                      function ensureGridIsOneFrame() {
                          var nudgeValueField = sf.ui.proTools.mainWindow.gridNudgeCluster.nudgeControls.nudgeValue.invalidate();
                          var nudgeValue = (nudgeValueField.value.value + '').trim();
                          if (nudgeValue.indexOf('+') >= 0) {
                              //Feet+Frames
                              if (nudgeValue != '0+01.00') {
                                  nudgeValueField.elementClick();
                                  sf.keyboard.press({ keys: '0, right, 1, right, 0, enter' });
                              }
                          } else {
                              //Assume timecode
                              if (nudgeValue != '00:00:00:01.00') {
                                  sf.ui.proTools.nudgeSet({ value: '00:00:00:01.00' });
                              }
                          }
                      }
                      
                      function extendSelectionOnEitherSide(frameCount) {
                          ensureGridIsOneFrame(); //You can remove this if it doesn't work for you; optimized for PT2019+
                          sf.keyboard.press({ keys: 'alt+shift+numpad minus', repetitions: frameCount });
                          sf.keyboard.press({ keys: 'cmd+shift+numpad plus', repetitions: frameCount });
                      }
                      
                      function trim() {
                          sf.ui.proTools.getMenuItem('Edit', 'Trim Clip', 'To Selection').elementClick();
                      }
                      
                      function createFade(presetNum) {
                          sf.ui.proTools.getMenuItem('Edit', 'Fades', 'Create...').elementClick();
                      
                          var win = sf.ui.proTools.windows.whoseTitle.is('Batch Fades').first.elementWaitFor({ timeout: 500 }, 'Could not find Batch Fades window').element;
                          win.buttons.whoseTitle.is('Fade Preset Toggle').allItems[presetNum - 1].elementClick({}, 'Could not click preset button');
                          win.buttons.whoseTitle.is('OK').first.elementClick();
                      }
                      
                      sf.ui.proTools.appActivateMainWindow();
                      extendSelectionOnEitherSide(2); //Change to 5 for 5 frames
                      trim();
                      createFade(1); //Change to a different number for a different Batch Fades preset.
                      
                      Reply5 LikesSolution
                      1. U@Ugosound
                          2019-04-12 15:30:39.304Z

                          Amazing! That does it all! Such a time saver... Thank you!

                          1. In reply tochrscheuer:
                            BBen Zenium @Ben_Zenium
                              2020-09-24 10:12:43.284Z

                              Amazing Christian - massive shout to you on this script. I changed to Fill Selection and was away. Awesome work, man!

                              1. In reply tochrscheuer:
                                Jason King @Jason_King
                                  2022-07-10 23:17:58.788Z

                                  This is awesome! This would save sooo much time editing Atmos's! Are these steps available in Macros?

                                  1. No, but you can just create a script and copy paste this into the script. That script can then be used inside other macros by just dragging and dropping it into a macro.

                                    1. Jason King @Jason_King
                                        2022-07-11 00:36:26.635Z

                                        I need to learn how to paste scripts 😆

                                        1. Click "+ New", choose "Script", give it a name, copy the code from above as text, just hit Cmd+V in the script editor inside SF.

                                          1. Jason King @Jason_King
                                              2022-07-11 02:30:20.152Z

                                              So it all can go in 1 line?

                                      • In reply tochrscheuer:
                                        Jason King @Jason_King
                                          2022-07-11 04:02:57.766Z2022-07-11 04:11:23.644Z

                                          Ok @chrscheuer just had a chance to try this but it doesn't work for me. I can see it extending the selection out to frames but the actual region isn't extended. Only the selection.

                                          Ok wait I see what it's doing. Can this be altered to extend already trimmed clips. Just say you edit an entire TV/Film with Atmospheres and each clip is on the cut of a new environment. You want to;

                                          1. Extend (already edited) the clips by x frames along a whole timeline.
                                          2. Batch Fade with preset x
                                          1. Yea but probably better to start as a new thread :)

                                            1. Jason King @Jason_King
                                                2022-07-11 04:58:54.250Z

                                                Copy that @chrscheuer but it looks to me the OP was asking the exact same thing?

                                                "But I would like one that extend each clips by 5 Frames on both ends and then apply the fade to the handles length only."

                                                1. True but this thread has already been marked as solved years ago so you may not get as many responses here. I'm on my vacation right now so I won't have time to build it for you right now - it's usually better to not revive old threads that are marked solved as it makes it difficult for people to see which threads need attention. Better to create a new one and link to this.

                                                  1. Jason King @Jason_King
                                                      2022-07-11 05:17:40.279Z

                                                      No worries. Enjoy your trip Christian!

                                                      New thread here: Extend all clips by 'x' & Batch Fade using Batch Fade preset (whole timeline)

                                              • In reply tochrscheuer:
                                                MManne @Manne
                                                  2022-10-27 14:07:02.909Z

                                                  Hi! This stopped working on the " win.buttons.whoseTitle.is('Fade Preset Toggle').allItems[presetNum - 1].elementClick({}, 'Could not click preset button');" line. Don't know if it's the new PT version.

                                                  1. Yea these have new titles in newer PT versions. I believe @Chris_Shaw was the first to alert me to what they're called now. You should be able to use the UI Picker though to find the reference yourself.

                                                    1. In reply toManne:
                                                      MMikko Roisko @Mikko_Roisko
                                                        2023-12-15 22:18:13.415Z

                                                        Hi Manne! Did you ever figure out what you need to change in order to get this script to work on latest Pro Tools versions? Would love to use this!

                                        • K
                                          In reply toUgosound:
                                          Kenneth Skoglund @Kenneth_Skoglund
                                            2020-09-01 16:50:08.464Z

                                            New to this, but this script is just what I have been looking for, great!
                                            In my PT version (2019.6) I had to change Trim Clip/To Selection to Trim Clip/To Fill Selection to get it to work.
                                            A question, been trying with not much luck...
                                            If I have automation on the clip, lets say volume. In PT, If I use the trimmer to extend the clip, automation will follow, but not when I trim to fill selection, so when I use this script on clips with automation, it will not follow the extended clip, is there a way to have the automation follow the trim? Or is there another script to add to fix this?
                                            Thanks, Ken

                                            1. Hi Ken. I didn't see your post here since you replied in a closed thread. Thanks for reminding us.
                                              Generally, it's better to start a new thread and link to the existing thread :)

                                              This behavior appears to be a limitation in how the Pro Tools commands you mentioned work.
                                              To automate something, the first step would still be to figure out a sequence of manual commands that could work in Pro Tools. So in this case the only thing I could think of would be positioning the cursor towards the end of the clip, engaging Preview on all parameters on the track, then expanding the selection and finally writing auto to selection. That's just to extend the automation at one end. Then that would need to be coupled with any other sequencing of commands you were already doing.

                                              1. KKenneth Skoglund @Kenneth_Skoglund
                                                  2020-09-04 11:46:24.019Z

                                                  Hi Christian, yeah, not used to this type of forum, its kinda different. My new post was weird also, and I could not delete it.

                                                  Thanks. I'll try that, I also tried the script that clears automation on clip edges, might work with some mods, if I can figure out how, :)

                                                  1. Sounds good! Happy to help if you get stuck :)
                                                    But yea, the first thing is to figure out the manual sequence of commands that need to run, respecting that those cannot be mouse movements across the clips (as SF wouldn't be able to automate that).

                                              2. K
                                                In reply toUgosound:
                                                Kenneth Skoglund @Kenneth_Skoglund
                                                  2020-09-04 13:32:59.306Z

                                                  How do you copy and paste an action in the editor?

                                                  1. K
                                                    In reply toUgosound:
                                                    Kenneth Skoglund @Kenneth_Skoglund
                                                      2020-09-04 14:08:00.932Z

                                                      Since I don't have any plugs in my film at this point, I only need to move volume automation. I figured this will do it for now. It works, if I'm sure I start from the right mode and window focus... I had to use Keyboard strokes, even though I saw on the videos that it's not the greatest. Gonna work on a better solution once I have more time.

                                                      sf.ui.proTools.viewCloseFocusedFloatingWindow();

                                                      sf.keyboard.press({
                                                      keys: "alt+minus",
                                                      });
                                                      sf.keyboard.press({
                                                      keys: "alt+tab, alt+shift+numpad minus, numpad minus, numpad minus, numpad minus",
                                                      });
                                                      sf.keyboard.press({
                                                      keys: "tab, tab, cmd+shift+numpad plus, numpad plus, numpad plus, numpad plus",
                                                      });