-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathloive.py
227 lines (145 loc) · 5.22 KB
/
loive.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#Loive - Interactive command line API for ableton live
import xml.etree.ElementTree as ET
import pprint
import shutil
import os.path, time
import gzip
from subprocess import call
from datetime import datetime
from colorama import init
from colorama import Fore,Back,Style
#We introduce class Loive, were everything
#always goes smoothe...
class Loive:
def __init__(self, cmands):
#Temporary, this means all string must match
#find a handler for this later,
self.args = cmands
#determine weither full path is being used or local directory
if self.args.startswith('~') | self.args.startswith('/'):
self.full_path = cmands
else:
self.full_path = os.getcwd() + '/' + cmands
self.gunzip_file()
self.setTimeDate()
self.tree = ET.parse(self.strip_string)
self.root = self.tree.getroot()
#Perform queries at initialization
self.run_query()
#Fetch local-plugin data
self.efx_local()
#Fetch external plugin data (VST, AU etc..)
self.efx_global()
#Initialize colors
init(autoreset=True)
def gunzip_file(self):
self.strip_string = self.args.split('.', 1)[0]
conversionString = self.strip_string + '.gz'
#XML-Conversion
shutil.copyfile(self.full_path, conversionString)
gzip_path = conversionString
call(["gunzip", gzip_path])
def setTimeDate(self):
modifiedTime = os.path.getmtime(self.full_path)
self.mod_time = datetime.fromtimestamp(modifiedTime).strftime("%d %b %Y %H:%M:%S")
createTime = os.path.getctime(self.full_path)
self.create_time = datetime.fromtimestamp(createTime).strftime("%d %b %Y %H:%M:%S")
def run_query(self):
self.manufact_container = {}
self.manu_list = []
self.au_list = []
#Track listing
self.track_query = self.root.findall(".//LiveSet//Tracks/")
self.track_count = len(self.track_query)
#Local plugin query
#Fetches all local Devices, Ableton effects, non vst-plugins
self.local_xml_query = ".//LiveSet//Tracks//DeviceChain//Devices[1]/*"
self.local_elems = self.root.findall(self.local_xml_query)
#Global plugin query
self.vst_xml_query = ".//LiveSet//Tracks//DeviceChain//Devices//PluginDevice//PluginDesc//VstPluginInfo//PlugName"
self.vst_elem = self.root.findall(self.vst_xml_query)
#We need special query for Au plugins
self.AU_query = ".//LiveSet//Tracks//DeviceChain//Devices//AuPluginDevice//PluginDesc//AuPluginInfo/Name"
self.AuPlugs = self.root.findall(self.AU_query)
#Might become useful
self.manuf = self.root.findall(".//LiveSet//Tracks//DeviceChain//Devices//AuPluginDevice//PluginDesc//AuPluginInfo/Manufacturer")
for m in self.manuf:
self.manu_list.append(m.attrib['Value'])
for a in self.AuPlugs:
self.au_list.append(a.attrib['Value'])
#Stores a dict with manufacturers and name value filled
self.manufacturers = dict(zip(self.au_list, self.manu_list))
def list_manufacturers(self):
ppr = pprint.PrettyPrinter(indent=1, width=20)
ppr.pprint(self.manufacturers)
def efx_local(self):
#Follow Au or Ableton devices and are useless
default_a = ['AuPluginDevice', 'PluginDevice']
self.list_values = []
self.clean_local_list = []
#Extract values
for e in self.local_elems:
self.list_values.append(e.tag)
utilStr = list(set(self.list_values))
for i in utilStr:
if i in default_a:
utilStr.remove(i)
self.clean_local_list = utilStr
return self.clean_local_list
def efx_local_print(self):
ppr = pprint.PrettyPrinter(indent=6)
ppr.pprint(self.clean_local_list)
def efx_global(self):
#Setup containers
self.vst_list = []
self.Au_list = []
self.global_ext_list = []
#Extract values
for v in self.vst_elem:
self.vst_list.append(v.attrib['Value'])
for au in self.AuPlugs:
self.Au_list.append(au.attrib['Value'])
#Remove duplicates
self.clean_vst_list = list(set(self.vst_list))
self.clean_au_list = list(set(self.Au_list))
#construct one final list
self.global_ext_list = self.clean_vst_list + self.clean_au_list
return self.global_ext_list
def efx_global_print(self):
ppr = pprint.PrettyPrinter(indent=6)
ppr.pprint(self.global_ext_list)
def getPluginInfo(self):
#Very simple, fetches local/global plugin info
#Prints it out
print(Fore.RED + 'Ableton Effects: \n')
pl = pprint.PrettyPrinter(indent=6)
pl.pprint(self.clean_local_list)
print '\n'
print(Fore.RED + 'Global Effects/VST: \n')
pe = pprint.PrettyPrinter(indent=6)
pe.pprint(self.global_ext_list)
print '\n'
def live_version(self):
#returns verison number in string format
minorVersion = '[Ableton live minor version: ' + self.root.attrib['MinorVersion'] + ']'
if len(self.root.attrib) == 2:
return minorVersion
else:
creator_str = self.root.attrib['Creator']
return creator_str
def print_live_version(self):
vers = self.live_version()
print(Fore.CYAN + vers)
def print_summary(self):
print '\n'
nameis = os.path.basename(self.full_path)
print 'Name : ' + nameis
print 'Full path : ' + self.full_path
print 'Version : ' + self.live_version()
print '\n'
print( 'Number of tracks : ' + str(self.track_count))
print '\n'
self.getPluginInfo()
print '\n'
print "last modified: %s" % self.mod_time
print "created: %s" % self.create_time