Skip to content

Instantly share code, notes, and snippets.

@tastycode
Created May 24, 2020 00:25
Show Gist options
  • Save tastycode/e651d27612db0ff823b6df35f0479f8c to your computer and use it in GitHub Desktop.
Save tastycode/e651d27612db0ff823b6df35f0479f8c to your computer and use it in GitHub Desktop.
Find unused recordings in ableton live sets
// usage "node index.js /path/to/your/project.als"
const path = require('path')
const fs = require('fs')
const Ableton = require('ableton') //https://github.com/CocoFox/ableton
const [_,__,projectPath] = process.argv
const project = new Ableton(projectPath)
const main = async () => {
const $ = await new Promise((resolve, reject) => {
project.read((error, $) => {
if (error) {
reject(error)
} else {
resolve($)
}
})
})
const samplePaths = $('SampleRef FileRef').toArray().filter(sample => {
const findResult = $(sample).find('RelativePathElement').toArray()
const recordedResults = findResult.find( pathElement => {
return pathElement.attribs.dir == 'Recorded'
})
return recordedResults
}).map( sample => {
const nameResult = $(sample).find(`name[value$="aif"]`)
return nameResult.attr('value')
})
const usedSamples = [...new Set(samplePaths)]
const parentDir = path.dirname(projectPath)
const recordedPath = path.join(parentDir, 'Samples', 'Recorded')
const recordedFiles = fs.readdirSync(recordedPath).filter(file => /aif$/.test(file))
const orphans = recordedFiles.filter(file => !usedSamples.includes(file))
console.log({orphans})
}
main()
function execShellCommand(cmd) {
const exec = require('child_process').exec
return new Promise((resolve) => {
exec(cmd, (error, stdout, stderr) => {
if (error) {
console.warn(error)
}
resolve(stdout ? stdout : stderr)
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment