No internet connection
  1. Home
  2. How to

Edit tool toggle

By Mark Mangini @Mark_Mangini
    2021-04-17 17:12:53.285Z

    Does any have a macro that toggles all the edit tools. As I am using Stream Deck I would want it to toggle between TRIM-SELECT-GRAB each time I press a button. I don't see any Macros that do this. Thanks in advance for anyone who can help.

    Solved in post #6, click to view
    • 9 replies
    1. samuel henriques @samuel_henriques
        2021-04-17 17:55:42.556Z2021-04-17 18:19:31.430Z

        Hello @Mark_Mangini,

        Try this, let me know how it goes.
        It's possible to remove the Smart Tool if you want

        sf.ui.proTools.appActivateMainWindow();
        
        const btn = sf.ui.proTools.mainWindow.groups.allItems[2].buttons
        const trimBtn = btn.allItems[2].invalidate().value.value === "Selected"
        const selectorBtn = btn.allItems[3].invalidate().value.value === "Selected"
        const grabberBtn = btn.allItems[4].invalidate().value.value === "Selected"
        
        
        
        let selectTool
        switch (true) {
            case trimBtn && selectorBtn && grabberBtn: selectTool = "Trim"
                break;
            case trimBtn: selectTool = "Selector"
                break;
            case selectorBtn: selectTool = "Grabber"
                break;
            case grabberBtn: selectTool = "Smart"
                break;
        }
        
        sf.ui.proTools.toolsSelect({ tool: selectTool }) // Red lined but works
        
        1. samuel henriques @samuel_henriques
            2021-04-17 18:18:30.928Z

            UPDATE: changed to Switch Statement, it seams to make more sense.

            1. Hi Samuel,

              Your updated switch statement unfortunately doesn't make much sense, since you're switching on a constant, not a variable. AFAIK you can't make it work this way.

              You were also using an indexed group to get to the items (the groups.allItems[2]) - this is not very stable, since it is dependent on groups potentially being rearranged.

              In this code, I'm using SoundFlow's built in syntax for the cursor tool cluster to get directly to the correct buttons :)

              const { trimTool, selectorTool, grabberTool } = 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';
              
              /**@type {'Trim' | 'Selector' | 'Grabber' | 'Smart'} */
              let newTool = 'Trim';
              if (isTrimTool && isSelectorTool && isTrimTool) newTool = 'Trim';
              else if (isTrimTool) newTool = 'Selector';
              else if (isSelectorTool) newTool = 'Grabber';
              else if (isGrabberTool) newTool = 'Smart';
              
              sf.ui.proTools.toolsSelect({ tool: newTool });
              
              1. samuel henriques @samuel_henriques
                  2021-04-19 09:45:19.234Z2021-04-19 15:44:51.486Z

                  Hey @chrscheuer thank you for jumping in,

                  I did wander if groups.allItems[2]could have problems in different systems.
                  This makes it way better

                  const { trimTool, selectorTool, grabberTool } = sf.ui.proTools.mainWindow.cursorToolCluster;
                  

                  Didn't know you could choose the propery like this, awesome

                  And now we have access to the smartToo valuel, we can clean up that &&:

                  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 });
                  

                  Just noticed that this sf.ui.proTools.toolsSelect({ tool: undefined });
                  will select trimTool, that's why I didn't notice I needed a default value, so I'm guessing you used let newTool = 'Trim'; instead of let newTool to have a default ?

                  About the switch i'll make a new thread so it doesn't clutter this one.

                  @Mark_Mangini, I'm sorry, I'm learning as I go. Although the two codes might behave the same now, you should change to Christian's, technically his is more error proof.

                  Thank you so much Christian.

                  Reply2 LikesSolution
                  1. MMark Mangini @Mark_Mangini
                      2021-04-19 10:24:57.960Z

                      So which code should I copy?

                      1. samuel henriques @samuel_henriques
                          2021-04-19 10:35:21.886Z

                          this is the best one, I made a slight change to it but @Christian might have something to add.

                          1. Confirming: This latest version from Samuel is the best one :)

                            1. MMark Mangini @Mark_Mangini
                                2021-04-19 15:21:50.905Z

                                Yup, that works really well, too. Thank you both.

                  2. M
                    In reply toMark_Mangini:
                    Mark Mangini @Mark_Mangini
                      2021-04-18 16:53:55.183Z

                      Thank you Samuel. That works great!!