Duplicate Multiple Tracks Using A Script?
Hi There Geniuses!
I have this amazing script that y'all helped me write and it works perfectly for duplicating a single track, renaming the duplicate tracks to be numerically sequential, and bringing over the correct track attributes. Now I am hoping to figure out how to modify it for working with multiple tracks. For example, if i select the tracks "Gtr Amp" and "Gtr Room" and then run this script, currently it will make all the new tracks have the name and attributes from the first selected track. Can I make this go through and create the duplicate process for each of the selected tracks separately?
And, can the process then put these new duplicates together in the same order that the original tracks were in?
So if I created 3 duplicates of Gtr Amp and Gtr Room my track list would show
Gtr Amp 1
Gtr Room 1
Gtr Amp 2
Gtr Room 2
Gtr Amp 3
Gtr Room 3
Gtr Amp 4
Gtr Room 4
I think this should be an easy edit of this script...i tried but failed! Any help appreciated :)
var numberOfDups = Number(prompt('How many duplicates?', '1'));
var originalTrackName = sf.ui.proTools.selectedTrackNames[0];
sf.ui.proTools.trackDuplicateSelected({
duplicateActivePlaylist: false,
duplicateAlternatePlaylists: false,
duplicateAutomation: false,
duplicateGroupAssignments: true,
duplicateInserts: true,
duplicateSends: true,
insertAfterLastSelectedTrack: true,
numberOfDuplicates: numberOfDups
});
sf.ui.proTools.trackSelectByName({ names: [originalTrackName], deselectOthers: false });
sf.ui.proTools.selectedTrack.trackBulkRenameNumerical();
- samuel henriques @samuel_henriques
Hello Philip,
try this:/** * @param {number} numberOfDups * @param {AxPtTrackHeader} track */ function duplicate(numberOfDups, track) { const trackName = track.normalizedTrackName; // var originalTrackName = sf.ui.proTools.selectedTrackNames[0]; sf.ui.proTools.trackDuplicateSelected({ duplicateActivePlaylist: false, duplicateAlternatePlaylists: false, duplicateAutomation: false, duplicateGroupAssignments: true, duplicateInserts: true, duplicateSends: true, insertAfterLastSelectedTrack: true, numberOfDuplicates: numberOfDups }); sf.ui.proTools.trackSelectByName({ names: [trackName], deselectOthers: false }); sf.ui.proTools.selectedTrack.trackBulkRenameNumerical(); }; function main() { sf.ui.proTools.appActivateMainWindow(); sf.ui.proTools.invalidate(); var numberOfDups = Number(prompt('How many duplicates?', '1')); const selectedTrackHeaders = sf.ui.proTools.selectedTrackHeaders; selectedTrackHeaders.forEach(track => { track.trackSelect(); track.trackScrollToView(); duplicate(numberOfDups, track) }); //Select original tracks sf.ui.proTools.trackSelectByName({ names: selectedTrackHeaders.map(th => th.normalizedTrackName) }); }; main();
- PPhilip weinrobe @Philip_weinrobe
@samuel_henriques
this is INCREDIBLE. wow. thank you.
one last little request (i didn't realize until this worked!)
can the duplicated tracks be next to each other instead of next to their originals?for example --
Gtr DI 1
Gtr Amp 1...if duplicated twice
..would appear in my track list as:
Gtr DI 1
Gtr Amp 1
Gtr DI 2
Gtr Amp 2
Gtr DI 3
Gtr Amp 3thank you!
philipsamuel henriques @samuel_henriques
try this,
function main() { sf.ui.proTools.appActivateMainWindow(); sf.ui.proTools.invalidate(); var numberOfDups = Number(prompt('How many duplicates?', '1')); let tracksToDup = sf.ui.proTools.selectedTrackNames; sf.ui.proTools.trackDuplicateSelected({ duplicateActivePlaylist: false, duplicateAlternatePlaylists: false, duplicateAutomation: false, duplicateGroupAssignments: true, duplicateInserts: true, duplicateSends: true, insertAfterLastSelectedTrack: true, numberOfDuplicates: numberOfDups }); const dupTracks = sf.ui.proTools.invalidate().selectedTrackNames; //Rename Tracks tracksToDup.forEach(trackName => { const trackDups = dupTracks.filter(tn => tn.startsWith(trackName)) sf.ui.proTools.trackSelectByName({ names: [trackName, ...trackDups] }); sf.ui.proTools.selectedTrack.trackBulkRenameNumerical(); }); }; main();
- PPhilip weinrobe @Philip_weinrobe
dang, samuel. you a true genius.
thank you! - In reply tosamuel_henriques⬆:DDaniel Knobler @Daniel_Knobler
Hello Sam,
This is an incredibly helpful script! Would it be possible to get a version that also creates groups for each new set of tracks?
Using Phil's example, each new set of duplicates would have its own group:
Gtr DI 2 and Gtr Amp 2 grouped together
Gtr DI 3 and Gtr Amp 3 grouped together.Maybe it prompts for a group prefix name (i.e. I assign the group prefix Gtr and then it makes the group names "Gtr 2" and "Gtr 3")
Thanks so much!
samuel henriques @samuel_henriques
here you go,
function main() { sf.ui.proTools.appActivateMainWindow(); sf.ui.proTools.invalidate(); // ASk how many duplicates var numberOfDups = Number(prompt('How many duplicates?', '1')); for (let i = 0; i < numberOfDups; i++) { let tracksToDup = sf.ui.proTools.selectedTrackNames; const [inst, des, num] = tracksToDup[0].split(" ") let trackNamesToNewGroup = [] sf.ui.proTools.trackDuplicateSelected({ duplicateActivePlaylist: false, duplicateAlternatePlaylists: false, duplicateAutomation: false, duplicateGroupAssignments: false, duplicateInserts: true, duplicateSends: true, insertAfterLastSelectedTrack: true, numberOfDuplicates: 1 }); const dupTracks = sf.ui.proTools.invalidate().selectedTrackNames; if (dupTracks.length > 1) { //Create Group const groupName = inst + " " + (num ? +num + 1 : 2) sf.ui.proTools.groupsCreate({ groupName: groupName }) } //Rename Tracks tracksToDup.forEach(trackName => { const trackDups = dupTracks.filter(tn => tn.startsWith(trackName)) sf.ui.proTools.trackSelectByName({ names: [trackName, ...trackDups] }); sf.ui.proTools.selectedTrack.trackBulkRenameNumerical(); trackNamesToNewGroup.push(sf.ui.proTools.invalidate().selectedTrackNames.slice(-1)[0]) }); sf.ui.proTools.trackSelectByName({ names: trackNamesToNewGroup }); }; }; main();
- D2danielkassulke @danielkassulke
Hi @samuel_henriques this is wonderful! Just thought I'd flag that this script runs into a slight problem when creating more than one duplicate. The duplicate group name isn't incrementing, so the script gets stuck naming the 2nd group at line 45.
samuel henriques @samuel_henriques
Could you show me the track names you are using when it fails?
I'm taking the info to create the group name from the track names to duplicate, so there might be an issue there.samuel henriques @samuel_henriques
I can reproduce the line 45 error if I try to duplicate tracks where adding 1 to the name would create a track that exists, and the track group name as well. Let me thing Of a way around this.
- In reply tosamuel_henriques⬆:D2danielkassulke @danielkassulke
Hi Samuel, your initial instinct regarding track names was correct. When testing, I just named an audio track "Drums" because it was the first thing that popped into my head for the test. I guess this is only an issue when working with stems or VIs.
samuel henriques @samuel_henriques
And if you Have a few dup and then make a new dup not from the last, it will fail as well. I'll try to work on a better version that "knows" better what the group and track name should be,
- DIn reply toPhilip_weinrobe⬆:Daniel Knobler @Daniel_Knobler
Fantastic! Thank you so much.
- PPhilip weinrobe @Philip_weinrobe
the script grows even stronger.....
lol.
this is awesome.