Mercurial > hg > chourdakisreiss2016
view experiment-reverb/code/ardourtoyaml.py @ 2:c87a9505f294 tip
Added LICENSE for code, removed .wav files
author | Emmanouil Theofanis Chourdakis <e.t.chourdakis@qmul.ac.uk> |
---|---|
date | Sat, 30 Sep 2017 13:25:50 +0100 |
parents | 246d5546657c |
children |
line wrap: on
line source
#!/bin/python2 from lxml import etree from sys import argv, exit from time import ctime if __name__=="__main__": if len(argv) != 3: print "[EE] Incorrect number of arguments" print "[II] Syntax is:" print " \t%s <file.ardour> <file.yaml>" % argv[0] print "Where <file.ardour> is an ardour session file and" print "<file.yaml> is the output .yaml file containing the session automation" exit(-1) doc = etree.parse(argv[1]) outfilename = argv[2] automationdir = {} timestampdir = {} name = doc.iter("Session").next().attrib['name'] SR = int(doc.iter("Session").next().attrib['sample-rate']) print "[II] Metadata:" print "[II] \tName: %s" % name print "[II] \tSample rate: %dHz" % SR for io in doc.iter("Route"): if int(io.attrib['id']) > 100: ioname = io.attrib['name'] automationdir[ioname] = {} print "[II] Track name: %s" % ioname for e in io.iter("AutomationList"): id = e.attrib['automation-id'] print "[II] \tAutomation with id: %s:" % e.attrib['automation-id'] children = e.getchildren() for c in children: if c.tag == 'events': timestampdir = {} listofevents = c.text.split('\n') for i in listofevents: if i!='': ts = i.split(' ')[0] v = i.split(' ')[-1] # timestampdir[round(float(ts)*16000.0/44100.0)] = float(v) timestampdir[ts] = float(v) automationdir[ioname][id] = timestampdir outfile = open(outfilename, 'w') import yaml yaml.dump( {'metadata': {'ardoursessionname': name, 'date': ctime(), 'sessionsamplerate': SR}, 'automation' : automationdir}, outfile, default_flow_style=False) outfile.close() print "[II] Automation dictionary dumped to %s." % outfilename