No internet connection
  1. Home
  2. How to
  3. Pro Tools

Consolidate Individual Clips on Multiple Selected Tracks

By Audiosyncrasy @audiosyncrasy
    2024-02-26 15:50:57.517Z

    Hey Everyone, I'm trying to write a script that's supposed to help me condense sessions down for archiving.

    My first step is to strip silence across the whole session which I got working with a script. The second step is where I'm stuck.. I want to be able to highlight across my entire session (of course avoiding anything that isn't an audio track), and hit 1 button on my streamdeck to trigger a script that goes through each track and consolidates however many clips are on that track, then moves on to the next track, and so on and so forth until it's done.

    The problem I'm having is the consolidation command I'm using.. even just to test on 1 track, leaves behind this tiny tiny 44 sample length cut. Its almost as though when it selects the clip, it selects it 44 samples too short on the tail end and consolidates it. So the result is I get a tiny 44 sample little clip at the tail end of every single clip. Now sure how to avoid that, so I got a script that goes through and deletes any clip that's less than a certain duration and I can't get that to work across the multiple selected tracks, it only works on one... but regardless, I wouldn't need that script if the consolidation select the clips 44 samples short. Here is the script I've been using for consolidating all these clips in one swoop.

    If anyone could help, I would really appreciate it cuz it's been driving me crazy.

    Thank you!

    function Consolidate() {
    sf.ui.proTools.clipConsolidate();
    }
    
    function main() {
        sf.ui.proTools.appActivateMainWindow();
        sf.ui.proTools.mainWindow.invalidate();
    
        let selectedTracks = sf.ui.proTools.selectedTrackNames;
    
        selectedTracks.forEach(track => {
            sf.ui.proTools.trackSelectByName({
                names: [track],
                deselectOthers: true,
            });
    
            sf.ui.proTools.selectedTrack.trackScrollToView();
    
            sf.ui.proTools.clipDoForEachSelectedClip({ action: Consolidate });
        });
    }
    
    main();
    
    • 4 replies
    1. samuel henriques @samuel_henriques
        2024-02-26 17:11:01.979Z

        Hello Narek,
        I think the problem you are getting with the clipDoForEachSelectedClip and consolidate is that clipDoForEachSelectedClip will not select the last fade and after the first selection consider the fade as clip and consolidate it. Check if you have 44 sample fades at the end of the clips you are having this problem.
        If you are looking to do this for archiving. Check out pro tools compact function.

        1. AAudiosyncrasy @audiosyncrasy
            2024-02-27 00:53:51.789Z2024-02-27 14:45:31.997Z

            Hey Samuel, you're absolutely correct. I just went back and realized the "strip silence" script I was using had a sneaky "press key f" in there. So yes those fades we're being created. I usually never do that, but I had no idea the script was doing it. I do apologize. Thank you for bringing that to my attention, I would have been scratching my head for days lol.

            Quick question though, is there any way to speed up this consolidation processes by not tabbing to the emptiness between to clips then to the clip? Is there any way to make it jump from clip to clip? Currently, it goes from clip, tabs and selects the empty space, then tabs and selects next clip. For example, when you just hit "CTRL+TAB" on a track, it just jumps from clip to clip. Can we possibly write a script where it takes all the audio tracks I selected, and goes through it top to bottom by using the CTRL+TAB style, then consolidating each one, until there's nothing left on that track, then going down to the next track and repeating that process, until it's at the end of my selected tracks? Essentially it does that now, but also tabs to what's inbetween the clips too so it takes double the time it would take if it didn't.

            Thanks so much!

            1. samuel henriques @samuel_henriques
                2024-03-04 21:08:01.468Z

                hello Audiosyncrasy,
                If you are sure you don't have any fades in any clip. and there aren't any contiguous clips joined by a crossfade. You can try this.
                This is a new method by taking advantage of the pro tools api integration SF is working on with avid. It might still take some time to get this to work with fades and crossfades.
                Let me know what you think. This will consolidate ALL clips on ALL selected tracks. Again, be aware that a fade or a crossfade will be considered one clip.

                function consolidateClips(arr) {
                    for (let i = 0; i < arr.length; i++) {
                
                        sf.app.proTools.setTimelineSelection({
                            inTime: arr[i]['StartTime'].toString(),
                            outTime: arr[i]['EndTime'].toString(),
                
                        });
                
                        sf.app.proTools.consolidateClip();
                        sf.ui.proTools.waitForNoModals();
                    };
                };
                
                
                function main() {
                
                    const selectedTrack = sf.ui.proTools.selectedTrackHeaders
                
                    selectedTrack.forEach(track => {
                
                        sf.app.proTools.selectAllClipsOnTrack({ trackName: track.normalizedTrackName })
                
                        var clips = sf.app.proTools.getSelectedClipInfo().clips
                
                        const uniqueClipSelections = clips.reduce((acc, curr) => {
                            const found = acc.find(item => item['StartTime'] === curr['StartTime'] && item['EndTime'] === curr['EndTime']);
                            if (!found) {
                                acc.push(curr);
                            }
                            return acc;
                        }, []);
                
                
                        consolidateClips(uniqueClipSelections);
                
                    })
                
                    sf.ui.proTools.trackSelectByName({ names: selectedTrack.map(t => t.normalizedTrackName) });
                };
                
                 main();
                
                1. samuel henriques @samuel_henriques
                    2024-03-04 22:10:59.685Z

                    Maybe we don't need to wait a long time, here's a version that will select all clips of every track and make a selection containing crossfaded sections. Thank you chatGPT.

                    PLEASE PLEASE test this, can't garante this is flowless.

                    function consolidateClips(arr) {
                        for (let i = 0; i < arr.length; i++) {
                    
                            sf.app.proTools.setTimelineSelection({
                                inTime: arr[i]['StartTime'].toString(),
                                outTime: arr[i]['EndTime'].toString(),
                    
                            });
                    
                            sf.app.proTools.consolidateClip();
                            sf.ui.proTools.waitForNoModals();
                        };
                    };
                    
                    
                    function consolidateClipsIncludingCrossFades() {
                    
                        //Get original track and timeline selection
                        const selectedTrack = sf.ui.proTools.selectedTrackHeaders
                        const { inTime, outTime } = sf.app.proTools.getTimelineSelection()
                    
                    
                        selectedTrack.forEach(track => {
                    
                            track.trackSelect();
                            track.trackScrollToView();
                    
                            var data = sf.app.proTools.getSelectedClipInfo().clips
                    
                            // Remove duplicates based on StartTime and EndTime
                            const uniqueArray = [];
                            const seenTimes = {};
                    
                            for (let i = 0; i < data.length; i++) {
                                const obj = data[i];
                                const key = `${obj["StartTime"]}-${obj["EndTime"]}`;
                                if (!seenTimes[key]) {
                                    uniqueArray.push(obj);
                                    seenTimes[key] = true;
                                }
                            }
                    
                            // Merge consecutive objects with matching EndTime and StartTime
                            const mergedArray = [];
                            let currentMerge = null;
                    
                            for (let i = 0; i < uniqueArray.length; i++) {
                                const current = uniqueArray[i];
                                const next = uniqueArray[i + 1];
                    
                                if (!currentMerge) {
                                    currentMerge = { ...current };
                                }
                    
                                if (next && current["EndTime"] === next["StartTime"]) {
                                    currentMerge["ClipName"] += ` & ${next["ClipName"]}`;
                                    currentMerge["EndTime"] = next["EndTime"];
                                } else {
                                    mergedArray.push(currentMerge);
                                    currentMerge = null;
                                }
                            }
                    
                            consolidateClips(mergedArray);
                    
                        })
                    
                    
                        //Set original track and timeline selection
                        sf.app.proTools.setTimelineSelection({ inTime, outTime })
                        sf.ui.proTools.trackSelectByName({ names: selectedTrack.map(t => t.normalizedTrackName) });
                    };
                    
                    consolidateClipsIncludingCrossFades();