====== create a specimen (sampler) file from wave files ====== \\ NOTE: there was a similar script by Florian Schmidt, but it disappeared. [[http://tapas.affenbande.org/wordpress/?page_id=33| DEAD_LINK]] Does anyone still have it? \\ ===== dir2beef - by Atte André Jensen ===== \\ found at lau-ml, 25. April 2008 15:35 # how to use: # put it in yout path and type the following in a terminal: dir2beef --help \\ #!/usr/bin/env python # -*- coding: latin-1 -*- import os, optparse, sys, os.path, wave parser = optparse.OptionParser() if '-?' in sys.argv: sys.argv.remove('-?') sys.argv.append('-h') parser.add_option('-d','--directory-containing-wavs', dest="wavDir", default='.') parser.add_option('-l','--lowest-note-of-mapping', dest="startNote", default='36') parser.add_option('-f','--force-overwrite', action="store_true", dest="forceOverwrite", default=False) parser.add_option('-s','--stdout', action="store_true", dest="stdOut", default=False) parser.add_option('-o','--outfile', dest="outFile") (options, args) = parser.parse_args() def getDir(dir): result = [] import os.path path = os.path.abspath(dir) + '/' list = os.listdir(dir) for file in list: (root, ext) = os.path.splitext(file) if os.path.isfile(path + file) and ext in ['.wav','.WAV']: result.append(path + file) return result header = """ """ patch = """ %s %s 0 %s 1,000000 0,000000 5 0 0 0 %s %s 0 %s 0 %s 1,000000 0,000000 0,000000 2 no 0,050000 no no 0,000000 no 0,000000 0,000000 1,000000 0,000000 0,000000 0,000000 0,000000 no 1,000000 0,000000 0,000000 1,000000 1,000000 no no no sine 0,000000 no 0,000000 0,000000 1,000000 0,000000 0,000000 0,000000 0,000000 no 0,000000 0,000000 0,000000 1,000000 1,000000 no no no sine 0,000000 no 0,000000 0,000000 1,000000 0,000000 0,000000 0,000000 0,000000 no 0,000000 0,000000 0,000000 1,000000 1,000000 no no no sine 0,000000 no 0,000000 0,000000 1,000000 0,000000 0,000000 0,000000 0,000000 no 0,000000 0,000000 0,000000 1,000000 1,000000 no no no sine 0,000000 no 0,000000 0,000000 1,000000 0,000000 0,000000 0,000000 0,000000 no 0,000000 0,000000 0,000000 1,000000 1,000000 no no no sine """ footer = "" # --- the action ---- output = [] output.append(header) note = int(options.startNote) for file in getDir(options.wavDir): (head, tail) = os.path.split(file) (basename, ext) = os.path.splitext(tail) wav = wave.open(file) end = wav.getnframes() -1 values = (basename,file,note, note, note, end, end) output.append(patch % values) note = note + 1 output.append(footer) if options.stdOut == True: print '\n'.join(output) sys.exit() if not options.outFile: options.outFile = options.wavDir.strip('/').split('/')[-1:][0] + '.beef' if not os.path.exists(options.outFile) or options.forceOverwrite: FILE = open(options.outFile,"w") for line in output: FILE.write(line) else: print 'outfile "' + options.outFile + '" exists, use -f to force overwrite'