Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
7.0KB

  1. #!/usr/bin/env python
  2. # Copyright (C) 2013 Jonathan Moore Liles #
  3. # #
  4. # This program is free software; you can redistribute it and/or modify it #
  5. # under the terms of the GNU General Public License as published by the #
  6. # Free Software Foundation; either version 2 of the License, or (at your #
  7. # option) any later version. #
  8. # #
  9. # This program is distributed in the hope that it will be useful, but WITHOUT #
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
  11. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
  12. # more details. #
  13. # #
  14. # You should have received a copy of the GNU General Public License along #
  15. # with This program; see the file COPYING. If not,write to the Free Software #
  16. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
  17. import xml.etree.ElementTree as et
  18. import random
  19. import sys
  20. import os
  21. from datetime import date
  22. import shutil
  23. if len(sys.argv) != 3:
  24. print "Usage: import-ardour-session [PATH_TO_ARDOUR_FILE] [NAME_OF_NON_TIMELINE_PROJECT]"
  25. sys.exit( 1 )
  26. ArdourFilePath = sys.argv[1];
  27. NonTimelineProjectPath = sys.argv[2];
  28. try:
  29. os.makedirs( NonTimelineProjectPath );
  30. os.makedirs( NonTimelineProjectPath + "/sources");
  31. except:
  32. print "Output path already exists"
  33. sys.exit( 1 )
  34. History = open( NonTimelineProjectPath + "/history", 'w' );
  35. try:
  36. tree = et.parse( ArdourFilePath );
  37. except:
  38. print "Invalid XML input"
  39. sys.exit( 1 )
  40. root = tree.getroot();
  41. Sources = {}
  42. DiskStreams = {}
  43. print "Gathering session info"
  44. if root.tag != "Session":
  45. print "Not an Ardour session?"
  46. sys.exit(1)
  47. print "Ardour session file version is " + root.attrib["version"]
  48. print "This program is known to work with versions <= 3.0.1"
  49. ProjectName = root.attrib["name"]
  50. print "Converting Ardour session \"" + ProjectName + "\" to Non Timeline format. Please be patient."
  51. Info = open( NonTimelineProjectPath + "/info", 'w' )
  52. try:
  53. SampleRate = root.attrib["sample-rate"]
  54. except:
  55. print "Couldn't find sample rate... Using default."
  56. SampleRate = "48000"
  57. Info.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" )
  58. print "Gathering sources."
  59. for node in root.findall( "./Sources/Source" ):
  60. Sources[node.attrib["id"]] = node;
  61. # print "\tFound source " + node.attrib["name"]
  62. print "Gathering version 3 diskstreams."
  63. for node in root.findall( "./Routes/Route/Diskstream" ):
  64. DiskStreams[node.attrib["id"]] = node;
  65. print "\tFound diskstream " + node.attrib["name"];
  66. print "Gathering version 2 diskstreams."
  67. for node in root.findall( "./DiskStreams/AudioDiskstream" ):
  68. DiskStreams[node.attrib["id"]] = node;
  69. # print "\tFound diskstream " + node.attrib["name"];
  70. print "Gathering version 1 diskstreams."
  71. for node in root.findall( "./DiskStreams/DiskStream" ):
  72. DiskStreams[node.attrib["id"]] = node;
  73. # print "\tFound diskstream " + node.attrib["name"];
  74. LoggableID = 1;
  75. def NewID():
  76. global LoggableID
  77. ID="0x%x" % LoggableID
  78. LoggableID = LoggableID + 1
  79. return ID
  80. print "Processing tempo."
  81. for node in root.findall("./TempoMap/Tempo"):
  82. TempoID = NewID()
  83. History.write( "Tempo_Point " + TempoID + " create :start 0 :tempo " + node.attrib["beats-per-minute"] + "\n")
  84. for node in root.findall("./TempoMap/Meter"):
  85. TimeID = NewID()
  86. try:
  87. BPB = node.attrib["beats-per-bar"]
  88. except:
  89. BPB = node.attrib["divisions-per-bar"]
  90. History.write( "Time_Point " + TimeID + " create :start 0 :beats_per_bar " + BPB + " :beat_type " + node.attrib["note-type"] + "\n")
  91. print "Processing playlists."
  92. for node in root.findall( "./Playlists/Playlist" ):
  93. try:
  94. Track = DiskStreams[node.attrib["orig_diskstream_id"]]
  95. except:
  96. try:
  97. Track = DiskStreams[node.attrib["orig-track-id"]]
  98. except:
  99. print "\tSkipping playlist " + node.attrib["name"] + " for unknown diskstream"
  100. continue
  101. if node.attrib["name"] == Track.attrib["playlist"]:
  102. print "\tFound playlist " + node.attrib["name"]
  103. for chan in range(0, int( Track.attrib["channels"] )):
  104. TrackID = NewID()
  105. SequenceID = NewID()
  106. if int(Track.attrib["channels"]) > 1:
  107. TrackName = Track.attrib["name"] + "-" + ( "%i" % chan )
  108. else:
  109. TrackName = Track.attrib["name"]
  110. History.write( "Track " + TrackID + " create :name \"" + TrackName + "\"" + ( " :sequence " + SequenceID ) + " :color " + ( "%i" % random.randint(256,123123123)) + " :inputs 1 :outputs 1\n" )
  111. History.write( "Audio_Sequence " + SequenceID + " create :track " + TrackID + " :name \"" + node.attrib["name"] + "\"\n" )
  112. for n2 in node.findall("./Region"):
  113. RegionID = NewID();
  114. SourceName = Sources[n2.attrib["source-" + ( "%i" % chan )]].attrib["name"];
  115. if not os.path.exists( NonTimelineProjectPath + "/sources/" + SourceName ):
  116. print "\t\tCopying source: " + SourceName;
  117. try:
  118. shutil.copy( os.path.dirname(ArdourFilePath) + "/interchange/" + ProjectName + "/audiofiles/" + SourceName,
  119. NonTimelineProjectPath + "/sources/" )
  120. except:
  121. shutil.copy( os.path.dirname(ArdourFilePath) + "/sounds/" + SourceName,
  122. NonTimelineProjectPath + "/sources/" )
  123. History.write ("Audio_Region " + RegionID +
  124. " create :source \"" + Sources[n2.attrib["source-" + ( "%i" % chan )]].attrib["name"] +
  125. "\" :start " + n2.attrib["position"] +
  126. " :length " + n2.attrib["length"] +
  127. " :offset " + n2.attrib["start"] +
  128. " :sequence " + SequenceID + "\n")
  129. else:
  130. print "\tSkipping inactive playlist"
  131. print "Done. You've been freed. Go make music!"