DISCLAIMER: THIS IS PRERELEASE and very much in the prototyping/early alpha stage. Posting it here because people were interested in how this might look. As with all prerelease APIs it is subject to change.
Here's a rather complex example using new functions for reading audio file metadata and using it to spot files to certain positions in your timeline:
//Helper function to extract filename without extension from a full path
function getFileNameFromPath(path) {
return path.split('/').slice(-1)[0].split('.').slice(0, -1).join('.');
}
//Ask user to select a folder
var folderPath = sf.interaction.selectFolder({
prompt: 'Please select a folder containing WAV files'
}).path;
//Get the paths of all .wav files in the selected folder and subfolders
var filePaths = sf.file.directoryGetFiles({
path: folderPath,
searchPattern: '*.wav',
isRecursive: true,
}).paths;
//Make sure Pro Tools is active
sf.ui.proTools.appActivateMainWindow();
//Loop through all the wav files and spot them one by one
//Start spotting clips at samples 0
var spotTimeInSamples = 0;
for (var i = 0; i < filePaths.length; i++) {
sf.engine.checkForCancellation(); //When running in long loops, this makes sure we stop immediately if the user cancelled our command.
var filePath = filePaths[i];
var fileName = getFileNameFromPath(filePath);
//Go to start of session (samples 0)
sf.keyboard.press({ keys: 'enter' });
sf.ui.proTools.selectionSetInSamples({
selectionStart: 0,
selectionLength: 0,
});
//Get the file's length in samples
var fileSampleCount = sf.metadata.readFromAudioFile({
path: filePath,
}).metadata.sampleCount;
//Spot the wav file on the current track, utilizing the metadata we just collected
sf.ui.proTools.spotFile({
path: filePath,
regionName: fileName,
sourceSampleStart: 0,
sourceSampleLength: fileSampleCount,
trackSampleOffset: spotTimeInSamples,
trackVerticalOffset: 0,
});
//Increase spotTimeInSamples with the length of the file, so the next file will be placed right after this one
//Ignore the red line
spotTimeInSamples += fileSampleCount;
}
This sample requires at least 2.2.0-preview.1.9 - installer in the bottom of this post.
Note this is prerelease so in a very early stage and not ready for production.
2.2.0-preview.1.9 installer:
https://firebasestorage.googleapis.com/v0/b/soundflow-4533b.appspot.com/o/downloads%2Fsoundflow%2FSoundFlow_2.2.0-preview.1.9.pkg?alt=media&token=7e9328a3-da9b-484b-8d07-8464329e5e88
- Christian Scheuer @chrscheuer2019-01-30 04:58:04.436Z
Check this video to see it in action:
https://drive.google.com/open?id=1VmpB3SawqnSyiZP8Srx9I8IQQcIndyMVChristian Scheuer @chrscheuer2019-01-30 19:25:22.111Z
Note for anybody watching: The video is sped up for viewing convenience - the speed of spotting is slower in reality.
- In reply tochrscheuer⬆:Christian Scheuer @chrscheuer2019-01-30 19:25:40.599Z
Solution in original post