No internet connection
  1. Home
  2. How to

How to loop as many times as markers are in the PT session?

Hi all,

I have tried to develop a loop that repeats an action as many times as markers are in my session (without any previous selection) but I couldn't get a script working properly.

I have tried:

//Get the markers
var markers = sf.ui.protools.selectionGetInfo().markers;

//Loop for each marker
for (var i = 0; i < markers.length; i++) {

Because my idea was "take the total number of markers and then repeat that number" using the basic loop structure.

Any ideas folks?

Cheers

Solved in post #2, click to view
  • 8 replies
  1. Try this:

    //Fetch memory locations
    const markers = sf.proTools.memoryLocationsFetch().collection["List"];
    
    //Loop for each marker
    for (var i = 0; i < markers.length; i++) {
    
        // Do stuff here
        
    }
    
    
    Reply1 LikeSolution
    1. AAna del Sol Perez Zamora @Ana_del_Sol_Perez_Za
        2023-04-27 11:21:06.570Z2023-04-27 16:55:20.266Z

        Hi Chris,

        It's absolutely working.
        The first step you did is so intelligent, and I was definitely stuck on it!

        I was getting the following pop up window when there are no more markers which is fine but prevents me from linking my next actions. So included the following command that skips the loop if there's no next marker available

           //Check if there are more markers
           if (i == markers.length - 1) {
               break; //exit the loop
           }
        

        Thanks again! It's so helpful!

        1. In reply toChris_Shaw:
          Mike Wax @mikewax
            2023-09-23 22:04:43.687Z

            Hey @Chris_Shaw,

            Thank you for sharing this code. I'm trying to use this code but filter it to get the .length of only Track Markers.

            When i log the "List", it gives me an object and then another array. Inside that object is "MarkerTrack", that's the info i'm trying to get/count.

            I tried to add a .filter() but wasn't able to access it.
            Thanks for the help!

            [
                {
                    "Number": 4,
                    "Name": "Track Marker 2",
                    "MarkerTrack": "Selected. BOOM",
                    "MainCounterValue": "00:00:16:10"
                },
                {
                    "Number": 3,
                    "Name": "Track Marker 1",
                    "MarkerTrack": "BOOM",
                    "MainCounterValue": "00:00:11:22"
                },
                {
                    "Number": 8,
                    "Name": "Track Marker",
                    "MarkerTrack": "BOOM",
                    "MainCounterValue": "00:00:09:08"
                },
                {
                    "Number": 2,
                    "Name": "Track Marker",
                    "MarkerTrack": "BOOM",
                    "MainCounterValue": "00:00:07:03"
                },
                {
                    "Number": 1,
                    "Name": "Track Marker",
                    "MarkerTrack": "BOOM",
                    "MainCounterValue": "00:00:01:14"
                },
                {
                    "Number": 6,
                    "Name": "Main Marker 2",
                    "MarkerTrack": "Marker Ruler",
                    "MainCounterValue": "00:00:12:12"
                },
                {
                    "Number": 5,
                    "Name": "Main Marker 1",
                    "MarkerTrack": "Marker Ruler",
                    "MainCounterValue": "00:00:04:23"
                },
                {
                    "Number": 7,
                    "Name": "Main Marker 2",
                    "MarkerTrack": "Marker Ruler",
                    "MainCounterValue": "00:00:00:00"
                }
            ]
            
            1. Chris Shaw @Chris_Shaw2023-09-23 22:30:24.072Z2023-09-24 00:33:36.433Z

              @mikewax
              This will return all track markers

              //Fetch memory locations
              const markers = sf.proTools.memoryLocationsFetch().collection["List"];
              
              //Filter track markers
              const trackMarkers = markers.filter(m => m.markerTrack !=="Marker Ruler");
              
              log (trackMarkers)
              

              This will return the track markers on the selected track:

              //Fetch memory locations
              const markers = sf.proTools.memoryLocationsFetch().collection["List"];
              
              //Filter track markers on selected track
              const trackName = sf.ui.proTools.selectedTrackNames[0]
              const trackMarkers = markers.filter(m => m.markerTrack.replace(/Selected\. /g, '') == trackName);
              
              log (trackMarkers)
              

              This will return track markers on all selected tracks (probably the most flexible option)

              //Fetch memory locations
              const markers = sf.proTools.memoryLocationsFetch().collection["List"];
              
              //Filter track markers on selected track
              const trackNames = sf.ui.proTools.selectedTrackNames
              const trackMarkers = markers.filter(m => trackNames.includes(m.markerTrack.replace(/Selected\. /g, '')));
              
              log(trackMarkers)
              
              1. memoryLocationsFetch() returns an array and each element in the array is an object.
                So, in order to find a memory location that matches a particular property/key, you filter each object by the key and value you're looking for.
                Ex.
                if you wanted to find a marker with a particular counter value you 'd do this:
                const trackMarkers = markers.filter(m => m. mainCounterValue == "00:00:04:23");
                which would return memory location #5 in the array of objects you posted above

                1. In reply toChris_Shaw:

                  to get the length of track markers on any of these scripts you would just do

                  log (trackMarkers.length)
                  
                  1. In reply toChris_Shaw:

                    the .replace(/Selected\. /g, '') will replace any instance of "Selected. " with an empty string. Otherwise the selected marker (like marker #4 in your object above) would not be filtered properly

                    1. Mike Wax @mikewax
                        2023-09-24 01:37:32.528Z

                        Wow @Chris_Shaw!! This is perfect!

                        I knew there was something with .filter() but couldn't get the syntax correct.
                        As always, thank you so much for the help!!