No internet connection
  1. Home
  2. How to

Pasting across multiple clips and tracks

By FACUNDO GZ @FACUNDO_GZ
    2023-08-09 17:35:39.321Z

    Hi all, I’m very new to SoundFlow, so I’m still learning the very basics. I was wondering if there’s a script that would paste whatever sound /clip is on the “clipboard” across several tracks, given a specific duration, behind each clip in each track, and across a specific timeline selection. One example would be to copy the same room tone after each lav cut.

    I have created some macros, but I have no idea on how to go about doing this…

    Thanks in advance!

    • 4 replies
    1. F
      FACUNDO GZ @FACUNDO_GZ
        2023-08-10 15:10:06.581Z

        So, I guess that what I'm trying to build is a scritp that would keep pressing TAB within a specific time selection. It would keep tabing if a fade is found, and would only paste if a clip end is reached.
        Any advice on how I would go about doing that?
        Is there any way to investigate this for the non-coders like me?
        Thanks!

        1. In reply toFACUNDO_GZ:
          samuel henriques @samuel_henriques
            2023-08-16 23:46:14.289Z

            Hello Facundo,
            This will paste and fill selection on silence between clips on an initial selection, so far will do one track only.
            Please copy to clipboard the audio you would like to paste, make a selection and run the script.

            function getUserMainCounter() {
            
                // get current counter
                const mainCounter = sf.ui.proTools.getCurrentTimecode().stringValue
            
                let originalTimeCounter
                /// Bars Beats .  
                if (mainCounter.includes("|")) originalTimeCounter = "Bars|Beats"
                //  Min Secs .    
                else if (mainCounter.includes(":") && mainCounter.includes(".")) originalTimeCounter = "Min:Secs"
                //  Time code
                else if (mainCounter.split(":").length == 4) originalTimeCounter = "Timecode"
                //  Feet+Frames
                else if (mainCounter.includes("+")) originalTimeCounter = "Feet+Frames"
                //  Samples.     
                else originalTimeCounter = "Samples"
            
                return originalTimeCounter
            };
            
            
            function isWithinInitialSelection(initialSel, nowSel) {
                return nowSel.selectionStart <= initialSel.selectionEnd && nowSel.selectionEnd <= initialSel.selectionEnd
            };
            
            function dismissFades() {
                const fadesWin = sf.ui.proTools.windows.whoseTitle.is("Batch Fades").first
                if (fadesWin.exists) {
                    fadesWin.buttons.whoseTitle.is("Cancel").first.elementClick()
                };
            };
            
            const isSilence = () => !sf.ui.proTools.getMenuItem("Edit", "Fades").isEnabled
            const walk = () => { sf.keyboard.press({ keys: "tab" }); sf.keyboard.press({ keys: "shift+tab" }); }
            
            
            function pasteOnSilence(selection) {
             
                while (true) {
            
                    walk();
                    // Check if still within selection
                    if (isWithinInitialSelection(selection, sf.ui.proTools.selectionGetInSamples())) {
            
                        // If its Silence, paste
                        if (isSilence()) {
                            sf.ui.proTools.menuClick({ menuPath: ["Edit", "Paste Special", "Repeat to Fill Selection"] });
                            dismissFades();
                            sf.keyboard.press({ keys: "up" });
                        };
                    } else {
                        // If has reached the end of selection, stop
                        break;
                    };
                    sf.wait({ intervalMs: 100 })
                }
            };
            
            
            function main() {
            
                sf.ui.proTools.appActivateMainWindow();
                sf.ui.invalidate();
            
                const initialSelection = sf.ui.proTools.selectionGetInSamples();
                const userMainCounter = getUserMainCounter()
            
                sf.ui.proTools.mainCounterSetValue({ targetValue: "Samples" })
            
                try {
            
                    pasteOnSilence(initialSelection);
            
                } finally {
            
                    sf.ui.proTools.selectionSetInSamples({
                        selectionStart: initialSelection.selectionStart,
                        selectionEnd: initialSelection.selectionEnd
                    });
                    sf.keyboard.press({ keys: "left" });
                    sf.ui.proTools.mainCounterSetValue({ targetValue: userMainCounter })
                };
            };
            
            
            main();
            
            1. FFACUNDO GZ @FACUNDO_GZ
                2023-08-23 18:32:04.288Z

                Hi Samuel!

                Thank you for your reply and your code! I've been testing it but I seem to have some erratic behaviours. It's hard for me to tell exactly why it performs the way it does, but this is what I can comment on:

                • It changes to sample based timeline
                • It sweeps correctly through the time selection within the track
                • It seems to fail to "recognize" audio information if there are crossfaded clips (ie. it replaces audio clips with silence when clips are merged by a crossfade)
                • It sometimes does paste the roomtone that is copied to the clipboard correctly, but sometimes it doesn't. This one is tricky to analyze, I haven't understood why that occurs or why it doesn't, most of the time it does not perform the action.
                • It does not paste the roomtone after the last clip whithn the selection

                If there's anything I can do to help, please let me know.

                1. samuel henriques @samuel_henriques
                    2023-08-23 19:13:03.924Z

                    Tank you for the testing, I'll try to figure it out.