Timeline: Update syntax of impor-ardour-session script to work with python3.

pull/122/head
Jonathan Moore Liles 2014-05-04 13:22:32 -07:00
parent 5b0d6e6bd1
commit 467e369cd1
1 changed files with 28 additions and 28 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python2
# Copyright (C) 2013 Jonathan Moore Liles # # Copyright (C) 2013 Jonathan Moore Liles #
# # # #
@ -24,7 +24,7 @@ from datetime import date
import shutil import shutil
if len(sys.argv) == 1: if len(sys.argv) == 1:
print "Usage: import-ardour-session [PATH_TO_ARDOUR_FILE] [NAME_OF_NON_TIMELINE_PROJECT]" print( "Usage: import-ardour-session [PATH_TO_ARDOUR_FILE] [NAME_OF_NON_TIMELINE_PROJECT]" )
sys.exit( 1 ) sys.exit( 1 )
Overwrite=False Overwrite=False
@ -45,13 +45,13 @@ try:
os.makedirs( NonTimelineProjectPath + "/sources"); os.makedirs( NonTimelineProjectPath + "/sources");
except: except:
if not Overwrite: if not Overwrite:
print "Output path already exists!" print( "Output path already exists!" )
sys.exit( 1 ) sys.exit( 1 )
try: try:
tree = et.parse( ArdourFilePath ); tree = et.parse( ArdourFilePath );
except: except:
print "Invalid XML input" print( "Invalid XML input" )
sys.exit( 1 ) sys.exit( 1 )
root = tree.getroot(); root = tree.getroot();
@ -59,39 +59,39 @@ root = tree.getroot();
Sources = {} Sources = {}
DiskStreams = {} DiskStreams = {}
print "Gathering session info" print( "Gathering session info" )
if root.tag != "Session": if root.tag != "Session":
print "Not an Ardour session?" print( "Not an Ardour session?" )
sys.exit(1) sys.exit(1)
print "Ardour session file version is " + root.attrib["version"] print( "Ardour session file version is " + root.attrib["version"] )
print "This program is known to work with versions <= 3.0.1" print( "This program is known to work with versions <= 3.0.1" )
ProjectName = root.attrib["name"] ProjectName = root.attrib["name"]
print "Converting Ardour session \"" + ProjectName + "\" to Non Timeline format. Please be patient." print( "Converting Ardour session \"" + ProjectName + "\" to Non Timeline format. Please be patient." )
print "Gathering sources." print( "Gathering sources." )
for node in root.findall( "./Sources/Source" ): for node in root.findall( "./Sources/Source" ):
Sources[node.attrib["id"]] = node; Sources[node.attrib["id"]] = node;
# print "\tFound source " + node.attrib["name"] # print( "\tFound source " + node.attrib["name"] )
print "Gathering version 3 diskstreams." print( "Gathering version 3 diskstreams." )
for node in root.findall( "./Routes/Route/Diskstream" ): for node in root.findall( "./Routes/Route/Diskstream" ):
DiskStreams[node.attrib["id"]] = node; DiskStreams[node.attrib["id"]] = node;
print "\tFound diskstream " + node.attrib["name"]; print( "\tFound diskstream " + node.attrib["name"] )
print "Gathering version 2 diskstreams." print( "Gathering version 2 diskstreams." )
for node in root.findall( "./DiskStreams/AudioDiskstream" ): for node in root.findall( "./DiskStreams/AudioDiskstream" ):
DiskStreams[node.attrib["id"]] = node; DiskStreams[node.attrib["id"]] = node;
# print "\tFound diskstream " + node.attrib["name"]; # print( "\tFound diskstream " + node.attrib["name"]; )
print "Gathering version 1 diskstreams." print( "Gathering version 1 diskstreams." )
for node in root.findall( "./DiskStreams/DiskStream" ): for node in root.findall( "./DiskStreams/DiskStream" ):
DiskStreams[node.attrib["id"]] = node; DiskStreams[node.attrib["id"]] = node;
# print "\tFound diskstream " + node.attrib["name"]; # print( "\tFound diskstream " + node.attrib["name"]; )
LoggableID = 1; LoggableID = 1;
@ -104,7 +104,7 @@ def NewID():
History = "{\n" History = "{\n"
print "Processing tempo." print( "Processing tempo." )
for node in root.findall("./TempoMap/Tempo"): for node in root.findall("./TempoMap/Tempo"):
TempoID = NewID() TempoID = NewID()
@ -120,7 +120,7 @@ for node in root.findall("./TempoMap/Meter"):
History += ( "\tTime_Point " + TimeID + " create :start 0 :beats_per_bar " + BPB + " :beat_type " + node.attrib["note-type"] + "\n") History += ( "\tTime_Point " + TimeID + " create :start 0 :beats_per_bar " + BPB + " :beat_type " + node.attrib["note-type"] + "\n")
print "Processing playlists." print( "Processing playlists." )
for node in root.findall( "./Playlists/Playlist" ): for node in root.findall( "./Playlists/Playlist" ):
try: try:
@ -129,12 +129,12 @@ for node in root.findall( "./Playlists/Playlist" ):
try: try:
Track = DiskStreams[node.attrib["orig-track-id"]] Track = DiskStreams[node.attrib["orig-track-id"]]
except: except:
print "\tSkipping playlist " + node.attrib["name"] + " for unknown diskstream" print( "\tSkipping playlist " + node.attrib["name"] + " for unknown diskstream" )
continue continue
if node.attrib["name"] == Track.attrib["playlist"]: if node.attrib["name"] == Track.attrib["playlist"]:
print "\tFound playlist " + node.attrib["name"] print( "\tFound playlist " + node.attrib["name"] )
# for chan in range(0, int( Track.attrib["channels"] )): # for chan in range(0, int( Track.attrib["channels"] )):
TrackID = NewID() TrackID = NewID()
@ -164,7 +164,7 @@ for node in root.findall( "./Playlists/Playlist" ):
elif os.path.exists( APath2 + SourceName ): elif os.path.exists( APath2 + SourceName ):
SourceName = APath2 + SourceName SourceName = APath2 + SourceName
else: else:
print "source not found!" print( "source not found!" )
SourceList.append( "'" + SourceName + "'" ); SourceList.append( "'" + SourceName + "'" );
@ -174,13 +174,13 @@ for node in root.findall( "./Playlists/Playlist" ):
OutputName = NonTimelineProjectPath + "/sources/" + SourceName OutputName = NonTimelineProjectPath + "/sources/" + SourceName
if not os.path.exists( OutputName ): if not os.path.exists( OutputName ):
print "Combining multifile source into multichannel source" print( "Combining multifile source into multichannel source" )
os.system( "sox -S -M " + " ".join(SourceList) + " " + "'" + OutputName + "'" ) os.system( "sox -S -M " + " ".join(SourceList) + " " + "'" + OutputName + "'" )
else: else:
SourceName = Sources[n2.attrib["source-0"]].attrib["name"]; SourceName = Sources[n2.attrib["source-0"]].attrib["name"];
if not os.path.exists( NonTimelineProjectPath + "/sources/" + SourceName ): if not os.path.exists( NonTimelineProjectPath + "/sources/" + SourceName ):
print "\t\tCopying source: " + SourceName; print( "\t\tCopying source: " + SourceName )
try: try:
shutil.copy( os.path.dirname(ArdourFilePath) + "/interchange/" + ProjectName + "/audiofiles/" + SourceName, shutil.copy( os.path.dirname(ArdourFilePath) + "/interchange/" + ProjectName + "/audiofiles/" + SourceName,
@ -197,17 +197,17 @@ for node in root.findall( "./Playlists/Playlist" ):
" :offset " + n2.attrib["start"] + " :offset " + n2.attrib["start"] +
" :sequence " + SequenceID + "\n") " :sequence " + SequenceID + "\n")
else: else:
print "\tSkipping inactive playlist" print( "\tSkipping inactive playlist" )
History += ("}\n") History += ("}\n")
print "Comitting to disk." print( "Comitting to disk." )
with open( NonTimelineProjectPath + "/info", 'w' ) as InfoFile: with open( NonTimelineProjectPath + "/info", 'w' ) as InfoFile:
try: try:
SampleRate = root.attrib["sample-rate"] SampleRate = root.attrib["sample-rate"]
except: except:
print "Couldn't find sample rate... Using default." print( "Couldn't find sample rate... Using default." )
SampleRate = "48000" SampleRate = "48000"
InfoFile.write( "created by\n\tNon-Timeline 1.2.0\ncreated on\n\t" + date.today().ctime() + "\nversion\n\t2\nsample rate\n\t" + SampleRate + "\n" ) InfoFile.write( "created by\n\tNon-Timeline 1.2.0\ncreated on\n\t" + date.today().ctime() + "\nversion\n\t2\nsample rate\n\t" + SampleRate + "\n" )
@ -215,5 +215,5 @@ with open( NonTimelineProjectPath + "/info", 'w' ) as InfoFile:
with open( NonTimelineProjectPath + "/history", 'w' ) as HistoryFile: with open( NonTimelineProjectPath + "/history", 'w' ) as HistoryFile:
HistoryFile.write( History ) HistoryFile.write( History )
print "Done. You've been freed. Go make music!" print( "Done. You've been freed. Go make music!" )