annotate 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
rev   line source
e@0 1 #!/bin/python2
e@0 2
e@0 3 from lxml import etree
e@0 4 from sys import argv, exit
e@0 5 from time import ctime
e@0 6
e@0 7 if __name__=="__main__":
e@0 8 if len(argv) != 3:
e@0 9 print "[EE] Incorrect number of arguments"
e@0 10 print "[II] Syntax is:"
e@0 11 print " \t%s <file.ardour> <file.yaml>" % argv[0]
e@0 12 print "Where <file.ardour> is an ardour session file and"
e@0 13 print "<file.yaml> is the output .yaml file containing the session automation"
e@0 14
e@0 15 exit(-1)
e@0 16
e@0 17 doc = etree.parse(argv[1])
e@0 18
e@0 19 outfilename = argv[2]
e@0 20
e@0 21 automationdir = {}
e@0 22 timestampdir = {}
e@0 23
e@0 24 name = doc.iter("Session").next().attrib['name']
e@0 25
e@0 26 SR = int(doc.iter("Session").next().attrib['sample-rate'])
e@0 27 print "[II] Metadata:"
e@0 28 print "[II] \tName: %s" % name
e@0 29 print "[II] \tSample rate: %dHz" % SR
e@0 30 for io in doc.iter("Route"):
e@0 31 if int(io.attrib['id']) > 100:
e@0 32 ioname = io.attrib['name']
e@0 33 automationdir[ioname] = {}
e@0 34 print "[II] Track name: %s" % ioname
e@0 35 for e in io.iter("AutomationList"):
e@0 36 id = e.attrib['automation-id']
e@0 37 print "[II] \tAutomation with id: %s:" % e.attrib['automation-id']
e@0 38 children = e.getchildren()
e@0 39 for c in children:
e@0 40 if c.tag == 'events':
e@0 41 timestampdir = {}
e@0 42 listofevents = c.text.split('\n')
e@0 43 for i in listofevents:
e@0 44 if i!='':
e@0 45 ts = i.split(' ')[0]
e@0 46 v = i.split(' ')[-1]
e@0 47 # timestampdir[round(float(ts)*16000.0/44100.0)] = float(v)
e@0 48 timestampdir[ts] = float(v)
e@0 49
e@0 50 automationdir[ioname][id] = timestampdir
e@0 51
e@0 52
e@0 53 outfile = open(outfilename, 'w')
e@0 54 import yaml
e@0 55 yaml.dump(
e@0 56 {'metadata':
e@0 57 {'ardoursessionname': name,
e@0 58 'date': ctime(),
e@0 59 'sessionsamplerate': SR},
e@0 60 'automation' : automationdir},
e@0 61 outfile, default_flow_style=False)
e@0 62 outfile.close()
e@0 63 print "[II] Automation dictionary dumped to %s." % outfilename
e@0 64
e@0 65