No internet connection
  1. Home
  2. How to

Edit tools toggle question

By Thomas Gloor @Thomas_Gloor
    2021-07-03 16:04:07.063Z

    Hi!

    I wrote this little piece of code to be able to toggle between Trimmer/Selector and Grabber Tools in Pro Tools.
    I NEVER want to use the "sub-tools", my goal is to toggle between the 3 main tools)

    //selector tool variable
    var selectorTool = sf.ui.proTools.mainWindow.groups.whoseTitle.is("Cursor Tool Cluster").first.buttons.whoseTitle.is("Selector tool").first;
    
    //grabber tool variables
    var grabberTool = sf.ui.proTools.mainWindow.groups.whoseTitle.is("Cursor Tool Cluster").first.buttons.whoseTitle.is("Grabber tool (Time)").first;
    var splitgrabberTool = sf.ui.proTools.mainWindow.groups.whoseTitle.is("Cursor Tool Cluster").first.buttons.whoseTitle.is("Grabber tool (Separation)").first;
    var objectgrabberTool = sf.ui.proTools.mainWindow.groups.whoseTitle.is("Cursor Tool Cluster").first.buttons.whoseTitle.is("Grabber tool (Object)").first;
    
    //trimmer tool variables
    var trimmerTool = sf.ui.proTools.mainWindow.groups.whoseTitle.is("Cursor Tool Cluster").first.buttons.whoseTitle.is("Trim tool").first;
    var stretchtrimmerTool = sf.ui.proTools.mainWindow.groups.whoseTitle.is("Cursor Tool Cluster").first.buttons.whoseTitle.is("Time Compression/Expansion Trim tool").first;
    var scrubtrimmerTool = sf.ui.proTools.mainWindow.groups.whoseTitle.is("Cursor Tool Cluster").first.buttons.whoseTitle.is("Scrub Trim tool").first;
    var looptrimmerTool = sf.ui.proTools.mainWindow.groups.whoseTitle.is("Cursor Tool Cluster").first.buttons.whoseTitle.is("Loop Trim tool").first;
    
    
    //Toggle command
    if(selectorTool.value.invalidate().value === "Selected") {
        grabberTool.elementClick();
    
    } else if (grabberTool.value.invalidate().value === "Selected") {
        trimmerTool.elementClick();
    
    } else {
        selectorTool.elementClick();
        
    }
    

    I created all the variables corresponding to the tools and subtools.

    With this actual script, when toggling from the main tools, there are no problems, but when let's say the TIMESTRETCH trimmer is activated, the script fails.

    How can I work this out? I guess I'd have to do something along the lines of

    if grabberTool.value.inv or splitgrabberTool or objectgrabberTools is selected then select trimmerTool

    Any idea?

    • 22 replies

    There are 22 replies. Estimated reading time: 11 minutes

    1. samuel henriques @samuel_henriques
        2021-07-03 18:12:22.506Z

        Hey Thomas,

        I made this a while ago, give it a try.

        sf.ui.proTools.appActivateMainWindow();
        
        const { trimTool, selectorTool, grabberTool, smartTool } = sf.ui.proTools.mainWindow.cursorToolCluster;
        
        const isTrimTool = trimTool.value.invalidate().value === 'Selected';
        const isSelectorTool = selectorTool.value.invalidate().value === 'Selected';
        const isGrabberTool = grabberTool.value.invalidate().value === 'Selected';
        const isSmartTool = smartTool.value.invalidate().value === 'Selected';
        
        
        /**@type {'Trim' | 'Selector' | 'Grabber' | 'Smart'} */
        let newTool = 'Trim';
        if (isSmartTool) newTool = 'Trim';
        else if (isTrimTool) newTool = 'Selector';
        else if (isSelectorTool) newTool = 'Grabber';
        else if (isGrabberTool) newTool = 'Smart';
        
        
        sf.ui.proTools.toolsSelect({ tool: newTool });
        
        1. Very slick…

          1. samuel henriques @samuel_henriques
              2021-07-03 20:47:04.850Z

              Hi Chris, really appreciate, thank you.

              1. samuel henriques @samuel_henriques
                  2021-07-03 23:37:29.332Z

                  Actually this is not my script, I was filling with this idea, but Christian made it for me.

                  1. Ahh ok.
                    That first line is the slick part.

                    1. samuel henriques @samuel_henriques
                        2021-07-04 09:36:42.884Z2021-07-04 09:58:38.083Z

                        Yep, and the **@type. when I posted, I started to wonder how I'd come up with these and with a bit of investigation it was pretty evident I didn't 😂!

                • @Thomas_Gloor : If you don't want to cycle the smart tool just delete the line:
                  else if (isGrabberTool) newTool = 'Smart';

                  1. TThomas Gloor @Thomas_Gloor
                      2021-07-07 07:49:28.364Z

                      Hey @samuel_henriques

                      I tried it! It now doesnt fail when another sub tool is selected, but when let's say the "time stretch" trim tool is selected, it moves on to the selector and doesn't move any more...It does work perfectly when a GRABBER sub tool is selected.

                      Any idea?

                      1. samuel henriques @samuel_henriques
                          2021-07-07 09:51:29.606Z

                          You are right, are you on pt 2021.6? I'm on 2022.6 and it is behaving as you say. The way the buttons have "selected" value might have changed.
                          I'll figure out another way.

                          1. samuel henriques @samuel_henriques
                              2021-07-07 10:33:40.040Z

                              In the mean time, if you don't mind reseting trim and grabber to the standard position, this should do it:

                              sf.ui.proTools.appActivateMainWindow();
                              
                              const { trimTool, selectorTool, grabberTool, smartTool } = sf.ui.proTools.mainWindow.cursorToolCluster;
                              
                              const isTrimTool = trimTool.value.invalidate().value === 'Selected';
                              const isSelectorTool = selectorTool.value.invalidate().value === 'Selected';
                              const isGrabberTool = grabberTool.value.invalidate().value === 'Selected';
                              const isSmartTool = smartTool.value.invalidate().value === 'Selected';
                              
                              
                              if (trimTool.title.invalidate().value != 'Trim tool') { trimTool.popupMenuSelect({ menuPath: ['Standard'], isRightClick: true }) }
                              if (grabberTool.title.invalidate().value != 'Grabber tool (Time)') { grabberTool.popupMenuSelect({ menuPath: ['Time'], isRightClick: true }) }
                              
                              /**@type {'Trim' | 'Selector' | 'Grabber' | 'Smart'} */
                              let newTool = 'Trim';
                              if (isSmartTool) newTool = 'Trim';
                              else if (isTrimTool) newTool = 'Selector';
                              else if (isSelectorTool) newTool = 'Grabber';
                              else if (isGrabberTool) newTool = 'Smart';
                              
                              
                              sf.ui.proTools.toolsSelect({ tool: newTool });
                              
                              1. TThomas Gloor @Thomas_Gloor
                                  2021-07-07 11:00:58.659Z

                                  hey @samuel_henriques

                                  thank you it works perfectly!

                                  I run PT 2020.12.0

                                  Do you have a way to avoid the popup menu?

                                  Thank you so much!

                                  1. samuel henriques @samuel_henriques
                                      2021-07-07 13:09:17.860Z

                                      This is not ideal, since it doesn't "know" which tool is selected, but will circle them.
                                      Just out of curiosity, why is this better than using the F6, F7, F8?

                                      Let me know if you want to remove the Smart tool:

                                      sf.ui.proTools.appActivateMainWindow();
                                      
                                      
                                      if (globalState.newTool === undefined) { globalState.newTool = 'Smart' }
                                      
                                      if (globalState.newTool === 'Smart') {
                                      
                                          globalState.newTool = 'Trim'
                                      
                                      } else if (globalState.newTool === 'Trim') {
                                      
                                          globalState.newTool = 'Selector'
                                      
                                      } else if (globalState.newTool === 'Selector') {
                                      
                                          globalState.newTool = 'Grabber'
                                      
                                      } else if (globalState.newTool === 'Grabber') {
                                      
                                          globalState.newTool = 'Smart'
                                      }
                                      
                                      sf.ui.proTools.toolsSelect({ tool: globalState.newTool });
                                      
                                      1. TThomas Gloor @Thomas_Gloor
                                          2021-07-07 13:46:28.980Z

                                          Hey @samuel_henriques

                                          Thank you! It's exactly what I was looking for! I modified it so it doesn't use the Smart Tool.

                                          Well, It might sound stupid, but I have a two stream decks. One on the left hand side of the keyboard and one above in the center.

                                          The left one is basically used for editing shortcuts, etc etc. I added very common short cuts so my hand can stay on it, and also to avoid keyboard shortcuts that twist my hand.

                                          1. TThomas Gloor @Thomas_Gloor
                                              2021-07-07 13:48:07.945Z

                                              I did however leave

                                              if (globalState.newTool === undefined) { globalState.newTool = 'Smart' }````
                                              
                                              should I replace SMART by Trim or Grabber?
                                              1. samuel henriques @samuel_henriques
                                                  2021-07-07 14:01:20.580Z2021-07-07 14:40:22.822Z

                                                  Cool, doesn't sound stupid at all, everyone has their own workflow. I always learn something new.

                                                  without the smart tool it should be like this, you should restart SoundFlow after applying this code.

                                                  the line:

                                                  if (globalState.newTool === undefined) { globalState.newTool = 'Trim' }
                                                  

                                                  is there to make sure globalState.newTool has a value. When you restart SoundFlow, globalState values are lost. Without this line, every time you restart, the script won't work.

                                                  if (globalState.newTool === undefined) { globalState.newTool = 'Trim' }
                                                  
                                                  
                                                  if (globalState.newTool === 'Trim') {
                                                  
                                                      globalState.newTool = 'Selector'
                                                  
                                                  } else if (globalState.newTool === 'Selector') {
                                                  
                                                      globalState.newTool = 'Grabber'
                                                  
                                                  } else if (globalState.newTool === 'Grabber') {
                                                  
                                                      globalState.newTool = 'Trim'
                                                  }
                                                  
                                                  sf.ui.proTools.toolsSelect({ tool: globalState.newTool });
                                                  
                                                  1. TThomas Gloor @Thomas_Gloor
                                                      2021-07-08 07:47:29.709Z

                                                      Hey @samuel_henriques
                                                      Thank you so much again.

                                                      One more question. I have a toggle command to flip between SLIP and ABS GRID mode. It fails when the grid is in REL GRID.

                                                      var grid = sf.ui.proTools.mainWindow.groups.whoseTitle.is("Edit Mode Cluster").first.buttons.whoseTitle.is("Absolute Grid mode").first;
                                                      var relgrid = sf.ui.proTools.mainWindow.groups.whoseTitle.is("Edit Mode Cluster").first.buttons.whoseTitle.is("Relative Grid mode").first;
                                                      
                                                      var slip = sf.ui.proTools.mainWindow.groups.whoseTitle.is("Edit Mode Cluster").first.buttons.whoseTitle.is("EditModeSlip").first;
                                                      
                                                      if(grid.value.invalidate().value === "Selected") {
                                                          slip.elementClick();
                                                      } else {
                                                          grid.elementClick()
                                                      }
                                                      

                                                      Do you have a variant of your EDIT TOOL TOGGLE for this? That would not fail but just stay in rel grid, or even better, switch to abs grid and move on?

                                                      Best,

                                                      T.

                                                      1. samuel henriques @samuel_henriques
                                                          2021-07-08 08:14:13.185Z

                                                          Hi Thomas,
                                                          Could you post this question on a new thread, please, just so it's easier for others to find in the future.
                                                          I'll try something and let you know.

                                                          1. TThomas Gloor @Thomas_Gloor
                                                              2021-07-08 08:16:10.555Z

                                                              Samuel,

                                                              Will do now!

                                                              1. TThomas Gloor @Thomas_Gloor
                                                                  2021-07-16 11:30:53.597Z

                                                                  Hey @samuel_henriques !

                                                                  I noticed something weird with the edit tools toggle

                                                                  Sometimes it doesnt fully switch the tool before I click (anywhere in the timeline)

                                                                  Any idea?

                                                                  Best,

                                                                  T

                                                                  1. samuel henriques @samuel_henriques
                                                                      2021-07-16 15:22:09.630Z

                                                                      Not being able to reproduce the problem.
                                                                      Try to notice more details, like just did something to pro tools, or just opened session...
                                                                      In the mean time, you can try to activate pro tools, put this line at the start of the script,

                                                                      sf.ui.proTools.appActivateMainWindow();
                                                                      
                                                                      1. TThomas Gloor @Thomas_Gloor
                                                                          2021-07-16 16:00:21.195Z

                                                                          ok. let's see :)

                                                                          this line was already in!

                                                                          Thank you anyway :)

                                                                          1. samuel henriques @samuel_henriques
                                                                              2021-07-16 16:10:42.965Z

                                                                              ahh, yes it was I was looking to the wrong post.

                                                                              If you get any hits let me know, and I'll try as well.