No internet connection
  1. Home
  2. How to

Copy Track Volume to Trim Plugin

By Ben Singleton @Ben_Singleton
    2021-10-10 12:33:01.148Z

    I'm trying to create a macro where by I can copy the volume information of a track in pro tools and paste it into a trim plugin so I can zero the fader. Ultimately I would like to do this to all selected tracks.
    This works manually, but strangely not all the time. Using actions such as click ui element I have had no luck.
    My question is as to whether this is possible and what would be the best way to start with such a project?

    Thanks
    Ben

    Solved in post #4, click to view
    • 6 replies
    1. B
      Ben Singleton @Ben_Singleton
        2021-10-11 10:22:20.423Z2021-10-11 20:18:36.528Z

        Ok so I've been plodding on with this, the first part of this works as I can use a log command to show the track output value. I currently don't know how to write it to work with a selected track instead of a specific track.
        The second part however wont open the trim plugin and select the gain text box (It will select the box if the trim plugin is already open though).
        Getting the script to enter the track output value into the text box isn't there yet.

        sf.ui.proTools.mainWindow.groups.whoseTitle.is("Audio 12 - Audio Track ").first.groups.whoseTitle.is("Audio IO").first.buttons.whoseTitle.is("Output Window button").first.elementClick();
        
        sf.ui.proTools.mainTrackOutputWindow.elementWaitFor();
        
        var mixLevel = sf.ui.proTools.mainTrackOutputWindow.textFields.first.value.invalidate().value;
        
        sf.wait();
        
        sf.proTools.appActivateMainWindow();
        
        sf.ui.proTools.selectedTrack.trackInsertToggleShow({
            insertNumber: 1,
            targetValue: "Enable",
            onCancel: "continue",
            onError: "continue",
        });
        
        sf.ui.proTools.windows.whoseTitle.is("Plug-in: Trim").first.elementWaitFor();
        
        sf.ui.proTools.windows.whoseTitle.is("Plug-in: Trim").first.mouseClickElement({
            relativePosition: {"x":406,"y":162}, 
        }); 
        
        sf.ui.proTools.selectionSet({
            selectionLength: mixLevel
        });
        
        1. B
          In reply toBen_Singleton:
          Ben Singleton @Ben_Singleton
            2021-10-11 12:53:04.605Z2021-10-11 20:18:59.374Z

            Got it working a bit better, still no idea how to set it as selected track, but insert is opening and gain text box is also selected.
            I managed to get soundflow to type a random number into the trim plugin using keypress, but that has since stopped working. But I still can't work out how to get the output level into this text box;

            sf.ui.proTools.mainWindow.groups.whoseTitle.is("Audio 12 - Audio Track ").first.groups.whoseTitle.is("Audio IO").first.buttons.whoseTitle.is("Output Window button").first.elementClick();
            
            sf.ui.proTools.mainTrackOutputWindow.elementWaitFor();
            
            var mixLevel = sf.ui.proTools.mainTrackOutputWindow.textFields.first.value.invalidate().value;
            
            sf.wait({
                intervalMs: 100,
            });
            
            sf.ui.proTools.selectedTrack.trackInsertToggleShow({
                insertNumber: 1,
                targetValue: "Enable",
            });
            
            sf.ui.proTools.windows.whoseTitle.is("Plug-in: Trim").first.elementWaitFor();
            
            sf.ui.proTools.windows.whoseTitle.is("Plug-in: Trim").first.mouseClickElement({
                relativePosition: {"x":406,"y":162},
            });
            
            1. samuel henriques @samuel_henriques
                2021-10-11 18:34:13.919Z2021-10-11 19:05:55.936Z

                Hello Ben_Singleton,

                Good start, I had come across the problem of making sure the output widow belongs to the selected track so had part of this done.
                As it stands it will expect trim to be on slot 1.

                Here you go, let me know if this is it:

                
                /**
                 * @param {'send a'|'send b'|'send c'|'send d'|'send e'|'send f'|'send g'|'send h'|'send i'|'send j'|'main out'} outputViewSelector
                 */
                function openOutputWindow(outputViewSelector) {
                
                    const outputViewSelectorBtn = sf.ui.proTools.mainTrackOutputWindow.buttons.whoseTitle.is("Output View selector").first
                    const selectedTrackName = sf.ui.proTools.selectedTrackNames[0]
                    const rackOutWinTrackName = sf.ui.proTools.mainTrackOutputWindow.buttons.first;
                
                    if (!outputViewSelectorBtn.exists) {
                        sf.ui.proTools.selectedTrack.trackOutputToggleShow()
                        sf.ui.proTools.invalidate()
                    }
                
                    if (selectedTrackName != rackOutWinTrackName.value.invalidate().value ||
                        !outputViewSelectorBtn.value.invalidate().value.startsWith(outputViewSelector)) {
                
                        sf.ui.proTools.selectedTrack.trackOutputToggleShow()
                        openOutputWindow(outputViewSelector)
                    }
                
                
                    return sf.ui.proTools.mainTrackOutputWindow.textFields.whoseTitle.is("Volume Numerical").first.value.invalidate().value
                
                }
                
                
                /**
                * @param {string} newVolume
                */
                function setVolumeOnTrim(newVolume) {
                
                    const trimWin = sf.ui.proTools.windows.whoseTitle.is("Plug-in: Trim").first
                
                    if (trimWin.exists) {
                
                        //  Set +12 dB
                        trimWin.mouseClickElement({ relativePosition: { "x": 254, "y": 90 } });
                
                        // Click on volume
                        trimWin.mouseClickElement({ relativePosition: { "x": 415, "y": 159 } });
                
                        // Type volume
                        sf.keyboard.type({ text: newVolume })
                
                        // Enter
                        sf.keyboard.press({ keys: "return" })
                    };
                };
                
                function main() {
                    //Get selected tracks
                    const originalTracks = sf.ui.proTools.selectedTrackNames;
                
                    //Do for each track.
                    sf.ui.proTools.selectedTracks.trackHeaders.slice().map(track => {
                
                        //Select track
                        track.trackSelect();
                
                        //Scroll track into View
                        track.trackScrollToView();
                
                        try {
                            sf.ui.proTools.selectedTrack.trackInsertToggleShow({
                                insertNumber: 1,
                                targetValue: "Enable"
                            })
                        } catch (err) { }
                
                
                        const newVolume = openOutputWindow("main out")
                
                        setVolumeOnTrim(newVolume)
                
                    });
                
                    //Restore previously selected tracks
                    sf.ui.proTools.trackSelectByName({ names: originalTracks });
                }
                
                main()
                
                Reply1 LikeSolution
                1. samuel henriques @samuel_henriques
                    2021-10-11 19:06:28.308Z

                    Just updated above. Improved speed.

                2. B
                  In reply toBen_Singleton:
                  Ben Singleton @Ben_Singleton
                    2021-10-11 20:05:30.448Z

                    Hi,
                    Thank you so much!!! It works like an absolute dream!!
                    I'll have to study what you have done to try and understand how it all fits together, but this is such a great help.
                    Thanks again.
                    Ben

                    1. samuel henriques @samuel_henriques
                        2021-10-11 20:14:18.753Z

                        Awesome, happy to help.