Set mono Track's Pan slider
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
- In reply toKitch⬆:Ryan DeRemer @Ryan_DeRemer
@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! :)
- In reply toKitch⬆:Christian Scheuer @chrscheuer2022-05-19 23:15:42.148Z
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?Kitch Membery @Kitch2022-05-19 23:22:22.871Z
Rooky mistakes.
Update now. Thanks C!:-)