No internet connection
  1. Home
  2. How to

How to spot multiple files using the spotFile action

By Christian Scheuer @chrscheuer2019-01-30 04:56:19.255Z2019-01-30 05:03:34.999Z

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

Solved in post #5, click to view
  • 4 replies
    1. Note for anybody watching: The video is sped up for viewing convenience - the speed of spotting is slower in reality.

    2. ?
      In reply tochrscheuer:
      @anon6770933309
        2019-01-30 13:32:24.576Z

        Very cool indeed! 👍

        1. In reply tochrscheuer:

          Solution in original post

          ReplySolution