-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReaperTimecodeExport.py
281 lines (238 loc) · 8.45 KB
/
ReaperTimecodeExport.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
"""
A simple (and shitty) script to read a Reaper created .csv file and convert
it to a macro and a timecode sheet.
Author: 12xx12 - [email protected]
dependency lxml: pip install lxml
"""
import csv
import os
import sys
from datetime import datetime
from lxml import etree as xml
def minutesToFrames(time: str):
"""
converts the time given in HH:MM::SS:Frames to a time in Frames
:param time: string to convert
:return: the time og the string in frames
"""
times = time.split(":")
res = 0
for k, timeUnit in enumerate(times):
if k == 0:
res += int(timeUnit) * 30 * 60 * 60
elif k == 1:
res += int(timeUnit) * 30 * 60
elif k == 2:
res += int(timeUnit) * 30
elif k == 3:
res += int(timeUnit)
return str(res)
if len(sys.argv) < 2 or len(sys.argv) > 3:
print("Usage: ReaperTimecodeExport [your exported file.csv]")
exit(-1)
autoStart = True # enable autostart for the exec
# asks the user for input values
while True:
data = input("Number of the sequence to use: ")
if not data.isnumeric():
print("input is not a number")
else:
sequenceNumber = int(data)
break
while True:
data = input("Number of the Page to assign the exec to: ")
if not data.isnumeric():
print("input is not a number")
else:
pageNumber = int(data)
break
while True:
data = input("Number of the exec to assgin to: ")
if not data.isnumeric():
print("input is not a number")
else:
execNumber = int(data)
break
while True:
data = input("Number of the sequence to use: ")
if not data.isnumeric():
print("input is not a number")
else:
fadeTime = int(data)
break
while True:
data = input("Number of the timecode slot: ")
if not data.isnumeric():
print("input is not a number")
else:
timeCodeSlot = int(data)
break
if not os.path.isdir("./importexport"):
try:
os.mkdir("importexport")
except OSError as err:
print(format(err))
if not os.path.isdir("./macros"):
try:
os.mkdir("macros")
except OSError as err:
print(format(err))
# ------------------------------------------------------------------------------
# reads the input file and writes everything in one array
array = []
try:
with open(sys.argv[1], 'r') as csvfile:
reader = csv.DictReader(csvfile)
for i, row in enumerate(reader):
helperArry = []
for j, element in enumerate(row):
helperArry.append(row[element])
array.append(helperArry)
except IOError as err:
print(format(err))
exit(-1)
# ------------------------------------------------------------------------------
# creating the timecode file
MA = xml.XML(
"<MA xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
"xmlns=\"http://schemas.malighting.de/grandma2/xml/MA\" "
"xsi:schemaLocation=\"http://schemas.malighting.de/grandma2/xml/MA "
"http://schemas.malighting.de/grandma2/xml/3.3.4/MA.xsd\" "
"major_vers=\"3\" minor_vers=\"3\" "
"stream_vers=\"4\"></MA>")
Info = xml.SubElement(MA, "Info")
Info.set("datetime", str(datetime.now())[:-7].replace(" ", "T"))
Info.set("showfile", "Insert funny name here")
TimeCode = xml.SubElement(MA, "Timecode")
TimeCode.set("index", "0")
TimeCode.set("name", sys.argv[1][:-4])
TimeCode.set("length", minutesToFrames(array[len(array) - 1][2]))
TimeCode.set("slot", "TC Slot " + str(timeCodeSlot))
TimeCode.set("frame_format", "30 FPS")
if autoStart:
TimeCode.set("m_autostart", "true")
TimeCode.set("no_status_call", "true")
Track = xml.SubElement(TimeCode, "Track")
Track.set("index", "0")
Track.set("active", "true")
Track.set("expanded", "true")
Object = xml.SubElement(Track, "Object")
Object.set("name", sys.argv[1][:-4] + " " + str(pageNumber) + "." +
str(execNumber))
# this seems to be the type no of page
Type = xml.SubElement(Object, "No")
Type.text = "30"
sequence = xml.SubElement(Object, "No")
sequence.text = str(sequenceNumber)
Page = xml.SubElement(Object, "No")
Page.text = str(pageNumber)
Exec = xml.SubElement(Object, "No")
Exec.text = str(execNumber)
SubTrack = xml.SubElement(Track, "SubTrack")
SubTrack.set("index", "0")
for i, e in enumerate(array):
Event = xml.SubElement(SubTrack, "Event")
Event.set("index", str(i))
Event.set("time", minutesToFrames(e[2]))
Event.set("command", "Goto")
Event.set("pressed", "true")
Event.set("step", str(i + 1))
Cue = xml.SubElement(Event, "Cue")
if e[1]:
Cue.set("name", e[1])
else:
Cue.set("name", str(i + 1))
theOneEverywhere = xml.SubElement(Cue, "No")
theOneEverywhere.text = "1"
Sequence = xml.SubElement(Cue, "No")
Sequence.text = str(sequenceNumber)
CueNumber = xml.SubElement(Cue, "No")
CueNumber.text = str(i + 1)
tree = xml.ElementTree(MA)
try:
tree.write("importexport/timecode" + sys.argv[1][:-4] + ".xml",
encoding="UTF-8", xml_declaration=True, pretty_print=True)
except IOError as err:
print(format(err))
with open("importexport/timecode" + sys.argv[1][:-4] + ".xml", 'r+') as fd:
contents = fd.readlines()
copy = contents[0]
contents[0] = copy[:-1] + " <?xml-stylesheet type=\"text/xsl\" " \
"href=\"styles/[email protected]\"?>\n"
fd.seek(0)
fd.writelines(contents)
if len(sys.argv) == 3 and sys.argv[2] != "--nolog":
print("Exported the timecode file successful!")
# -----------------------------------------------------------------------------------------------
# creating the macro file
MA2 = xml.XML(
"<MA xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
"xmlns=\"http://schemas.malighting.de/grandma2/xml/MA\" "
"xsi:schemaLocation=\"http://schemas.malighting.de/grandma2/xml/MA "
"http://schemas.malighting.de/grandma2/xml/3.3.4/MA.xsd\" "
"major_vers=\"3\" minor_vers=\"3\" stream_vers=\"4\"></MA>"
)
Macro = xml.SubElement(MA2, "Macro")
Macro.set("index", "1")
Macro.set("name", "import" + sys.argv[1][:-4])
j = 1
i = 0
for i, e in enumerate(array):
Macroline = xml.SubElement(Macro, "Macroline")
Macroline.set("index", str(j))
text = xml.SubElement(Macroline, "text")
if array[i][1]:
text.text = "Store Sequence " + str(sequenceNumber) + " Cue " +\
str(i + 1) + " \"" + array[i][1] + "\" /o /nc"
else:
text.text = "Store Sequence " + str(sequenceNumber) + " Cue " +\
str(i + 1) + " \"" + str(i + 1) + "\" /o /nc"
j += 1
Macroline = xml.SubElement(Macro, "Macroline")
Macroline.set("index", str(j))
text = xml.SubElement(Macroline, "text")
text.text = "Assign Sequence " + str(sequenceNumber) + " Cue " +\
str(i + 1) + " /fade=" + str(fadeTime) + ".00 "
j += 1
Macroline = xml.SubElement(Macro, "Macroline")
Macroline.set("index", str(j))
text = xml.SubElement(Macroline, "text")
text.text = "Label Sequence " + str(sequenceNumber) + " \"" + \
sys.argv[1][:-4] + "\""
j += 1
Macroline = xml.SubElement(Macro, "Macroline")
Macroline.set("index", str(j))
text = xml.SubElement(Macroline, "text")
text.text = "Assign Sequence " + str(sequenceNumber) + " At Exec 1." +\
str(pageNumber) + "." + str(execNumber)
j += 1
Macroline = xml.SubElement(Macro, "Macroline")
Macroline.set("index", str(j))
text = xml.SubElement(Macroline, "text")
text.text = "SelectDrive 4"
j += 1
Macroline = xml.SubElement(Macro, "Macroline")
Macroline.set("index", str(j))
text = xml.SubElement(Macroline, "text")
text.text = "Import \"timecode" + sys.argv[1][:-4] + "\" At Timecode 1 /o"
j += 1
Macroline = xml.SubElement(Macro, "Macroline")
Macroline.set("index", str(j))
text = xml.SubElement(Macroline, "text")
text.text = "Label Timecode 1 \"" + sys.argv[1][:-4] + "\""
j += 1
tree = xml.ElementTree(MA2)
try:
tree.write("Macros/macro" + sys.argv[1][:-4] + ".xml", encoding="UTF-8",
xml_declaration=True, pretty_print=True)
except IOError as err:
print(format(err))
if len(sys.argv) == 3 and sys.argv[2] != "--nolog":
print("Exported the macro file successful!")
print("Now copy the two folders onto the gma2 folder on your"
" USB-drive and import the macro and run it\n"
"If you are running onPC and you are loading from the internal"
" storage you need to change the SelectDrive"
" to 1 im the macro")
else:
print("processed" + sys.argv[1])