If else statement to vca output
By mikkeljm @mikkeljm
I have this script that routes, and puts a track in a folder for programmed kick drums. It creates a group and add an already created vca fader to the group. I also have a folder for programmed snare drum that does the same, but I need SF to read the state of the vca io so it doesn't try and add the vca to the group once again. I can't figure out how to write that "if else" statement. @Kitch helped me out yesterday with a script that might do this trick as well.
Heres the script I use for now
let targetOutputName = "Prg Kick (Stereo)";
sf.ui.proTools.appActivateMainWindow();
sf.ui.proTools.mainWindow.invalidate();
sf.ui.proTools.selectedTrack.trackOutputSelect({
outputSelector: menuItems => menuItems.filter(mi => mi.path[mi.path.length - 1] === targetOutputName)[0],
selectForAllSelectedTracks: true,
});
sf.ui.proTools.selectedTrack.titleButton.popupMenuSelect({
isRightClick: true,
menuPath: ['Move to...', ' -Prg Kick'],
});
// Get originally selected tracks and first orig selected track
const origSelectedTracks = sf.ui.proTools.selectedTrackNames;
const firstSelectedTrack = origSelectedTracks[0];
/**
* @param {string} trackName
* @param {string[]} selectedTracks
*/
function scrollToTrackNamed(trackName, selectedTracks) {
// Open scroll to track dialog and enter track name
sf.ui.proTools.menuClick({ menuPath: ['Track', 'Scroll to Track...'] });
var confirmationDialogWin = sf.ui.proTools.confirmationDialog;
confirmationDialogWin.elementWaitFor();
confirmationDialogWin.textFields.first.elementSetTextFieldWithAreaValue({ value: trackName });
confirmationDialogWin.buttons.whoseTitle.is('OK').first.elementClick();
confirmationDialogWin.elementWaitFor({ waitType: 'Disappear' });
//Re-select originally selected tracks
sf.ui.proTools.trackSelectByName({ names: origSelectedTracks })
};
sf.wait({
intervalMs: 500,
});
//Calling command "Create and Add To Groups" from package "undefined" (installed from user/pkg/version "sp8S3ewi4RhTvy8g6wz5cBzljUJ2/ckf4cskt4000ky4101o721bfs/clcgra10y0004ms10akaklrj9")
sf.soundflow.runCommand({
commandId: 'user:ckzfaw4m90001j710060jpvnm:ckf4cv3ei000oy410dgixx1tu',
props: {
groupName: "PRG",
groupNumber: "1",
letter: "d",
disableGroupAfterCreation: true,
createVCA: false,
groupAction: "create",
}
});
sf.wait({
intervalMs: 500,
});
sf.ui.proTools.colorsSelect({
colorNumber: 01,
});
sf.ui.proTools.trackSelectByName({
names: ["Prg"],
});
sf.wait({
intervalMs: 500,
});
sf.ui.proTools.selectedTrack.groups.whoseTitle.is("VCA IO").first.buttons.first.popupMenuSelect({
menuPath: ["d - PRG"],
});
Linked from:
- Kitch Membery @Kitch2024-02-14 07:23:03.606Z
Hi @mikkeljm
Here is the way I'd create an if-else statement for this.
// Declare VCA Track name const vcaTrackName = "VCA 1"; // Declare Group name const groupName = "PRG"; // Activate Pro Tools Main Window sf.ui.proTools.appActivateMainWindow(); // Invalidate the main window incase track infromation has changed sf.ui.proTools.mainWindow.invalidate(); // Get the track by name const targetVcaTrack = sf.ui.proTools.trackGetByName({ name: vcaTrackName }).track // If there is no VCA Track throw an error if(targetVcaTrack === null) throw `Could not find the VCA track named "${vcaTrackName}"`; // Get the VCA IO button from the VCA Track const vcaIoButton = targetVcaTrack.groups.whoseTitle.is("VCA IO").first.buttons.first; // If there is no VCA IO Button throw an error if(vcaIoButton === null) throw `Could not find the VCA IO button on the VCA track named"${vcaTrackName}"` // If the VCA button value (What is shown on the button) is not the group name, scroll the track into view and assign it to the group. if (vcaIoButton.value.invalidate().value !== groupName) { targetVcaTrack.trackScrollToView(); vcaIoButton.popupMenuSelect({ // Use menu selector to select the groupName from the vcaIoButton. menuSelector: items => items.filter(item => item.path[0].split(" - ").pop() === groupName)[0], }); } else { log(`The VCA track named "${vcaTrackName}" is already assigned to the group named "${groupName}"`); }
The
else
is just there for demonstration purposes.I hope that helps.