I'm trying to select all audio tracks currently displayed in the edit window as part of a longer script...
In a real-world context; I often need to export all audio tracks as a track bounce however when I "Show Only Audio Tracks" folder tracks will also display... deselecting these is quite time consuming and leaves room for human error.
Any ideas on this?
I barely have a starting point for this.
I've tried to modify a script from @chrscheuer on this thread: "No Input" for all Audio Tracks #post-8
Here's as far as I've managed (however it's failing on line 4):
function isAudioTrack(trackName) {
var track = sf.ui.proTools.trackGetByName({ name: trackName }).track;
return track.title.value.indexOf('Audio Track') >= 0;
}
function getTrackWidth(trackName) {
var track = sf.ui.proTools.trackGetByName({ name: trackName }).track;
var width = track.groups.whoseTitle.is('Audio IO').first.sliders.whoseTitle.contains('Pan').count;
return width;
}
function showAllTracks() {
sf.ui.proTools.mainWindow.trackListPopupButton.popupMenuSelect({
menuPath: ["Show Only","Audio Tracks"]
});
sf.ui.proTools.mainWindow.invalidate();
}
function setTrackHeightForAllTracks(size) {
var track = sf.ui.proTools.visibleTrackHeaders[0];
track.trackScrollToView();
track.trackSelect();
var f = track.frame;
var popupMenu = track.popupMenuOpenFromElement({
relativePosition: { x: f.w - 10, y: 5 },
isOption: true,
}).popupMenu;
popupMenu.menuClickPopupMenu({
menuPath: [size]
});
}
function selectAllAudioTracksOfWidth(width) {
var names = sf.ui.proTools.trackNames.filter(isAudioTrack).filter(t => getTrackWidth(t) === width);
if (names.length === 0) return;
sf.ui.proTools.trackGetByName({ name: names[0] }).track.trackScrollToView();
sf.ui.proTools.trackSelectByName({
names: names,
deselectOthers: true
});
}
function main() {
sf.ui.proTools.appActivateMainWindow();
//Make sure all tracks are shown
showAllTracks();
//Make sure all tracks are medium sized so we can read if they're mono or stereo
setTrackHeightForAllTracks('medium');
//Select all mono->mono tracks and set their input
selectAllAudioTracksOfWidth(0);
//Select all mono->X tracks and set their input
selectAllAudioTracksOfWidth(1);
//Select all stereo->X tracks and set their input
selectAllAudioTracksOfWidth(2);
}
main();
Many thanks in advance!
- Christian Scheuer @chrscheuer2021-12-01 17:44:21.034Z
What's the error you're seeing?
- BBen Farestvedt @Ben_Farestvedt
Hey Christian!
Here's the log:
01.12.2021 17:47:12.24 [Backend]: !! Command Error: Select All Audio Tracks [user:ckuznqq7k0006di10snl2qmmd:ckwnoh6h40001gw10ua50aj5k]:
TypeError: Cannot read property 'title' of null
(Select All Audio Tracks line 4)As far as I can see; it's getting as far as selecting "Show Audio Tracks Only" and setting the track size to medium before throwing this up.
Christian Scheuer @chrscheuer2021-12-01 17:53:30.481Z
Ah yea the issue comes from showing audio tracks only first and the fact that this line tries to enumerate through all tracks not just visible tracks:
var names = sf.ui.proTools.trackNames.filter(isAudioTrack).filter(t => getTrackWidth(t) === width);
Christian Scheuer @chrscheuer2021-12-01 17:57:01.124Z
Try something like this (fully untested as I don't have PT on my laptop):
/** * @param {AxPtTrackHeader} track */ function isAudioTrack(track) { return track.title.value.indexOf('Audio Track') >= 0; } function showOnlyAudioTracks() { sf.ui.proTools.mainWindow.trackListPopupButton.popupMenuSelect({ menuPath: ["Show Only", "Audio Tracks"] }); sf.ui.proTools.mainWindow.invalidate(); } function selectAllAudioTracks() { var tracksToSelect = sf.ui.proTools.visibleTrackHeaders.filter(isAudioTrack); sf.ui.proTools.trackSelectByName({ names: tracksToSelect.map(t => t.normalizedTrackName), deselectOthers: true, }); } function main() { sf.ui.proTools.appActivateMainWindow(); //Make sure only audio tracks are shown showOnlyAudioTracks(); //Select all audio tracks selectAllAudioTracks(); } main();
- BBen Farestvedt @Ben_Farestvedt
Whoa! Holy **** @chrscheuer - that's seemless... and works really fast too!
Thankyou so much! I think you just bought me a day p/week with my family!
Christian Scheuer @chrscheuer2021-12-01 18:35:01.553Z
Wohooo!! Nice, happy to hear that :)