e@0: #!/bin/python2 e@0: e@0: from lxml import etree e@0: from sys import argv, exit e@0: from time import ctime e@0: e@0: if __name__=="__main__": e@0: if len(argv) != 3: e@0: print "[EE] Incorrect number of arguments" e@0: print "[II] Syntax is:" e@0: print " \t%s " % argv[0] e@0: print "Where is an ardour session file and" e@0: print " is the output .yaml file containing the session automation" e@0: e@0: exit(-1) e@0: e@0: doc = etree.parse(argv[1]) e@0: e@0: outfilename = argv[2] e@0: e@0: automationdir = {} e@0: timestampdir = {} e@0: e@0: name = doc.iter("Session").next().attrib['name'] e@0: e@0: SR = int(doc.iter("Session").next().attrib['sample-rate']) e@0: print "[II] Metadata:" e@0: print "[II] \tName: %s" % name e@0: print "[II] \tSample rate: %dHz" % SR e@0: for io in doc.iter("Route"): e@0: if int(io.attrib['id']) > 100: e@0: ioname = io.attrib['name'] e@0: automationdir[ioname] = {} e@0: print "[II] Track name: %s" % ioname e@0: for e in io.iter("AutomationList"): e@0: id = e.attrib['automation-id'] e@0: print "[II] \tAutomation with id: %s:" % e.attrib['automation-id'] e@0: children = e.getchildren() e@0: for c in children: e@0: if c.tag == 'events': e@0: timestampdir = {} e@0: listofevents = c.text.split('\n') e@0: for i in listofevents: e@0: if i!='': e@0: ts = i.split(' ')[0] e@0: v = i.split(' ')[-1] e@0: # timestampdir[round(float(ts)*16000.0/44100.0)] = float(v) e@0: timestampdir[ts] = float(v) e@0: e@0: automationdir[ioname][id] = timestampdir e@0: e@0: e@0: outfile = open(outfilename, 'w') e@0: import yaml e@0: yaml.dump( e@0: {'metadata': e@0: {'ardoursessionname': name, e@0: 'date': ctime(), e@0: 'sessionsamplerate': SR}, e@0: 'automation' : automationdir}, e@0: outfile, default_flow_style=False) e@0: outfile.close() e@0: print "[II] Automation dictionary dumped to %s." % outfilename e@0: e@0: