No internet connection
  1. Home
  2. How to

Script that determines the nearest Pro Tools Marker to the parked cursor & copy/pastes the name of the marker to the enabled record track.

By Dane Butler @Dane_Butler
    2022-11-28 19:50:46.797Z

    @samuel_henriques

    I'm looking for a somewhat technical script this time. I do a lot of ADR, and I'm looking for something to give me a bit of a speed boost.

    I wanted to see if it would be possible to help me write a script that:

    A) determines the nearest marker location based on the timecode position of the parked cursor
    B) Selects and opens that marker and copies its text (ie Cassandra001, or pablo003).
    C) Pastes the text to the track name of the (only) record enabled track.

    Do you think that this is possible for Soundflow?

    • 12 replies
    1. D
      Dane Butler @Dane_Butler
        2022-11-28 19:54:39.287Z
        1. samuel henriques @samuel_henriques
            2022-12-09 14:12:54.276Z2022-12-09 22:01:56.890Z

            Hello Dane,
            Sorry I took so long,
            try this,

            function timeCounter() {
            
                // 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 getNextMarkerName(selection) {
                let nextMemLoc
                sf.ui.proTools.memoryLocationsEnsureWindow({
                    restoreWindowOpenState: true,
                    action: () => {
            
                        nextMemLoc = sf.proTools.memoryLocationsFetch().collection['List'].slice().find(m =>
                            m.mainCounterValue >= selection.selectionStart
                        );
                    }
                });
                return nextMemLoc ? nextMemLoc["name"] : undefined
            };
            
            
            function getRecordEnabledTracks() {
            
                const visibleTracks = sf.ui.proTools.visibleTrackHeaders
            
                const recTrack = visibleTracks.find(tr => {
                    const recButton = tr.buttons.whoseTitle.is("Track Record Enable").first
                    return recButton.exists && recButton.value.invalidate().value.includes("on state")
                });
                return recTrack
            }
            
            function getSessionInfo() {
                try {
            
                    // Get user info
                    this.originalTimeCounter = timeCounter();
                    this.originalSelectedTracks = sf.ui.proTools.selectedTrackHeaders;
            
                    // Get info
                    this.recordEnabledTrack = getRecordEnabledTracks();
                    //Set samples, setting here will prevent from changing more than once.
                    sf.ui.proTools.mainCounterSetValue({ targetValue: "Samples" });
                    this.currentSelection = sf.ui.proTools.selectionGetInSamples();
                    this.nextMarkerName = getNextMarkerName(this.currentSelection);
            
                    //Functions and set user original
                    this.renameRecTrack = () => {
                        this.recordEnabledTrack.trackSelect();
                        this.recordEnabledTrack.trackScrollToView();
                        this.recordEnabledTrack.trackBulkRename({ newName: this.nextMarkerName });
                        sf.ui.proTools.invalidate();
                    };
            
            
                    this.setUserOriginals = () => {
                        const originalSelected = this.originalSelectedTracks;
            
                        if (originalSelected.length > 0) {
            
                            // Selected Track
                            originalSelected[0].trackSelect();
                            originalSelected[0].trackScrollToView();
                            sf.ui.proTools.trackSelectByName({ names: originalSelected.map(th => th.normalizedTrackName) });
                        };
                        //user counter
                        sf.ui.proTools.mainCounterSetValue({ targetValue: this.originalTimeCounter });
            
                    };
            
                } catch (err) {
                    throw err
                };
            };
            
            function main() {
            
                sf.ui.proTools.appActivateMainWindow();
                sf.ui.proTools.invalidate();
            
                const session = new getSessionInfo();
                try {
                    if (!session.recordEnabledTrack) { alert("No record track found."); throw 0 };
                    if (!session.nextMarkerName) { alert("No More Memory Locations."); throw 0 };
            
                    session.renameRecTrack();
                } catch (err) {
                    throw err
            
                } finally {
            
                    session.setUserOriginals();
                };
            
            };
            
            main();
            
            1. DDane Butler @Dane_Butler
                2022-12-09 15:38:11.561Z

                Hey!!!!

                Thanks so much for getting back to me! I’ll give this a go here in a few minutes!! 😬😬😬😬

                1. DDane Butler @Dane_Butler
                    2022-12-09 16:27:14.487Z

                    Hey!

                    So first of all great work! This will help me so much. It does work, but it also throws this error code...

                    09.12.2022 10:24:08.97 [Backend]: !! Command Error: Get Timecode to Record [user:cl5r700c40003c710l3rhtp28:clbgpq2mc000eue10f0gxcle1]:
                    Selected track header and track list item does not match. List Name: ''. Header Name: 'Dad002' (Get Timecode to Record: Line 80)

                    I notice I have to park the cursor before the marker in order to pull the timecode marker name, but that's easy enough to work with! Thank you so much.

                    1. samuel henriques @samuel_henriques
                        2022-12-09 16:33:36.364Z

                        I thought I had fixed this error, I'll check again in a bit. I think it only happens if you don't have any track selected before running the script.

                        I notice I have to park the cursor before the marker in order to pull the timecode marker name, but that's easy enough to work with! Thank you so much.

                        This is what I understood from you request "A) determines the nearest marker location based on the timecode position of the parked cursor"

                        Do you want nearest before or after? Or something else?

                        1. DDane Butler @Dane_Butler
                            2022-12-09 17:26:21.372Z

                            Yeah I had a track selected! I always have the "link edit & track selection" button lit up. I think what you did was better than what I was thinking initially. Initially had the idea of the script making said determination based off of proximity with both before and after being taken into consideration, but just before is better because I think it will lead to more predictable performance so no need to change anything there! Just curious about the error code but like I said that's no big deal because it still works. Just a lot of pop up notifications

                            1. samuel henriques @samuel_henriques
                                2022-12-09 17:37:56.276Z

                                ok cool.
                                That error is stupid, I'll figure out what I did wrong. Probably has to do with the method I used to create the functions, it's something new to me that I was playing with.

                                1. samuel henriques @samuel_henriques
                                    2022-12-09 18:27:43.641Z2022-12-09 18:34:53.584Z

                                    Having trouble reproducing the error.
                                    Updated a new version and tweaked some bits, if you still see the erros make a video capture of the script failing so I can see if i missed something.

                                    1. samuel henriques @samuel_henriques
                                        2022-12-09 18:35:55.781Z

                                        New Update just now.

                                        1. samuel henriques @samuel_henriques
                                            2022-12-09 22:02:15.069Z

                                            Just Updated, slightly faster version.

                                            1. DDane Butler @Dane_Butler
                                                2022-12-10 01:18:00.815Z

                                                Copy that! I’ll give it a go & take a screenshot tomorrow!

                                                1. DDane Butler @Dane_Butler
                                                    2022-12-12 02:20:13.063Z

                                                    You're the man Sam! This works flawlessly.