No internet connection
  1. Home
  2. How to

How to programmatically set stereo pan

This script shows how to programmatically set the pan for a stereo track -> stereo output.

Solved in post #2, click to view
  • 15 replies
  1. //Config
    var howWide = 45;
    
    //Reset pan first
    sf.ui.proTools.trackOutputWindowResetPan();
    
    var win = sf.ui.proTools.mainTrackOutputWindow;
    
    //Get the two front pan knobs
    var pans = win.getElements('AXChildren').filter(function(e){ return e.title.value === "Front Pan Knob" });
    
    //Step through decrementing (turning left) Front Left pan, and incrementing (turning right) Front Right pan
    //thus widening the pan (because we start at center)
    var steps = Math.floor(howWide/5);
    for(var i=0; i<steps; i++)
    {
        pans[0].elementClick({actionName: 'AXDecrement'});
        pans[1].elementClick({actionName: 'AXIncrement'});
    }
    
    ReplySolution
    1. In reply tochrscheuer:

      Here's a version that sets the pan and writes it to the selected clip:

      //Config
      var howWide = 60;
      
      //Enable preview
      sf.ui.proTools.automationPreview({ targetValue: 'Enable' });
      
      //Reset pan first
      sf.ui.proTools.selectedTrack.trackOutputToggleShow();
      sf.ui.proTools.trackOutputWindowResetPan();
      
      var win = sf.ui.proTools.mainTrackOutputWindow;
      
      //Get the two front pan knobs
      var pans = win.getElements('AXChildren').filter(function(e){ return e.title.value === "Front Pan Knob" });
      
      //Step through decrementing (turning left) Front Left pan, and incrementing (turning right) Front Right pan
      //thus widening the pan (because we start at center)
      var steps = Math.floor(howWide/5);
      for(var i=0; i<steps; i++)
      {
          pans[0].elementClick({actionName: 'AXDecrement'});
          pans[1].elementClick({actionName: 'AXIncrement'});
      }
      
      sf.ui.proTools.automationWriteAutoToSelectionAndCloseWindows();
      
      1. Fokke van Saane @Fokke
          2018-07-21 08:10:41.725Z

          after the action protools prompts me : No Automation was written

          1. @Fokke I think I forgot to mention this action requires that you have 'Pan' enabled in the automation window.
            We could add that to the script if that's not something you are usually using.

            1. Fokke van Saane @Fokke
                2018-07-21 11:50:07.220Z

                it is enabled and still does it

                1. Fokke van Saane @Fokke
                    2018-07-21 11:54:20.868Z

                    Sorry, for some reason it works now.
                    But it does leave PREVIEW on in the Automation Window. See if i can turn that off.

                    1. Fokke van Saane @Fokke
                        2018-07-21 12:00:43.770Z

                        ah wait, it works on stereo to 5.1 but not on stereo to stereo tracks.

                        1. Fokke van Saane @Fokke
                            2018-07-21 17:04:37.307Z

                            To continue the sequel, i was wrong again! It DOES work on stereo to stereo tracks, but we get the error when the automation mode is set to READ! It should be on Touch Write or Latch.

                  • In reply tochrscheuer:
                    NNicolai Linck @Nicolai_Linck7
                      2024-01-05 10:27:15.163Z

                      This is great!. Is there a way to detect if the output window is open and if it is move on with the script? Right now it closes the window and gives you an error..
                      Thanks in advance

                      1. SSreejesh Nair @Sreejesh_Nair
                          2024-01-05 10:49:34.156Z

                          This should help. This is what I use as it considers both track as well as object outputs.

                              let outputWindowState = sf.ui.proTools.selectedTrack.outputWindowButton.value.invalidate().value;
                              if (!["open", "output bypassed active open"].includes(outputWindowState)) {
                                  sf.ui.proTools.selectedTrack.trackOutputToggleShow();
                              }
                          
                          1. NNicolai Linck @Nicolai_Linck7
                              2024-01-05 11:14:35.151Z

                              It works like a charm, but it somehow breaks the panning setting..

                              1. NNicolai Linck @Nicolai_Linck7
                                  2024-01-05 11:21:41.957Z

                                  And it somehow also closes all open insert windows?

                                  1. SSreejesh Nair @Sreejesh_Nair
                                      2024-01-05 11:28:11.876Z

                                      Strange. Works perfectly on my system. What panning setting is it breaking?

                                      1. NNicolai Linck @Nicolai_Linck7
                                          2024-01-05 13:07:22.021Z

                                          Ahh got it right.. I misplaced it and it messed up the panning.. Thank you so much for helping

                              2. V
                                In reply tochrscheuer:
                                Vanessa Garde @Vanessa_Garde
                                  2022-01-01 20:22:19.595Z

                                  Hi there,

                                  How would you modify it to Set Center% Knob to 0? (not putting it on preview, as I just want a start point with tracks on "read" without going to the center channel on the Center % pan setting...?

                                  Thanks a lot! Happy new year!