Select all member tracks of a folder track?
Is it possible to select all member tracks of a given folder through Soundflow? In my case, I'd like to unmute all member tracks in a folder. Thought I'd set the first action as selecting those folders.
Christian Scheuer @chrscheuer2021-10-31 00:58:24.608ZHi Cooper,
It should be possible to build something out of this code:
How to select specific type of tracks inside a folder #post-9What should happen to sub folders that are part of the folder?
Christian Scheuer @chrscheuer2021-10-31 01:00:52.778Z2021-10-31 16:05:15.317ZThis for example should mute all audio tracks in the selected folder:
/** * @param {AxPtTrackHeader} track */ function getTrackDepth(track) { return Math.floor((track.titleButton.frame.x - track.frame.x) / 15); } function getTrackFolderStructure() { var root = { children: [] }; var stack = []; stack[0] = root; var flatList = sf.ui.proTools.visibleTrackHeaders.map(t => ({ track: t, depth: getTrackDepth(t) })); for (var i = 0; i < flatList.length; i++) { var flatItem = flatList[i]; var node = { name: flatItem.track.normalizedTrackName, type: flatItem.track.title.value.match(/ - (.*)$/)[1].trim().replace(/track$/i, '').trim().toLowerCase(), track: flatItem.track, children: [] }; stack[flatItem.depth] = node; stack[flatItem.depth - 1].children.push(node); } return root; } function findNearestParentFolder(root, trackName) { var folderStack = []; function walk(node) { var isFolder = node.type && node.type.indexOf('folder') >= 0; if (isFolder) { folderStack.push(node); } if (node.name === trackName) { return folderStack.slice(-1)[0]; } for (var i = 0; i < node.children.length; i++) { var res = walk(node.children[i]); if (res) return res; } if (isFolder) { folderStack.pop(); } } return walk(root); } /** * @return {AxPtTrackHeader[]} */ function getTracksInCurrentFolderOfType(trackType) { sf.ui.proTools.mainWindow.invalidate(); var root = getTrackFolderStructure(); var nearestFolder = findNearestParentFolder(root, sf.ui.proTools.selectedTrack.normalizedTrackName); if (!nearestFolder) return []; return nearestFolder.children.filter(i => i.type === trackType).map(i => i.track); } function muteAudioTracksInCurrentFolder() { for(let track of getTracksInCurrentFolderOfType('audio')) { track.trackSetMute({ targetValue: 'Enable', }); } } muteAudioTracksInCurrentFolder();Note I haven't tested this so it's very possible it doesn't fully work.
- CCooper Babbes @cooper
Thanks for giving this a try! It's unfortunately not doing anything on my end. I checked that other post and tried some stuff, but I can't seem to get anything to work.
I think in the case of subfolders, whichever is the simpler & quicker execution, either:
- It could mute the subfolder track itself (if it's a routing folder), and leave the tracks within the subfolder alone.
- It could ignore track types and just mute all visible tracks within the specified folder track, including subfolders and the subfolders' member tracks.
I did figure out another solution that's working alright for now, which is exploiting a naming convention I have for member tracks in this instance, using regular expressions. I found this code you wrote elsewhere on the forum:
function selectTracksByNameWithWildcard(trackNames = []) { function matchWildcard(str, rule) { var escapeRegex = (str) => str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); return new RegExp("^" + rule.split("*").map(escapeRegex).join(".*") + "$", "i").test(str); } var allNames = sf.ui.proTools.trackNames; var namesToSelect = allNames.filter(n => trackNames.some(tn => matchWildcard(n, tn))); sf.ui.proTools.trackSelectByName({ names: namesToSelect, deselectOthers: true, }); } selectTracksByNameWithWildcard([ '* A - *' ]); - In reply tochrscheuer⬆:
Yujiro Yonetsu @Yujiro_YonetsuHello @chrscheuer !
I take advantage of this script and incorporate it into my own scripts.
But clearly there is one problem.
If you have a track inside a folder named
EG_TBR - ReaLPC
this will not work. It works fine in other cases, but for some reason this is the only one that does not work.Apparently it doesn't work when there is " - " (space - space)
Is there a solution to this?
Please help me