No internet connection
  1. Home
  2. How to

Show Only Tracks with Active Clips in Current Selection

By Cooper Babbes @cooper
    2022-02-25 22:21:07.952Z

    There is a built-in Soundflow command called "Show Only Tracks with Active Clips in Current Selection." It takes a few minutes to fully run on extremely large sessions, so I'm trying to make my own.

    Here's the series of actions I'm trying to achieve:

    1. Make sure "Link Track and Edit Selection" is on.
    2. Select all tracks (to extend current edit selection vertically to include all tracks)
    3. Object Select all clips in the current edit selection range (right-click on one of the selected clips in the Clips List, select "Object Select in Edit Window")
    4. From the Tracks List arrow drop-down menu, select "Show Only Selected Tracks"

    Would anyone be able to help me script this?

    I think this would work for the Select All Tracks step:

    function selectAllTracks() {
        sf.ui.proTools.mainWindow.groupListView
            .children.whoseRole.is("AXColumn").first
            .children.whoseRole.is("AXRow").first
            .children.whoseRole.is("AXCell").first
            .buttons.first.elementClick();
    }
    
    selectAllTracks();
    
    • 14 replies

    There are 14 replies. Estimated reading time: 13 minutes

    1. Kitch Membery @Kitch2022-03-06 04:12:11.053Z

      Great Idea... And yeah that's most probably going to be much faster. :-)

      Try this :-)

      function selectAllVisibleTracks() {
          sf.ui.proTools.trackDeselectAll();
      
          const topOfEditWindow = sf.ui.proTools.mainWindow.timelineFocusButton.frame.y;
      
          const topTrack = sf.ui.proTools.visibleTrackHeaders.filter(h => h.frame.y >= topOfEditWindow)[0];
      
      
          topTrack.titleButton.mouseClickElement({ isOption: true });
      }
      
      function main() {
          sf.ui.proTools.mainWindow.invalidate();
          sf.ui.proTools.appActivateMainWindow();
      
          const cursorToolCluster = sf.ui.proTools.mainWindow.cursorToolCluster;
          cursorToolCluster.buttons.whoseTitle.startsWith('Grabber tool').first.popupMenuSelect({
              isRightClick: true,
              menuPath: ['Object']
          });
      
          sf.ui.proTools.menuClick({
              menuPath: ["Options", "Link Track and Edit Selection"],
              targetValue: "Enable",
          });
      
          selectAllVisibleTracks();
      
          sf.ui.proTools.menuClick({
              menuPath: ["Edit", "Select All"],
          });
      
          sf.ui.proTools.mainWindow.trackListPopupButton.popupMenuSelect({
              menuPath: ["Show Only Selected Tracks"],
          });
      }
      
      main();
      

      Rock on!

      1. CCooper Babbes @cooper
          2022-03-31 21:40:20.009Z

          Thanks so much for giving this a shot! This unfortunately isn't working on my end. It ends up extending the edit selection horizontally to include all content across the timeline. Any idea what might be causing this?

          1. Kitch Membery @Kitch2022-03-31 21:52:57.509Z

            Ahh, I think I misread your question.

            I'll take a look later today and see if I can make it do what you are after. :-)

            1. In reply tocooper:
              Kitch Membery @Kitch2022-04-01 18:53:41.694Z

              Hi @cooper,

              On further investigation, the implementation you are describing would need a hacky workaround to make the script work.

              This is due to the following step from your post...
              right-click on one of the selected clips in the Clips List, select "Object Select in Edit Window"
              ...that would require scrolling to the first visible selected clip in the clips list (I'm yet to find a "stable" way to do this). When I have some free time I'll take another look and see if I can find a solution.

              Rock on

              1. CCooper Babbes @cooper
                  2022-04-01 18:58:13.406Z

                  Yeah, I was especially curious how that step was supposed to be executed. The clips list does automatically scroll to the most recent clip selected in the timeline, so maybe there's a way to get that step to work under the assumption that there is at least one visible selected clip in the Clips List? With the understanding that it won't work if there are no selected clips visible in the list?

                  Thanks!!

                  1. Kitch Membery @Kitch2022-04-01 21:10:15.142Z

                    Ohh I'd not noticed that. If that's the case I may be able to get it to work :-)
                    Thanks for pointing that out.

                    1. In reply tocooper:
                      Kitch Membery @Kitch2022-04-01 21:15:00.630Z

                      Hi @cooper

                      If that's the case... This should do the trick :-)

                      function objectSelectInEditWindow() {
                          sf.ui.proTools.appActivateMainWindow();
                      
                          let clipListView = sf.ui.proTools.mainWindow.clipListView;
                          let rows = clipListView.childrenByRole("AXRow");
                          let selectedRows = rows.filter(row => row.children.allItems[1].children.first.title.invalidate().value.startsWith("Selected. "));
                          let firstSelectedRow = selectedRows[0];
                      
                          firstSelectedRow.children.whoseRole.is("AXCell").allItems[1].popupMenuSelect({
                              isRightClick: true,
                              menuPath: ["Object Select in Edit Window"]
                          });
                      }
                      
                      function main() {
                          sf.ui.proTools.mainWindow.invalidate();
                          sf.ui.proTools.appActivateMainWindow();
                      
                          sf.ui.proTools.menuClick({
                              menuPath: ["Options", "Link Track and Edit Selection"],
                              targetValue: "Enable",
                          });
                      
                          objectSelectInEditWindow();
                      
                          sf.ui.proTools.mainWindow.trackListPopupButton.popupMenuSelect({
                              menuPath: ["Show Only Selected Tracks"],
                          });
                      }
                      
                      main();
                      

                      Fun!!! :-)
                      Rock on!

                      1. CCooper Babbes @cooper
                          2022-04-27 05:32:27.953Z

                          sorry for my late reply. this is awesome, thank you a ton!

                          Although, I can't seem to figure why, but it only sometimes successfully right-clicks on one of the selected clips (for the Object Select in Edit window step). Half the time it selects a seemingly random clip from the list. I can't seem to figure out what causes the issue or get consistent behavior.

                          Also, there's one step missing that I'd like to integrate: right-click the <ALL> group and select "Select Tracks in Group". That way any tracks in the whole session who have clips encompassed within the selected time range will be included, and you don't have to select them all manually. Is that possible to script?

                          Thanks again!

                          1. In reply toKitch:
                            CCooper Babbes @cooper
                              2022-06-20 23:44:04.793Z

                              Hey, just wanted to circle back to this. Still can't seem to figure out why this script only sometimes does a successful "Object Select in Edit Window". And, I'm still trying to figure out how to add the step to select all tracks before doing the "Object Select in Edit Window"

                              Would really appreciate help on this one. Thanks!

                              1. samuel henriques @samuel_henriques
                                  2022-06-21 15:31:59.704Z2022-06-22 07:48:30.118Z

                                  Hey guys,
                                  Here's my take on this, I've have problems in the past where there would be cases where the first selected clip would not scroll to be visible, so this idea would fail.

                                  This will create a clip group and then undo. That will keep selected only tracks with selected clips.

                                  Let me know if it's closer to what you are looking for:

                                  f
                                  function selectGraber() {
                                      const grabberToolToolBtn = sf.ui.proTools.mainWindow.groups.allItems[2].buttons.whoseTitle.startsWith('Grabber tool').first
                                  
                                      grabberToolToolBtn.elementClick();
                                      grabberToolToolBtn.popupMenuSelect({
                                          isRightClick: true,
                                          menuPath: ['Object']
                                      });
                                  }
                                  
                                  function getOriginalToolSelection() {
                                      // Get original Tools Selection
                                      const originalToolSelection = sf.ui.proTools.mainWindow.cursorToolCluster.buttons.filter(btn =>
                                          btn.title.value == "Smart tool" ||
                                          btn.title.value == "Trim tool" ||
                                          btn.title.value == "Selector tool" ||
                                          btn.title.value.startsWith("Grabber tool")
                                      ).filter(btn => btn.value.invalidate().value === "Selected")
                                      return originalToolSelection
                                  };
                                  
                                  
                                  function setOriginalToolSelection(originalToolSelection) {
                                      ///Select Original Tools Selection
                                      originalToolSelection.map(selBtn => selBtn.title.value).indexOf("Smart Tool") > 0 ?
                                          originalToolSelection.filter(selBtn => selBtn.title.value === "Smart Tool")[0].elementClick() :
                                          originalToolSelection[0].elementClick()
                                  };
                                  
                                  function selectAllTracks() {
                                      sf.ui.proTools.groupsEnsureGroupListIsVisible();
                                      sf.ui.proTools.mainWindow.groupListView.children.whoseRole.is("AXColumn").first
                                          .children.whoseRole.is("AXRow").first
                                          .children.whoseRole.is("AXCell").first
                                          .buttons.first.elementClick();
                                  
                                  };
                                  
                                  function main() {
                                  
                                      const originalToolSelection = getOriginalToolSelection()
                                  
                                      sf.ui.proTools.menuClick({ menuPath: ["Options", "Link Track and Edit Selection"], targetValue: "Enable" });
                                  
                                      try {
                                  
                                          selectGraber()
                                  
                                          selectAllTracks()
                                  
                                          sf.ui.proTools.menuClick({ menuPath: ["Clip", "Group"] })
                                          sf.ui.proTools.menuClick({ menuPath: ["Edit", "Undo Group Clips"] })
                                  
                                          sf.ui.proTools.mainWindow.trackListPopupButton.popupMenuSelect({
                                              menuPath: ["Show Only Selected Tracks"],
                                          });
                                      } catch (e) { log("Woops. Somehing wrong has happened.") }
                                      finally {
                                          setOriginalToolSelection(originalToolSelection)
                                      }
                                  }
                                  
                                  main()
                                  
                                  1. Kitch Membery @Kitch2022-06-21 17:50:35.857Z

                                    Nice one @samuel_henriques :-)

                                    1. CCooper Babbes @cooper
                                        2022-06-22 00:13:12.420Z

                                        Thanks! This is awesome, but it sadly doesn't work for my needs. Anything that requires selecting down every single track or clip one at a time takes much too long in gigantic sessions that I need to work in. That's why I came up with the steps I did, because it's all relatively instantaneous.

                                        Also, because the sessions I'm trying to use this in have many hundreds of tracks, my goal here is to start with an edit selection on just one track that expands to all tracks (via a "select all tracks" step with Link Track and Edit Selection on).

                                        Every time I do that "select all tracks" step manually, the clips list always jumps the view to a selected clip. I wonder why it's inconsistent when doing it through a Soundflow command :(

                                        1. samuel henriques @samuel_henriques
                                            2022-06-22 07:47:33.200Z

                                            Hello Cooper,

                                            You are correct about the time to selecting down every track, in very large sessions, it's not useful.

                                            And you are correct that when you make a selection of clips some show selected on the clips list, but many times, specially on large sessions, the visible selected will not be the first selected, and that's what the script is looking for, let firstSelectedRow = selectedRows[0];this line is looking for the first selected. I think we might figure out a way to guess the visible selected, let's see.

                                            Just updated above a version doing the clip group thing and undo, but using the select all tracks from the "ALL" btn.

                                            A video like Kitch asked is a good idea, as well.

                                            Hope this is getting closer.

                                        2. In reply tocooper:
                                          Kitch Membery @Kitch2022-06-22 00:34:00.443Z

                                          Hi @cooper

                                          Could you do a screen recording? Maybe that will help us solve the issue.

                                          Rock on!