comparison experiment-reverb/code/ardourtoyaml.py @ 0:246d5546657c

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