-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbletonMAExport.py
67 lines (47 loc) · 1.69 KB
/
AbletonMAExport.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import csv
import gzip
import sys
import os
from lxml import objectify
def bartominute(s: str, tempo: int) -> str:
a = float(s)
speed = 1 / (tempo / 60)
time = a * speed
frames = round(time * 30)
seconds = frames // 30
frames -= seconds * 30
minutes = seconds // 60
seconds -= minutes * 60
hours = minutes // 60
minutes -= hours * 60
return str(hours) + ":" + str(minutes).zfill(2) + ":" +\
str(seconds).zfill(2) + ":" + str(frames).zfill(2)
def takesecond(elem):
return float(elem[1])
with gzip.open(sys.argv[1], "rt") as file, open(sys.argv[1][:-4] + ".xml",
"w") as outfile:
projectFile = file.read()
outfile.write(projectFile)
with open(sys.argv[1][:-4] + ".xml", "rb") as file:
contents = file.read()
root = objectify.fromstring(contents)
attrib = root.attrib
locator = root.LiveSet.Locators.Locators
array = []
for child in locator.getchildren():
helperArray = ["", ""]
for e in child.getchildren():
if e.tag == "Name":
helperArray[0] = e.attrib["Value"].replace(" ", "")
elif e.tag == "Time":
helperArray[1] = e.attrib["Value"].replace(" ", "")
array.append(helperArray)
tempo = float(
root.LiveSet.MasterTrack.DeviceChain.Mixer.Tempo.Manual.attrib["Value"])
array.sort(key=takesecond)
with open(sys.argv[1][:-4] + ".csv", "w", newline='') as exportFile:
writer = csv.writer(exportFile, delimiter=',')
writer.writerow(["#", "Name", "Start", "End", "Length"])
for i, e in enumerate(array):
writer.writerow(["M" + str(i), e[0], bartominute(e[1], tempo), "", ""])
os.remove(sys.argv[1][:-4] + ".xml")