No internet connection
  1. Home
  2. How to

Move recorded clip to Take tracks on stop.

By Fernando J. Alanis @Fernando_J_Alanis
    2021-06-03 18:05:55.816Z

    Hi all! I want SoundFlow to automatically move the clips I just recorded when the recording stops. I want them to move from the Recording track to the next available spot on the Take Tracks.

    How could I achieve this?

    Thank you!!

    Fernando.

    • 7 replies
    1. samuel henriques @samuel_henriques
        2021-06-03 23:52:52.070Z2021-06-04 00:00:20.956Z

        Hello @Fernando_J_Alanis,

        There is a way to know when you stop recording, but I don't know how to get the clip you just recorded selected, So I wasn't able to script all you asked for.
        If you know a way pro tools selects the clip that was just recorded, let me know.
        also, the way the script knows witch tracks are free uses "clear clip gain" but since you just recorded it, should't be a problem.
        this will take your selected clip to a free track named "Take (any number)",
        let me know how it works for you:

        function getTakeTracks() {
            const takeTracks = sf.ui.proTools.trackGetAllTracks().names.filter(x =>
                x.match(/Take \d+/i))
            return takeTracks
        }
        
        sf.ui.proTools.appActivateMainWindow()
        sf.ui.proTools.invalidate()
        
        const recordingTrack = sf.ui.proTools.selectedTrackNames
        
        sf.ui.proTools.menuClick({ menuPath: ["Edit", "Copy"] });
        
        const takeTracks = getTakeTracks()
        
        sf.ui.proTools.trackSelectByName({ names: takeTracks })
        
        let grabberToolBtn = sf.ui.proTools.mainWindow.cursorToolCluster.grabberTool
        if (grabberToolBtn.title.invalidate().value != "Grabber tool (Object)") {
            grabberToolBtn.popupMenuSelect({ menuPath: ['Object'], isRightClick: true });
        }
        
        // Rest Menu
        sf.keyboard.press({ keys: "left" });
        
        
        // Track has clip
        if (sf.ui.proTools.getMenuItem("Edit", "Clear Special", "Clip Gain").isEnabled) {
        
            sf.ui.proTools.menuClick({ menuPath: ["Edit", "Clear Special", "Clip Gain"] });
        
            let currSelectedTracks = sf.ui.proTools.selectedTrackNames
        
            const cleanTracks = takeTracks.filter(x => !currSelectedTracks.includes(x));
        
            if (cleanTracks.length >= 1) {
                sf.ui.proTools.trackSelectByName({ names: [cleanTracks[0]] })
                sf.ui.proTools.menuClick({ menuPath: ["Edit", "Paste"] });
                sf.ui.proTools.trackSelectByName({ names: recordingTrack })
                sf.ui.proTools.menuClick({ menuPath: ["Edit", "Clear"] });
        
        
            } else {
                alert("All 'Take' tracks are used!")
                sf.ui.proTools.trackSelectByName({ names: recordingTrack })
            }
        } else {
            sf.ui.proTools.trackSelectByName({ names: [takeTracks[0]] })
            sf.ui.proTools.menuClick({ menuPath: ["Edit", "Paste"] });
            sf.ui.proTools.trackSelectByName({ names: recordingTrack })
            sf.ui.proTools.menuClick({ menuPath: ["Edit", "Clear"] });
        }
        
         grabberToolBtn.popupMenuSelect({ menuPath: ['Time'], isRightClick: true });
        
        
        
        1. samuel henriques @samuel_henriques
            2021-06-04 00:22:55.614Z

            Actually, if after you record a clip, that clip is the only on the track, it's possible to to select all and the clip will be selected to move to the Take tracks.
            That way I could write that part of code. Let me know.

            You seam to be trying to do the same as create a playlist for every take you record. Any reason you don't want to use playlists?

            1. Thanks Samuel! It would work with selecting everything in the track. It would be the only thing in that track.

              I prefer this way instead of playlists because of my way of working on ADR sessions. 😂

              1. samuel henriques @samuel_henriques
                  2021-06-04 07:18:06.407Z

                  Cool. I'll try to write the rest. In the mean time, if you could test this part to see if everything works as it should would be great.

                  1. samuel henriques @samuel_henriques
                      2021-06-04 15:02:58.937Z2021-06-04 18:32:14.822Z

                      Hello @Fernando_J_Alanis,

                      Here you go.

                      A few details to consider:

                      This script will be always running in the background as long as you have an open session. When you close the session the script will fail. This is something that can be fixed once everything is working well, but it's actually a good thing. It's not great to let runForever scripts actually run forever. For the sake of stability, it's a good idea to break them when you are not needing them. So, in this case it will break when you close the session, run it again when the session is open. Test it for a while and save often, please. I can't see any reason you could loose anything but you never know.

                      And, during the script we need to have the grabber tool in Object mode.
                      Let me know how you usually keep your tools, so I can leave it that way when the script ends. It might already be good though.

                      Hope you enjoy this, and let me know how it goes.

                      
                      function moveRecordedClipToTakeTrack() {
                          function getTakeTracks() {
                              const takeTracks = sf.ui.proTools.trackGetAllTracks().names.filter(x =>
                                  x.match(/Take \d+/i))
                              return takeTracks
                          }
                      
                          function getGroupListItem(name) {
                              var groupList = sf.ui.proTools.mainWindow.tables.whoseTitle.contains('Group').first;
                              return groupList.childrenByRole("AXRow").allItems.map(function (r) {
                                  return {
                                      row: r,
                                      selectBtn: r.childrenByRole("AXCell").first.children.first,
                                      name: r.childrenByRole("AXCell").allItems[1].children.first.title.value.match(/^.+ - ([^(]+)/)[1].replace(/ $/, ''),
                                  };
                              }).filter(function (r) { return r.name == name })[0];
                          }
                      
                          const recordingTrack = sf.ui.proTools.selectedTrackNames
                          const takeTracks = getTakeTracks()
                      
                      
                          sf.ui.proTools.menuClick({ menuPath: ["Edit", "Select All"] });
                      
                          sf.ui.proTools.menuClick({ menuPath: ["Edit", "Copy"] });
                      
                          // selecting Take Tracks by name
                          //sf.ui.proTools.trackSelectByName({ names: takeTracks })
                      
                          // selecting Take Tracks by track group
                          const groupListItem = getGroupListItem("Take Tracks");
                          groupListItem.selectBtn.elementClick();
                      
                      
                          let grabberToolBtn = sf.ui.proTools.mainWindow.cursorToolCluster.grabberTool
                          if (grabberToolBtn.title.invalidate().value != "Grabber tool (Object)") {
                              grabberToolBtn.popupMenuSelect({ menuPath: ['Object'], isRightClick: true });
                          }
                      
                          // any track has clip
                          if (sf.ui.proTools.getMenuItem("Edit", "Clear Special", "Clip Gain").isEnabled) {
                      
                              sf.ui.proTools.menuClick({ menuPath: ["Edit", "Clear Special", "Clip Gain"] });
                      
                              let currSelectedTracks = sf.ui.proTools.selectedTrackNames
                      
                              const cleanTracks = takeTracks.filter(x => !currSelectedTracks.includes(x));
                      
                              if (cleanTracks.length >= 1) {
                                  sf.ui.proTools.trackSelectByName({ names: [cleanTracks[0]] })
                                  sf.ui.proTools.menuClick({ menuPath: ["Edit", "Paste"] });
                                  sf.ui.proTools.trackSelectByName({ names: recordingTrack })
                                  sf.ui.proTools.menuClick({ menuPath: ["Edit", "Clear"] });
                      
                      
                              } else {
                                  alert("All 'Take' tracks are used!")
                                  sf.ui.proTools.trackSelectByName({ names: recordingTrack })
                              }
                          } else {
                              sf.ui.proTools.trackSelectByName({ names: [takeTracks[0]] })
                              sf.ui.proTools.menuClick({ menuPath: ["Edit", "Paste"] });
                              sf.ui.proTools.trackSelectByName({ names: recordingTrack })
                              sf.ui.proTools.menuClick({ menuPath: ["Edit", "Clear"] });
                          }
                      
                          grabberToolBtn.popupMenuSelect({ menuPath: ['Time'], isRightClick: true });
                      
                      }
                      
                      
                      
                      
                      function runForever(name, interval, timeout) {
                          var now = (new Date).valueOf();
                          if (now - globalState[name] < timeout) throw 0; //Exit if we were invoked again inside the timeout
                      
                          globalState[name] = now;
                          sf.engine.runInBackground(function () {
                              try {
                      
                                  const recordBtn = sf.ui.proTools.mainWindow.groups.allItems[5].groups.first.buttons.whoseTitle.is("Record Enable").first
                                  const playBtn = sf.ui.proTools.mainWindow.groups.allItems[5].groups.first.buttons.whoseTitle.is("Play").first
                                  let wasRecording
                      
                                  while (true) {
                                      sf.engine.checkForCancellation();
                      
                                      if (recordBtn.value.invalidate().value.endsWith("Is Recording")) { wasRecording = true }
                      
                                      if (wasRecording &&
                                          !playBtn.value.invalidate().value.includes("selected")) {
                                          wasRecording = false
                      
                                          moveRecordedClipToTakeTrack()
                                      }
                      
                                      sf.wait({ intervalMs: interval, executionMode: 'Background' });
                      
                                  }
                              } finally {
                                  globalState[name] = null;
                              }
                          });
                      }
                      
                      
                      sf.ui.proTools.appActivateMainWindow()
                      sf.ui.proTools.invalidate()
                      
                      runForever("moveClipToTakeTracks", 500, 5000);
                      
                      
                      1. samuel henriques @samuel_henriques
                          2021-06-04 18:36:16.466Z

                          UPDATE:
                          made it faster by selecting the 'Take' tracks by clicking the track group. But for this to work you need to create a track group named "Take Tracks".
                          You can change the group name here:

                          const groupListItem = getGroupListItem("Take Tracks");
                          

                          If you prefer not to have a group just replace this:

                              // selecting Take Tracks by name
                              //sf.ui.proTools.trackSelectByName({ names: takeTracks })
                          
                              // selecting Take Tracks by track group
                              const groupListItem = getGroupListItem("Take Tracks");
                              groupListItem.selectBtn.elementClick();
                          

                          with:

                              // selecting Take Tracks by name
                              sf.ui.proTools.trackSelectByName({ names: takeTracks })
                          
                              // selecting Take Tracks by track group
                              //const groupListItem = getGroupListItem("Take Tracks");
                              //groupListItem.selectBtn.elementClick();
                          

                          And the tracks will be selected by name instead.

                          1. Thanks a lot Samuel!! I’ll run some tests during the weekend and I’ll let you know how it works! 🙌🏻🙌🏻