No internet connection
  1. Home
  2. Support

RIght Click Submenu Selection PT

By Simon Franglen @Simon_Franglen
    2020-03-19 00:00:37.932Z

    Hi Christian,

    You’ve got loads of Audio commands but not much for us Midi fiends.

    I have Keyboard Maestro macros for right click Menu items that have submenus that I want to replace with Soundflow.

    In KM I have to do this the hard way, right click/wait/then move a specific number of pixels and click.

    Is there a neater solution?

    First example:

    Insert A Chord Symbol…

    To do this, I have to right click at the timeline insertion point, wait for the 1st level menu to arrive then slide right and select Chord Symbol…

    Solved in post #4, click to view
    • 7 replies
    1. Hi Simon

      Generally for popup menus, use the built in action "Open & Select Item in Popup Menu" in the macro editor.
      There's no need to manually wait for the popup menu to appear or to navigate it, SF takes care of that for you.

      You can see a video of how it works here:
      https://www.youtube.com/watch?v=20ECpTUy_jk

      For right clicking in the middle of the MIDI editor, you'll probably need a script.
      Something like this could get you started:

      
      function getCoordsOfMIDIArea(win) {
          var keyboardTable = win.tables.whoseTitle.is("TextGridView").filter(e => e.childrenByRole("AXColumn").count === 1)[0];
          var keyboardFrame = keyboardTable.frame;
          var winFrame = win.frame;
      
          var x = keyboardFrame.x + keyboardFrame.w;
          var y = keyboardFrame.y;
          var w = winFrame.w - x - 30;
          var h = keyboardFrame.h;
          var cx = Math.floor(x + w / 2);
          var cy = Math.floor(y + h / 2);
      
          return { x, y, w, h, cx, cy };
      }
      
      var midiEditorWin = sf.ui.proTools.windows.whoseTitle.startsWith("MIDI Editor:").first;
      var coords = getCoordsOfMIDIArea(midiEditorWin);
      
      midiEditorWin.popupMenuSelect({
          relativePosition: { x: coords.cx, y: coords.cy },
          isRightClick: true,
          menuPath: ['Insert', 'Chord Symbol...']
      });
      

      Please note however, while SoundFlow typically can read UI elements across the screen, we can't read the contents of the actual tracks, ie. the actual notes. I don't think we can read where the timeline insertion point is either. So for this particular usage, we may need a different approach.

      1. SSimon Franglen @Simon_Franglen
          2020-03-19 15:00:28.658Z

          Hi Christian,
          I don't need to select the click point with the macro, I can just move the mouse to wherever I want and then trigger the script. The current mouse location acts as the location for the Chord Symbol or Meter change, my issue was really with selecting Sub menus with menus. Here's a video of what I do manually

          https://www.dropbox.com/s/s2mkfhmw1qtoxio/Right Click for Midi Menu items.mov?dl=0

          and also a screen grab of how I've implemented it within Keyboard Maestro

          1: Right Click and Hold wherever the mouse is
          2: Wait 1 Sec - I found less couldn't be trusted - that brings up the top level of the right click Midi menu
          3: Move Mouse to the right and down
          4: Click and Release

          1. Ah gotcha - then it's as simple as this:

            var midiEditorWin = sf.ui.proTools.windows.whoseTitle.startsWith("MIDI Editor:").first;
            var midiEditorWinFrame = midiEditorWin.frame; 
            var mousePos = sf.mouse.getPosition().position;
            
            midiEditorWin.popupMenuSelect({
                relativePosition: { x: mousePos.x - midiEditorWinFrame.x, y: mousePos.y - midiEditorWinFrame.y },
                isRightClick: true,
                menuPath: ['Insert', 'Chord Symbol...']
            });
            

            Note how you can change it to any item in any sub menu, no need to manually calculate offsets :)

            ReplySolution
            1. SSimon Franglen @Simon_Franglen
                2020-03-20 12:53:17.108Z2020-03-20 12:56:40.814Z

                This works great. Thank you so much. Infinitely better than my Keyboard Maestro version.
                Could you check something, I've amended the script to work in the main editor window as we often add Chords, Meter changes etc… there. I
                did this by changing the 'startswith' to a 'contains' - since it's case sensitive. I set the string variable as: contains 'dit' - as both the main editor and the midi editor contain that string. Is this the most elegant way to do it, or have you got a cleaner solution?

                sf.ui.proTools.appActivateMainWindow();
                
                var EditorWin = sf.ui.proTools.windows.whoseTitle.contains("dit").first;
                var EditorWinFrame = EditorWin.frame; 
                var mousePos = sf.mouse.getPosition().position;
                
                EditorWin.popupMenuSelect({
                    relativePosition: { x: mousePos.x - EditorWinFrame.x, y: mousePos.y - EditorWinFrame.y },
                    isRightClick: true,
                    menuPath: ['Insert', 'Chord Symbol...']
                });
                
                1. You can use a regular expression to match on the title like this:

                  var EditorWin = sf.ui.proTools.windows.filter(w => w.title.value.match(/^(Edit:|MIDI Editor:)/))[0];
                  
                  1. SSimon Franglen @Simon_Franglen
                      2020-03-20 13:06:13.847Z

                      Got it, I'm going to use that a lot

                      1. Awesome :) So great to have you on board here Simon!