No internet connection
  1. Home
  2. Script Sharing

Insert plugin on first free insert of all selected tracks

By Sreejesh Nair @Sreejesh_Nair
    2024-01-18 18:34:04.213Z

    The following script will insert the EQ plugin on the first free slot of all the selected tracks. The difference here in making it faster is that it will first find out all the first free slots on all the selected tracks, and then select the tracks according to the grouped free slots and insert it in one go. This way it doesnt have to insert on each track one at a time and is much faster.

    sf.ui.proTools.appActivateMainWindow();
    
    var pluginPath = ["multi-mono plug-in", "EQ", "EQ3 7-Band (mono)"];
    
    // Function to find the first free insert slot of a track
    function findFirstFreeInsert(track) {
        return track.insertButtons.findIndex(btn => btn.invalidate().value.value === 'unassigned') + 1;
    }
    
    // Function to select a track by name
    function selectTrackByName(trackName) {
        sf.ui.proTools.trackGetByName({ name: trackName }).track.trackScrollToView();
        sf.ui.proTools.trackSelectByName({ names: [trackName] });
    }
    
    // Function to insert a plugin into the selected tracks
    function insertPlugin(insertNumber) {
        sf.ui.proTools.selectedTrack.trackInsertOrSendSelect({
            pluginNumber: insertNumber,
            pluginPath: pluginPath,
            selectForAllSelectedTracks: true,
        });
    }
    
    // Get the names of all selected tracks and group them by their first free insert slot
    const selectedTrackNames = sf.ui.proTools.selectedTrackNames;
    const tracksGroupedByInsert = selectedTrackNames.reduce((acc, trackName) => {
        selectTrackByName(trackName);
        const freeInsertIndex = findFirstFreeInsert(sf.ui.proTools.selectedTrack);
        if (freeInsertIndex > 0) {
            acc[freeInsertIndex] = acc[freeInsertIndex] || [];
            acc[freeInsertIndex].push(trackName);
        }
        return acc;
    }, {});
    
    // Iterate over each group and insert the plugin
    Object.entries(tracksGroupedByInsert).forEach(([insertNumber, trackNamesInGroup]) => {
        sf.ui.proTools.trackSelectByName({ names: trackNamesInGroup });
        insertPlugin(parseInt(insertNumber));
    });
    
    • 1 replies
    1. R
      Rojé KaPōn @Roje_KaPon
        2024-01-21 22:06:07.140Z

        Thanks @Sreejesh_Nair much appreciated. I was able to change the
        ( var pluginPath = )
        and direct it to my plugin of choice.
        var pluginPath = ["plug-in", "EQ", "Virtual Mix Rack (mono)"];
        2nd day.....1st script
        I will be using this one on my mix bus; You're the MVP
        Thanks a million.