VocalEasel/mma/util/timsplit.py

101 lines
2.3 KiB
Python
Raw Normal View History

2007-04-29 06:47:40 +00:00
#!/usr/bin/env python
2009-05-17 22:34:44 +00:00
# This program will take a mma file and use timidity to split it into
# a series of .wav files. 1 wav for each track in the file.
2007-04-29 06:47:40 +00:00
import sys, os, commands
2009-05-17 22:34:44 +00:00
tmpname = "tmp-%s" % os.getpid()
tmpmid = "%s.mid" % tmpname
bgtrack = "bg.wav"
2007-04-29 06:47:40 +00:00
def usage():
print "timsplit, (c) Bob van der Poel"
print "Create multi-track wav files using"
print " MMA files and timidity."
print
sys.exit(0)
if len(sys.argv[1:]) != 1:
print "timsplit: requires 1 filename argument."
usage()
2009-05-17 22:34:44 +00:00
mmafile = sys.argv[1]
if mmafile.endswith(".mma"):
basemid = mmafile[:-4]
else:
basemid = mmafile
basemid += ".mid"
2007-04-29 06:47:40 +00:00
2009-05-17 22:34:44 +00:00
# Create the background midi and wav. FIXME: have a command line option to skip
2007-04-29 06:47:40 +00:00
2009-05-17 22:34:44 +00:00
status, txt = commands.getstatusoutput("mma -0 %s -f %s" % (mmafile, basemid))
2007-04-29 06:47:40 +00:00
if status:
print "timsplit error", status
print txt
sys.exit(1)
2009-05-17 22:34:44 +00:00
# create a wav of the base file. This should get copied to your mixer
print "Creating background track:", bgtrack
status, txt = commands.getstatusoutput("timidity -Ow -o %s %s" % (bgtrack, basemid ))
if status:
print "timsplit error", status
print txt
sys.exit(1)
2007-04-29 06:47:40 +00:00
2009-05-17 22:34:44 +00:00
# Get the tracks generated in the file
status, txt = commands.getstatusoutput("mma -c %s" % mmafile)
txt = txt.split()
txt=txt[txt.index('assignments:')+1:]
tracklist=[]
for a in sorted(txt):
2007-04-29 06:47:40 +00:00
try:
2009-05-17 22:34:44 +00:00
int(a)
2007-04-29 06:47:40 +00:00
except:
2009-05-17 22:34:44 +00:00
tracklist.append(a)
2007-04-29 06:47:40 +00:00
2009-05-17 22:34:44 +00:00
print "MMA file '%s' being split to: " % mmafile,
for a in tracklist:
2007-04-29 06:47:40 +00:00
print a,
print
2009-05-17 22:34:44 +00:00
# Do the magic. For each track call mma and timidity.
for trackname in tracklist:
trackname = trackname.title()
status, txt = commands.getstatusoutput ("mma -0 %s -T %s -f %s " % (mmafile, trackname, tmpmid) )
if status:
2011-07-26 22:49:39 +00:00
if txt.find("No data created") >= 0:
2009-05-17 22:34:44 +00:00
print "NO DATA for '%s', skipping" % trackname
continue
2011-07-26 22:49:39 +00:00
print "timsplit error creating MIDI file:", status
2009-05-17 22:34:44 +00:00
print txt
sys.exit(1)
# create wav file
# Options for timidity: Ow -- output to wave
# M -- mono
print "Creating: %s.wav" % trackname
status, txt = commands.getstatusoutput ("timidity -OwM -o%s.wav %s" % (trackname, tmpmid) )
if status:
2011-07-26 22:49:39 +00:00
print "timsplit error running timidity:", status
2009-05-17 22:34:44 +00:00
print txt
sys.exit(1)
os.remove(tmpmid)
2007-04-29 06:47:40 +00:00