diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/experiment-reverb/code/ardourtoyaml.py	Wed Dec 14 13:15:48 2016 +0000
@@ -0,0 +1,65 @@
+#!/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
+       
+