No internet connection
  1. Home
  2. Script Sharing

Auto_Align Post Macro by @Owen_Granich_Young

By Jason Freeman @Jason_Freeman
    2024-04-05 18:01:25.248Z

    @Owen_Granich_Young
    Per our convo on the sound radix forum, could you please post your auto-align post reference track macro, please and thank you!!

    • 7 replies
    1. O
      Owen Granich-Young @Owen_Granich_Young
        2024-04-05 18:18:00.630Z2025-02-11 03:32:06.938Z

        You bet Jason!

        Here's the one for ADR, highlight all the tracks and then press the button and it selects all the even tracks and processes them to the track above them. (Currently Y on my keyboard that's how much I'm using it, lol) This also works for a single pair if you highlight two tracks it will auto align the bottom one to the top one.

        const firstAudioSuiteWindow = sf.ui.proTools.firstAudioSuiteWindow;
        const originalTimelineSeleciton = sf.app.proTools.getTimelineSelection();
        
        function setupAndRestore(callback) {
            sf.ui.proTools.appActivateMainWindow();
            sf.ui.proTools.invalidate();
        
            const videoWindowMenuItem = sf.ui.proTools.getMenuItem('Window', 'Video');
        
            const initialViews = {
                isVideoWinOpen: videoWindowMenuItem.getString('AXMenuItemMarkChar') === ('-') || videoWindowMenuItem.isMenuChecked,
                isFloatingWindowsEnabled: sf.ui.proTools.getMenuItem('Window', 'Hide All Floating Windows').isMenuChecked,
            }
        
            const { isVideoWinOpen, isFloatingWindowsEnabled } = initialViews;
        
            if (isVideoWinOpen) { sf.ui.proTools.menuClick({ menuPath: ['Window', 'Video'], }); }
            if (!isFloatingWindowsEnabled) { sf.ui.proTools.menuClick({ menuPath: ['Window', 'Hide All Floating Windows'], }); }
        
            try {
        
                callback();
        
            } finally {
        
                const modifiedViews = {
                    isVideoWinOpen: (videoWindowMenuItem.getString('AXMenuItemMarkChar') === ('-') || videoWindowMenuItem.isMenuChecked) !== initialViews.isVideoWinOpen,
                    isFloatingWindowsEnabled: sf.ui.proTools.getMenuItem('Window', 'Hide All Floating Windows').isMenuChecked !== initialViews.isFloatingWindowsEnabled,
                }
        
                const { isVideoWinOpen, isFloatingWindowsEnabled } = modifiedViews;
        
                if (isVideoWinOpen) { sf.ui.proTools.menuClick({ menuPath: ['Window', 'Video'], }); }
                if (isFloatingWindowsEnabled) { sf.ui.proTools.menuClick({ menuPath: ['Window', 'Hide All Floating Windows'], }); }
            }
        }
        
        function getPrecedingTrackName() {
            const tracks = sf.app.proTools.tracks.invalidate().allItems;
            const visibleTrackNames = tracks.filter(t => !t.isHidden).map(t => t.name);
            const selectedTrackName = tracks.find(t => !t.isHidden && t.isSelected).name;
            const selectedTrackIndex = visibleTrackNames.indexOf(selectedTrackName);
            return visibleTrackNames[selectedTrackIndex - 1];
        }
        
        function doForAllSelectedTracks(action) {
            const tracks = sf.app.proTools.tracks.invalidate().allItems;
        
            var originallySelectedTrackNames = tracks.filter(t => !t.isHidden && t.isSelected).map(t => t.name);
        
            try {
                originallySelectedTrackNames.forEach(trackName => {
                    sf.app.proTools.selectTracksByName({ trackNames: [trackName] });
                    action();
                });
            }
            finally {
                sf.app.proTools.selectTracksByName({ trackNames: originallySelectedTrackNames });
            }
        }
        
        function autoAlignEachSet() {
            const selectedTrackName = sf.app.proTools.tracks.invalidate().allItems.find(t => !t.isHidden && t.isSelected);
        
            const sideChainButton = firstAudioSuiteWindow.popupButtons.getByTitle("Key Input");
        
            if (sideChainButton.exists && selectedTrackName) {
        
                const precedingTrackName = getPrecedingTrackName();
        
                sideChainButton.popupMenuSelect({ menuPath: [precedingTrackName], });
            }
        
            firstAudioSuiteWindow.audioSuiteRender();
        
            sf.ui.proTools.waitForNoModals();
        
            const { inTime, outTime } = originalTimelineSeleciton;
        
            sf.app.proTools.setTimelineSelection({ inTime, outTime, });
        }
        
        function main() {
            setupAndRestore(() => {
                const isAutoAlignPostOpen = sf.ui.proTools.windows.whoseTitle.is("Audio Suite: Auto-Align Post").first.exists
        
                const selectedTrackNames = sf.app.proTools.tracks.invalidate().allItems.filter(t => !t.isHidden && t.isSelected).map(t => t.name);
        
                const everyOtherTrackNames = selectedTrackNames.filter((_, index) => index % 2 === 1);
        
                sf.app.proTools.selectTracksByName({ trackNames: everyOtherTrackNames, selectionMode: "Replace" });
        
                if (isAutoAlignPostOpen) {
        
                    sf.ui.proTools.windows.whoseTitle.is("Audio Suite: Auto-Align Post").first.elementRaise();
        
                } else {
        
                    sf.ui.proTools.audioSuiteOpenPlugin({ category: "Other", name: "Auto-Align Post", });
                }
        
                firstAudioSuiteWindow.audioSuiteSetOptions({
                    processingInputMode: 'ClipByClip',
                    processingOutputMode: `CreateIndividualFiles`,
                });
        
                doForAllSelectedTracks(autoAlignEachSet)
        
                if (!isAutoAlignPostOpen) {
                    firstAudioSuiteWindow.windowClose({}, `Could not find Audiosuite Window`);
                }
            });
        }
        
        main();
        

        And this one select the tracks you want auto aligned (say a few character's lav mics) and they will all align to the track ABOVE the ones selected. It's a little funky that this one you don't select the guide track as the top most, but I think I'm ok with it.

        function getBeforeSelectedTrackName() {
        
            const visibleTrackNames = sf.ui.proTools.visibleTrackNames
        
            const selectedTrackName = sf.ui.proTools.selectedTrackNames[0]
        
            const selectedTrackIndex = visibleTrackNames.indexOf(selectedTrackName)
        
            return visibleTrackNames[selectedTrackIndex - 1]
        
        }
        
        function main() {
            sf.ui.proTools.appActivateMainWindow();
            sf.ui.proTools.invalidate();
            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",
                });
            }
        
            let win = sf.ui.proTools.firstAudioSuiteWindow
        
        
            win.audioSuiteSetOptions({
                processingInputMode: 'ClipByClip',
                processingOutputMode: `CreateIndividualFiles`,
            });
        
            const selectedTrackName = sf.ui.proTools.selectedTrackNames[0]
            const sideChainButton = win.popupButtons.allItems[4]
        
            if (sideChainButton.exists && selectedTrackName) {
                sideChainButton.popupMenuSelect({
                    menuPath: [getBeforeSelectedTrackName()],
                });
            }
        
            win.audioSuiteRender();
        
            sf.ui.proTools.waitForNoModals();
        
            if(!aApostIsOpen){
            win.windowClose({}, `Could not find Audiosuite Window`);
            }
        }
        
        main();
        

        Happy Aligning
        Owen

        EDIT UPDATE SCRIPT 1 SDK FIXED up Thanks to @Kitch

        1. J
          In reply toJason_Freeman:
          Jason Freeman @Jason_Freeman
            2024-04-05 18:37:11.088Z

            Amazing! Im going to give these a try right now.

            1. JJason Freeman @Jason_Freeman
                2024-04-05 19:24:29.316Z

                OMG! This is EXACTLY what I have been looking for! You just saved me countless amounts of clicking and moving clips around. THANK YOU!

              • D
                In reply toJason_Freeman:
                danielkassulke @danielkassulke
                  2024-04-06 08:10:14.781Z

                  @Owen_Granich_Young this code absolutely rips. Thanks!

                  1. Just cobbled together from @samuel_henriques and @Kitch code. @Brian_Armstrong got me building it in the first place. I’ve actually never owned auto align without it, I can’t imagine using it with out lol. So many clicks.

                    Bests
                    Owen

                  2. C
                    In reply toJason_Freeman:
                    codebrainzero @codebrainzero
                      2024-08-17 17:28:33.640Z

                      Amazing work here. Been using AA for some time now and didn't think it could get better...

                      1. Thanks @codebrainzero -- here's an alternate (a little slower) approach that adds handles to the material.