Turn selected track down -15 dB
Hi all,
I recently found a script from Andrew Scheps in another thread that would turn down the volume of a track in pro tools the assigned amount. And it works perfectly for the assigned track in the script, but I'd love the script to be more general and work for whichever track I have selected, regardless of its name. I imagine there is a relatively simple way to adjust this code to make it work, I just have no clue how to do it myself. Thanks for your help!!
Here is the original script I have so far:
const TARGET_TRACK = "Audio 7";
const VOLUME = '-15';
sf.ui.proTools.appActivateMainWindow();
const checkBoxes = [
{ Title: 'I/O', State: "Enable" },
];
function setCheckboxState(item) {
sf.ui.proTools.menuClick({
menuPath: ['View', 'Edit Window Views', item.Title],
targetValue: item.State,
onError: "Continue",
})
}
function setupScreen() {
//Make sure I/O visible in Edit window
checkBoxes.forEach(setCheckboxState);
}
function setVolume() {
sf.ui.proTools.mainWindow.invalidate();
if (sf.ui.proTools.selectedTrack.outputWindowButton.value.invalidate().value != 'open')
sf.ui.proTools.selectedTrack.outputWindowButton.elementClick();
var win = sf.ui.proTools.floatingWindows.allItems.filter(function (w) {
return w.children.whoseTitle.is('Volume').exists;
})[0];
win.textFields.whoseTitle.is('Volume Numerical').first.elementClick();
sf.keyboard.type({ text: VOLUME });
sf.keyboard.press({ keys: 'enter' });
}
function main() {
setupScreen();
//Save the name of the originally selected track
var originalTrackName = sf.ui.proTools.selectedTrackNames[0];
//Select the desired track
sf.ui.proTools.trackSelectByName({ names: [TARGET_TRACK] });
//Set the volume
setVolume();
//Select original track again
sf.ui.proTools.trackSelectByName({ names: [originalTrackName] });
}
main();
- Chris Shaw @Chris_Shaw2021-05-08 00:14:23.602Z2021-05-08 00:28:05.379Z
You were pretty close.
This will set all selected tracks to -15. To set another volume just change
VOLUME =
to the desired value.const TARGET_TRACKS = sf.ui.proTools.selectedTrackNames; const VOLUME = '-15'; sf.ui.proTools.appActivateMainWindow(); const checkBoxes = [ { Title: 'I/O', State: "Enable" }, ]; function setCheckboxState(item) { sf.ui.proTools.menuClick({ menuPath: ['View', 'Edit Window Views', item.Title], targetValue: item.State, onError: "Continue", }) } function setupScreen() { //Make sure I/O visible in Edit window checkBoxes.forEach(setCheckboxState); } function setVolume() { sf.ui.proTools.mainWindow.invalidate(); if (sf.ui.proTools.selectedTrack.outputWindowButton.value.invalidate().value != 'open') sf.ui.proTools.selectedTrack.outputWindowButton.elementClick(); var win = sf.ui.proTools.floatingWindows.allItems.filter(function (w) { return w.children.whoseTitle.is('Volume').exists; })[0]; win.textFields.whoseTitle.is('Volume Numerical').first.elementClick(); sf.keyboard.type({ text: VOLUME }); sf.keyboard.press({ keys: 'enter' }); } function main() { setupScreen(); for (var i = 0; i < TARGET_TRACKS.length; i++) { //Select the desired track sf.ui.proTools.trackSelectByName({ names: [TARGET_TRACKS[i]] }); //Set the volume setVolume(); }; //Select original track again sf.ui.proTools.trackSelectByName({ names: TARGET_TRACKS }); } main();
PS - when you have a minute check this video out to learn how to post code on the forum:
How to quote code in the SoundFlow forum.- RRyan Short @Ryan_Short
Ah lovely, this is great, thanks so much Chris! Last little help request: would it be possible to also add that it then closes the fader window when the function is complete? (Sorry, I intend to learn how to do this stuff myself!)
And yes, I'm definitely gonna check out this link you sent, thanks for the help!
Chris Shaw @Chris_Shaw2021-05-08 00:33:45.879Z
No problem. I've even shortened the code by replacing the the
for
loop with aforEach
loop:const TARGET_TRACKS = sf.ui.proTools.selectedTrackNames; const VOLUME = '-15'; sf.ui.proTools.appActivateMainWindow(); const checkBoxes = [ { Title: 'I/O', State: "Enable" }, ]; function setCheckboxState(item) { sf.ui.proTools.menuClick({ menuPath: ['View', 'Edit Window Views', item.Title], targetValue: item.State, onError: "Continue", }) } function setupScreen() { //Make sure I/O visible in Edit window checkBoxes.forEach(setCheckboxState); } function setVolume() { sf.ui.proTools.mainWindow.invalidate(); if (sf.ui.proTools.selectedTrack.outputWindowButton.value.invalidate().value != 'open') sf.ui.proTools.selectedTrack.outputWindowButton.elementClick(); var win = sf.ui.proTools.floatingWindows.allItems.filter(function (w) { return w.children.whoseTitle.is('Volume').exists; })[0]; win.textFields.whoseTitle.is('Volume Numerical').first.elementClick(); sf.keyboard.type({ text: VOLUME }); sf.keyboard.press({ keys: 'enter' }); } function main() { setupScreen(); TARGET_TRACKS.forEach(function (track) { sf.ui.proTools.trackSelectByName({ names: [track] }); //Set the volume setVolume(); }); //Select original track(s) again sf.ui.proTools.trackSelectByName({ names: TARGET_TRACKS }); } main(); sf.ui.proTools.mainTrackOutputWindow.getElement("AXCloseButton").elementClick();
- RRyan Short @Ryan_Short
Oh man, amazing! Works perfectly, thank so much! This is so helpful for when I drag in samples or something into my session and instantly need to just knock them down a bit to fit with the rest of my gain structure! Thanks Chris!
- In reply toChris_Shaw⬆:MMarc Bazerman @Marc_Bazerman
This is great, building this into a bigger script that I am creating for important of tracks.
Thanks
- MIn reply toRyan_Short⬆:Matthew Bronleewe @Matthew_Bronleewe
Is there a way to have this script ask what volume you want to set to?
Nathan Salefski @nathansalefski
Sure is, you would just need to change the constant variable of
VOLUME
to a prompt like below:const TARGET_TRACKS = sf.ui.proTools.selectedTrackNames; const VOLUME = sf.interaction.displayDialog({ prompt: `Enter Target Volume`, defaultAnswer: '', buttons: ['Cancel', 'OK'], defaultButton: 'OK', }).text; sf.ui.proTools.appActivateMainWindow(); const checkBoxes = [ { Title: 'I/O', State: "Enable" }, ]; function setCheckboxState(item) { sf.ui.proTools.menuClick({ menuPath: ['View', 'Edit Window Views', item.Title], targetValue: item.State, onError: "Continue", }) } function setupScreen() { //Make sure I/O visible in Edit window checkBoxes.forEach(setCheckboxState); } function setVolume() { sf.ui.proTools.mainWindow.invalidate(); if (sf.ui.proTools.selectedTrack.outputWindowButton.value.invalidate().value != 'open') sf.ui.proTools.selectedTrack.outputWindowButton.elementClick(); var win = sf.ui.proTools.floatingWindows.allItems.filter(function (w) { return w.children.whoseTitle.is('Volume').exists; })[0]; win.textFields.whoseTitle.is('Volume Numerical').first.elementClick(); sf.keyboard.type({ text: VOLUME }); sf.keyboard.press({ keys: 'enter' }); } function main() { setupScreen(); TARGET_TRACKS.forEach(function (track) { sf.ui.proTools.trackSelectByName({ names: [track] }); //Set the volume setVolume(); }); //Select original track(s) again sf.ui.proTools.trackSelectByName({ names: TARGET_TRACKS }); } main(); sf.ui.proTools.mainTrackOutputWindow.getElement("AXCloseButton").elementClick();
- MIn reply toRyan_Short⬆:Matthew Bronleewe @Matthew_Bronleewe
For some reason I got an error the first time it ran, but now it's running smoothly! This is great, thanks!