No internet connection
  1. Home
  2. Macro and Script Help

Scripts are broken in newer versions of Sould Flow

By Ron Eng @Ron_Eng
    2024-05-17 23:04:21.420Z

    Title

    Scripts are broken in newer versions of Sould Flow

    What do you expect to happen when you run the script/macro?

    This is a friend's Auto Align script that works in SF 5.5.4 but breaks in any higher version at or around line 109.

    Why would things break in newer versions, wouldn't it be the exact opposite?

    Ron Eng

    Are you seeing an error?

    prompt on screen

    What happens when you run this script?

    copies regions to be auto aligned, up to work tracks, handles them out 12 seconds on beginning and ending of file. Auto Aligns them and restores the original duration of file and splits them files down to their original tracks

    How were you running this script?

    I used a keyboard shortcut within the target app

    How important is this issue to you?

    5

    Details

    {
        "inputExpected": "This is a friend's Auto Align script that works in SF 5.5.4 but breaks in any higher version at or around line 109.\n\nWhy would things break in newer versions, wouldn't it be the exact opposite?\n\nRon Eng",
        "inputIsError": true,
        "inputError": "prompt on screen",
        "inputWhatHappens": "copies regions to be auto aligned, up to work tracks, handles them out 12 seconds on beginning and ending of file.  Auto Aligns them and restores the original duration of file and splits them files down to their original tracks",
        "inputHowRun": {
            "key": "-Mpfwh4RkPLb2LPwjePT",
            "title": "I used a keyboard shortcut within the target app"
        },
        "inputImportance": 5,
        "inputTitle": "Scripts are broken in newer versions of Sould Flow"
    }

    Source

    //Track selection memory
    globalState.selectedTracks = sf.ui.proTools.selectedTrackNames;
    
    
    //Timeline selection memory
    globalState.rememberedSelection = sf.ui.proTools.selectionGet();
    
    
    sf.ui.proTools.appActivateMainWindow();
    sf.ui.proTools.mainWindow.invalidate();
    
    
    sf.ui.proTools.zoomPreset({
        zoomPreset: 1,
    });
    
    //Copy clips
    sf.ui.proTools.menuClick({ menuPath: ["Edit", "Copy"] });
    
    
    sf.ui.proTools.trackSelectByName({
        names: ["WORK 1","WORK 2"],
    });
    
    //Paste Clips
    sf.ui.proTools.menuClick({ menuPath: ["Edit", "Paste"] });
    
    sf.wait({
        intervalMs: 500,
    });
    
    //time selection
    sf.ui.proTools.nudgeSet({
        value: "120000",
    });
    
    sf.wait({
        intervalMs: 250,
    });
    
    sf.keyboard.press({
        keys: "shift+alt+numpad minus",
    });
    
    sf.wait({
        intervalMs: 250,
    });
    
    sf.keyboard.press({
        keys: "shift+cmd+numpad plus",
    });
    
    sf.wait({
        intervalMs: 250,
    });
    
    // Trim Clip to Boundaries
    sf.ui.proTools.menuClick({ menuPath: ["Edit", "Trim Clip", "To Fill Selection"] });
    
    sf.wait({
        intervalMs: 250,
    });
    
    /*
    // Trim Clip to Boundaries
    sf.ui.proTools.menuClick({ menuPath: ["Edit", "Trim Clip", "To File Boundaries"] });
    */
    
    sf.wait({
        intervalMs: 250,
    });
    
    // Remove edit from top
    sf.ui.proTools.menuClick({ menuPath: ["Edit", "Selection", "Remove Edit from Top"] });
    
    sf.wait({
        intervalMs: 250,
    });
    
    //Activate Auto-Align Post
    var asWin = sf.ui.proTools.getAudioSuiteWindow("Auto-Align Post");
    if (!asWin.exists) {
        asWin = sf.ui.proTools.audioSuiteOpenPlugin({
            category: "Other",
            name: "Auto-Align Post",
        }).window;
    }
    
    sf.wait({
        intervalMs: 250,
    });
    
    //Set processing options
    asWin.audioSuiteSetOptions({
        processingInputMode: "ClipByClip",
        processingOutputMode: "CreateIndividualFiles"
    });
    
    //Open sidechain menu and select track "DX x"
    sf.ui.proTools.firstAudioSuiteWindow.popupButtons.whoseTitle.is('Key Input').first.popupMenuSelect({
        menuPath: ["WORK 1"],
    });
    
        // Render
        asWin.audioSuiteRender();
    
    sf.wait({
        intervalMs: 1000,
    });
    
    //Timeline selection memory
    globalState.rememberedSelection = sf.ui.proTools.selectionGet();
    
    sf.wait({
        intervalMs: 250,
    });
    
    //Reselect previous tracks
    sf.ui.proTools.trackSelectByName({
        names: globalState.selectedTracks
    });
    
    sf.wait({
        intervalMs: 1000,
    });
    
    //Recall selection from globalState variable 'rememberedSelection'
    sf.ui.proTools.selectionSet({
        selectionStart: globalState.rememberedSelection.selectionStart,
        selectionLength: globalState.rememberedSelection.selectionLength,
    });
    
    sf.wait({
        intervalMs: 250,
    });
    
    const originalTrackNames = sf.ui.proTools.selectedTrackNames;
    
    sf.ui.proTools.trackSelectByName({
        names: ["WORK 1","WORK 2", "WORK 3"],
    });
    
    sf.wait({
        intervalMs: 250,
    });
    
    sf.ui.proTools.appActivateMainWindow();
    sf.ui.proTools.mainWindow.invalidate();
    
    sf.wait({
        intervalMs: 250,
    });
    
    sf.ui.proTools.menuClick({ menuPath: ["Edit", "Trim Clip", "To Selection"] });
    
    sf.wait({
        intervalMs: 250,
    });
    
    //Cut clips
    sf.ui.proTools.menuClick({ menuPath: ["Edit", "Cut"] });
    
    sf.wait({
        intervalMs: 250,
    });
    
    //Reselect previous tracks
    sf.ui.proTools.trackSelectByName({
        names: originalTrackNames
    });
    
    sf.wait({
        intervalMs: 250,
    });
    
    //Paste Clips
    sf.ui.proTools.menuClick({ menuPath: ["Edit", "Paste"] });
    
    sf.wait({
        intervalMs: 250,
    });
    
    sf.keyboard.press({
        keys: "semicolon",
    });
    
    sf.wait({
        intervalMs: 250,
    });
    
    sf.ui.proTools.zoomPreset({
        zoomPreset: 5,
    });
    
    sf.wait({
        intervalMs: 250,
    });
    
    sf.keyboard.press({
        keys: "w",
    });
    
    sf.wait({
        intervalMs: 250,
    });
    
    sf.ui.proTools.zoomPreset({
        zoomPreset: 5,
    });
    

    Links

    User UID: p6aSyHdDkhOOgvXKWhz3hgbmXL23

    Feedback Key: sffeedback:p6aSyHdDkhOOgvXKWhz3hgbmXL23:-Ny7n8dSmmHIZ8ueFV5O

    Feedback ZIP: 9kzkxl4uN4CKz13CkpTvt+y1dxKjJhOOEQBBHUnDKK9lNhNDrHDqr6wPi8LXvaO00xcUTlPdWsummv7J5G1AiKuiTckrRpQdeoZhv20LOjuZK4Xlq6KH8+8VRdZWc+mMy8AotYIxPn1HiIF5NQvb7aRNuP5Bb/cvA+LPwVEQKEDRNx/c3Be9DGXGTlCDIVBRHMsTOFWAlF8Ay6q9KTuMy8/HteUhweR3tTYSjOW+YJIGd+Z+RVrxGwChTrRtUefC4L1+JsOwAU3IoRKVeZQW4YuIuAqkq4Lv1EOzjJ5KLKRqPLYm7+YpU889npnDWifGLkFY7MzoXQUhl3nYyalOTg==

    • 5 replies
    1. See if changing the 2nd line to this helps:

      globalState.selectedTracks = sf.ui.proTools.selectedTrackNames.slice();
      
      1. OOwen Granich-Young @Owen_Granich_Young
          2024-05-20 18:03:20.211Z2024-05-20 21:14:36.276Z

          Hey Ron, I think we can lvl this script up ;) As long as you're on PT 2022 or later this should do ya a bit better (needs protools SDK.) You'll see at the top you can set your work tracks, and then on the last line(line 100) you can set your handle length in seconds (currently set to 12) Let me know if it's not working.

          @chrscheuer on line 52 I've had to put a manual wait in... the script was running line 54 before 51 could run. Any idea on a better work around for that?

          const workTracks = ["WORK 1", "WORK 2", "WORK 3"] //// SET WORK TRACKS HERE
          
          ////Handle Adding Function
          
          function addHandles(numberOfSeconds, ogSelection) {
              let sesisonSampleRate = sf.app.proTools.getSessionSampleRate().sampleRateNumerical
              /* let ogSelection = sf.app.proTools.getTimelineSelection(); */
              let aHandle = (Number(ogSelection.inTime) - (sesisonSampleRate * numberOfSeconds)).toString();
              let bHandle = (Number(ogSelection.outTime) + (sesisonSampleRate * numberOfSeconds)).toString();
              sf.app.proTools.setTimelineSelection({
                  inTime: aHandle,
                  outTime: bHandle
              })
              sf.ui.proTools.menuClick({ menuPath: ["Edit", "Trim Clip", "To Selection"] });
          }
          
          /// Main Function
          function autoAlignOnWorkTracks(handleLength) {
          
              sf.ui.proTools.appActivateMainWindow();
              sf.ui.proTools.invalidate();
          
              ///GET TRACK INFO ALL
              let trckInfo = sf.app.proTools.tracks.invalidate().allItems.map(m => {
                  let mappedProps = {};
          
                  for (let prop in m) {
                      const itemsToSkip = ["Parent", "FriendlyNodeName", "SupportsAutoUpdate"];
          
                      if (!itemsToSkip.includes(prop)) {
                          const lowerCasePropName = prop.slice(0, 1).toLowerCase() + prop.slice(1);
                          mappedProps[lowerCasePropName] = m[prop];
                      }
                  }
                  return mappedProps;
              });
              //// Get Selected Tracks as Name Only String Array
              let slctdTrcks = trckInfo.filter(track => track.isSelected === true).map(track => track.name)
              ////Get Selected Track Count
          
              /// Cut Selected Clips
              sf.app.proTools.cut()
              /// Select Work Tracks
              sf.app.proTools.selectTracksByName({ trackNames: workTracks, selectionMode: "Replace" })
              /// Paste Clips
              sf.app.proTools.paste()
              /// Get Original Selection
              let ogSelection = sf.app.proTools.getTimelineSelection()
              /// addHandles Variable Length
              addHandles(handleLength, ogSelection)
              sf.ui.proTools.menuClick({ menuPath: ["Edit", "Trim Clip", "To Fill Selection"] });
              sf.wait({    intervalMs: 250,}); //// I SHOULDN'T NEED THIS! WHYYYYYY....
              /// De-select work 1
              sf.app.proTools.selectTracksByName({ trackNames: [workTracks[0]], selectionMode: "Subtract" })
              ///Check Status of Auto Align
              const aApostIsOpen = sf.ui.proTools.windows.whoseTitle.is("Audio Suite: Auto-Align Post").first.exists
              if (aApostIsOpen) {
                  sf.ui.proTools.windows.whoseTitle.is("Audio Suite: Auto-Align Post").first.elementRaise();
              } else {
                  sf.ui.proTools.audioSuiteOpenPlugin({
                      category: "Other",
                      name: "Auto-Align Post",
                  });
              }
              /// Define Auto-Align Window
              let win = sf.ui.proTools.firstAudioSuiteWindow
              /// Set Processing Options
              win.audioSuiteSetOptions({
                  processingInputMode: 'ClipByClip',
                  processingOutputMode: `CreateIndividualFiles`,
              });
          
              const sideChainButton = win.popupButtons.allItems[4]
              /// Set Sidechain to Work Track 1 if It's not set
              if (sideChainButton.title.value != workTracks[0]) {
                  sideChainButton.popupMenuSelect({ menuPath: [workTracks[0]] })
              };
          
              /// Render Auto-Align
              win.audioSuiteRender();
              /// Wait For Render to Finish
              sf.ui.proTools.waitForNoModals();
              /// Re-Close Auto Align if it was Open
              if (!aApostIsOpen) { win.windowClose({}, `Could not find Audiosuite Window`); }
              //// Re-Select Work 1
              sf.app.proTools.selectTracksByName({ trackNames: [workTracks[0]], selectionMode: "Add" })
              /// Set Original Selection
              sf.app.proTools.setTimelineSelection({
                  inTime: ogSelection.inTime,
                  outTime: ogSelection.outTime
              })
              ///Trim to original Selction
              sf.app.proTools.trimToSelection()
              ///Move to Original Tracks
              sf.app.proTools.cut()
              sf.app.proTools.selectTracksByName({ trackNames: slctdTrcks })
              sf.app.proTools.paste();
          }
          
          
          autoAlignOnWorkTracks(12); /// SET HANDLE LENGTH HERE
          
          1. Because I wanted to see if I could... This one you can do multiple clips, here's a demo of it in action... https://www.dropbox.com/s/qde5rrobhl3rh7t/Auto Align with Handles Multi Clip.mov?dl=0 I'm pretty happy with the results.

            const workTracks = ["WORK 1", "WORK 2", "WORK 3"] //// SET WORK TRACKS HERE
            
            ////Handle Adding Function
            
            function addHandles(numberOfSeconds, ogSelection) {
                let sesisonSampleRate = sf.app.proTools.getSessionSampleRate().sampleRateNumerical
                /* let ogSelection = sf.app.proTools.getTimelineSelection(); */
                let aHandle = (Number(ogSelection.inTime) - (sesisonSampleRate * numberOfSeconds)).toString();
                let bHandle = (Number(ogSelection.outTime) + (sesisonSampleRate * numberOfSeconds)).toString();
                sf.app.proTools.setTimelineSelection({ inTime: aHandle, outTime: bHandle })
                sf.ui.proTools.menuClick({ menuPath: ["Edit", "Trim Clip", "To Selection"] });
            }
            
            
            function autoAlignOnWorkTracks(handleLength) {
            
                sf.ui.proTools.appActivateMainWindow();
                sf.ui.proTools.invalidate();
            
                ///GET TRACK INFO ALL
                let trckInfo = sf.app.proTools.tracks.invalidate().allItems.map(m => {
                    let mappedProps = {};
            
                    for (let prop in m) {
                        const itemsToSkip = ["Parent", "FriendlyNodeName", "SupportsAutoUpdate"];
            
                        if (!itemsToSkip.includes(prop)) {
                            const lowerCasePropName = prop.slice(0, 1).toLowerCase() + prop.slice(1);
                            mappedProps[lowerCasePropName] = m[prop];
                        }
                    }
                    return mappedProps;
                });
            
            
                //// Get Selected Tracks as Name Only String Array
                let slctdTrcks = trckInfo.filter(track => track.isSelected === true).map(track => track.name)
            
                sf.app.proTools.selectTracksByName({ trackNames: [slctdTrcks[0]], selectionMode: "Replace" })
            
                sf.ui.proTools.clipDoForEachSelectedClip({
                    action: () => {
                        ///ReSelect slecteTrks
                        sf.app.proTools.selectTracksByName({trackNames : slctdTrcks, selectionMode :"Replace"})
                        /// Cut Selected Clips
                        sf.app.proTools.cut()
                        /// Select Work Tracks
                        sf.app.proTools.selectTracksByName({ trackNames: workTracks, selectionMode: "Replace" })
                        /// Paste Clips
                        sf.app.proTools.paste()
                        /// Get Original Selection
                        let ogSelection = sf.app.proTools.getTimelineSelection()
                        /// addHandles Variable Length
                        addHandles(handleLength, ogSelection)
                        sf.ui.proTools.menuClick({ menuPath: ["Edit", "Trim Clip", "To Fill Selection"] });
                        sf.wait({ intervalMs: 250, }); //// I SHOULDN'T NEED THIS! WHYYYYYY....
                        /// De-select work 1
                        sf.app.proTools.selectTracksByName({ trackNames: [workTracks[0]], selectionMode: "Subtract" })
                        ///Check Status of Auto Align
                        const aApostIsOpen = sf.ui.proTools.windows.whoseTitle.is("Audio Suite: Auto-Align Post").first.exists
                        if (aApostIsOpen) {
                            sf.ui.proTools.windows.whoseTitle.is("Audio Suite: Auto-Align Post").first.elementRaise();
                        } else {
                            sf.ui.proTools.audioSuiteOpenPlugin({ category: "Other", name: "Auto-Align Post", });
                        }
                        /// Define Auto-Align Window
                        let win = sf.ui.proTools.firstAudioSuiteWindow
                        /// Set Processing Options
                        win.audioSuiteSetOptions({ processingInputMode: 'ClipByClip', processingOutputMode: `CreateIndividualFiles`, });
                        const sideChainButton = win.popupButtons.allItems[4]
                        /// Set Sidechain to Work Track 1 if It's not set
                        if (sideChainButton.title.value != workTracks[0]) { sideChainButton.popupMenuSelect({ menuPath: [workTracks[0]] }) };
                        /// Render Auto-Align
                        win.audioSuiteRender();
                        /// Wait For Render to Finish
                        sf.ui.proTools.waitForNoModals();
                        /// Re-Close Auto Align if it was Open
                        if (!aApostIsOpen) { win.windowClose({}, `Could not find Audiosuite Window`); }
                        //// Re-Select Work 1
                        sf.app.proTools.selectTracksByName({ trackNames: [workTracks[0]], selectionMode: "Add" })
                        /// Set Original Selection
                        sf.app.proTools.setTimelineSelection({ inTime: ogSelection.inTime, outTime: ogSelection.outTime })
                        ///Trim to original Selction
                        sf.app.proTools.trimToSelection()
                        ///Move to Original Tracks
                        sf.app.proTools.cut()
                        sf.app.proTools.selectTracksByName({ trackNames: slctdTrcks })
                        sf.app.proTools.paste();
                        /* sf.app.proTools.selectTracksByName({ trackNames: [slctdTrcks[0]], selectionMode: "Replace" }) */
                    }
                });
            
            
            
            }
            
            autoAlignOnWorkTracks(12); /// SET HANDLE LENGTH HERE
            
        • R
          In reply toRon_Eng:
          Ron Eng @Ron_Eng
            2024-05-20 23:49:34.844Z

            Thanks Owen and Christian, I will check this out later today- I didn't know that my emails to support went into the forum (and also to look for replies there). Muxch appreciated. Ron Engf

            1. RRon Eng @Ron_Eng
                2024-05-20 23:50:14.707Z

                Sorry typo on my name: Ron Eng