No internet connection
  1. Home
  2. How to

Set mono Track's Pan slider

By Kitch Membery @Kitch2022-05-18 22:05:25.855Z2022-05-19 23:21:31.785Z

Question from the SoundFlow Hangout this week by @Ryan_DeRemer,

How do I set a mono track's Pan slider without having to open the track's floating fader window?

The way to do this is by using the AXIncrement and AXDecrement actions within the elementClick() method.

Unfortunately, there is a limitation in that the fixed Increment & Decrement value is in +/-5 increments. But from what I remember this should serve your purpose.

Here is the script;

/**
 * Adjusts a mono track's pan slider rounded to the nearest 5
 * @param {{trackName: string, sliderValue: number}} args
*/
function setPanSlider({ trackName, sliderValue }) {
    if (sliderValue > 100 || sliderValue < -100) {
        throw "Please slider value must be withing -100 and 100";
    }

    const track = sf.ui.proTools.trackGetByName({ name: trackName }).track
    const ioPannel = track.groups.whoseTitle.is("Audio IO").first;
    let panSlider = ioPannel.sliders.whoseTitle.startsWith("Audio Pan indicator").first;

    //Rest the fader to 0
    panSlider.elementClick({ actionName: "AXPick" });

    //Round Values to the nearst 5
    let roundedSliderVal = Math.ceil(sliderValue / 5) * 5;

    let tryCount = 1;
    let maxTryCount = 20;

    if (panSlider.value.invalidate().intValue > roundedSliderVal) {
        while (panSlider.value.invalidate().intValue > roundedSliderVal && tryCount <= maxTryCount) {

            panSlider.elementClick({ actionName: 'AXDecrement' });

            tryCount++ //Increments Try Count
        }
    } else {
        while (panSlider.value.invalidate().intValue < roundedSliderVal && tryCount <= maxTryCount) {

            panSlider.elementClick({ actionName: 'AXIncrement' });

            tryCount++ //Increments Try Count
        }
    }
}

setPanSlider({
    trackName: "Audio 1",
    sliderValue: -15
});

PS. I spelled "Increment" correctly this time

I hope that helps :-)

Updated 05/19/22

  • 4 replies
  1. Kitch Membery @Kitch2022-05-18 22:34:07.143Z

    @Chris_Shaw My spelling!!!! 🤦‍♂️

    1. In reply toKitch:
      Ryan DeRemer @Ryan_DeRemer
        2022-05-19 04:43:05.209Z

        @Kitch you're a legend! I'm gonna start picking this apart to better understand it. I may have questions later, but as of now this is working. Thanks! I haven't really wrapped my head around the Math part (the roundedSliderValue part). Off to Youtube! :)

        1. In reply toKitch:

          Nice! Small correction, the tryCount comparison is in the "if" block where it should be in the "while" block in the first case (decrement case).
          And you're comparing to roundedSliderVal but to sliderValue in the while block - I'm thinking it should compare to rounderSliderVal right?

          1. Kitch Membery @Kitch2022-05-19 23:22:22.871Z

            Rooky mistakes.

            Update now. Thanks C!:-)