No internet connection
  1. Home
  2. How to

Render all selected clips (with fade ins and fade outs)

By Jack Byrne @Jack_Byrne
    2022-09-26 16:47:03.196Z

    Hey all!

    Trying to convert a KM macro that I've got for rendering drum samples, all of which have fade ins and outs. The script currently asks me how many times to repeat the action, but I'd love if it was possible to just select all the clips and have it do them without me having to do any counting!

    The current macro (I'll post a shot from KM) does it with keystrokes, but I'm sure there'll be a smarter way to script it that I don't know with SF. I've tested the sf.ui.proTools.clipDoForEachSelectedClip(); code to in isolation to see what happens, but it seems to cycle through the fades as well, rather than the clip including the fade Is there a neat way around this?

    • 5 replies
    1. J
      Jack Byrne @Jack_Byrne
        2022-09-26 17:00:58.547Z

        I've also just noticed that it doesn't work with multiple tracks at the same time, which I would need. Can Soundflow get the number of selected clips? There's probably a workaround if I do that instead

        1. samuel henriques @samuel_henriques
            2022-09-27 08:59:33.396Z2022-09-28 18:05:41.265Z

            Hello Jack,
            Try this:

            
            function getOriginalToolSelection() {
                // Get original Tools Selection
                const originalToolSelection = sf.ui.proTools.mainWindow.cursorToolCluster.buttons.filter(btn =>
                    btn.title.value == "Smart tool" ||
                    btn.title.value == "Trim tool" ||
                    btn.title.value == "Selector tool" ||
                    btn.title.value.startsWith("Grabber tool")
                ).filter(btn => btn.value.invalidate().value === "Selected")
                return originalToolSelection
            };
            
            
            function setOriginalToolSelection(originalToolSelection) {
                ///Set Original Tools Selection
                originalToolSelection.map(selBtn => selBtn.title.value).indexOf("Smart Tool") > 0 ?
                    originalToolSelection.filter(selBtn => selBtn.title.value === "Smart Tool")[0].elementClick() :
                    originalToolSelection[0].elementClick()
            };
            
            
            function setGrabberTool() {
                const grabberToolToolBtn = sf.ui.proTools.mainWindow.groups.allItems[2].buttons.whoseTitle.startsWith('Grabber tool').first
            
                grabberToolToolBtn.elementClick();
                grabberToolToolBtn.popupMenuSelect({
                    isRightClick: true,
                    menuPath: ['Object']
                });
            };
            
            
            
            
            
            function main() {
                sf.ui.proTools.appActivateMainWindow();
                sf.ui.proTools.invalidate();
            
            
                const selectedTracksH = sf.ui.proTools.selectedTrackHeaders;
                const originalToolSelection = getOriginalToolSelection()
                const getOriginalSelectionEnd = sf.ui.proTools.selectionGetInSamples().selectionEnd
            
                // Select grabber tool
                setGrabberTool();
            
                // Dor for each selected track
                selectedTracksH.map(track => {
            
                    // Track select & scroll to view
                    track.trackSelect();
                    track.trackScrollToView();
            
            
                    // Do for each selected clip
                    sf.ui.proTools.clipDoForEachSelectedClip({
                        action: () => {
            
            
                            // Using grabber will select the complete clip including fades, 
                            //group + undo will get the currect timeline selection
                            sf.ui.proTools.menuClick({ menuPath: ["Clip", "Group"] })
                            sf.ui.proTools.menuClick({ menuPath: ["Edit", "Undo Group Clips"] });
            
                            // Using grabber will select the next clip after initial selection, 
                            // checking its start to prevent selection
                            const getCurrentSelectionStart = sf.ui.proTools.selectionGetInSamples().selectionStart;
                            if (getCurrentSelectionStart > getOriginalSelectionEnd) return;
            
                            // Clip consolidate
                            sf.ui.proTools.clipConsolidate();
                        },
                    });
                });
            
            
                // Set original Tool Selection and Track Selection
                setOriginalToolSelection(originalToolSelection);
                sf.ui.proTools.trackSelectByName({ names: selectedTracksH.map(n => n.normalizedTrackName) });
            };
            
            
            main();
            
          • J
            In reply toJack_Byrne:
            Jack Byrne @Jack_Byrne
              2022-09-27 12:03:09.352Z

              That seems to work on a quick test, thanks! It's slower than being able to do it to multiple tracks at the same time, but it also seems to be completely hands off and doesn't require any counting on my part, so at least it means I can just step away and get something else done

              1. samuel henriques @samuel_henriques
                  2022-09-27 13:05:28.819Z

                  Good to hear its working so far. Keep testing and let me know how it goes.

                  1. JJack Byrne @Jack_Byrne
                      2022-11-01 16:26:17.361Z

                      Hey!

                      So, discovered an issue, if I'm working with two sets of samples across multiple tracks, it just loops at the end of the first track samples, and it's still dramatically slower than the old method. BUT, I've stumbled across something that I think is an improvement.

                      @raphaelsepulveda posted this here a while ago Is there a way to tell how many clips exist in a pro tools selection? #post-6

                      let selectedClips = sf.ui.proTools.mainWindow.tables.whoseTitle.is('CLIPS').first.children.whoseRole.is("AXRow").allItems.map(row => 
                          row.children[1].children.first.value.value).filter(c => c.startsWith('Selected. '));
                      
                      log(selectedClips.length);
                      

                      Which I've tested, and will give a count of the selected number of clips, even if they've got fades (which was a worry). So, all I would need to do is get that value for one track worth of the multi-mic sample, then use that to know how many times to repeat the OG keyboard maestro loop.

                      The next step after this is going to potentially be some real fun automation around running that loop, then exporting to the right folder and pulling those into Name Mangler to run my reverse sequencing loop so that they'll drop into Trigger Instrument Editor in the right order, but I've got some research to do before I can figure that out because I'm a code moron