-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMIDIbeat_utility_functions.py
397 lines (342 loc) · 18.4 KB
/
MIDIbeat_utility_functions.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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
from pydub import AudioSegment
import time
import shutil
import MIDIbeat_settings as s
import os
import sys
import json
import collections
from collections import Counter
import operator
import glob
def RenderNoteWavs(): #create samples from individual .wavs for preview purposes
debugprint = []
for note in s.notes:
for line in s.lines:
for layer in s.layers:
for cut in s.cuts:
debugprint.append(note)
debugprint.append(line)
debugprint.append(layer)
note_wav = AudioSegment.from_wav(s.path + note + s.ext)
line_wav = AudioSegment.from_wav(s.path + line + s.ext)
layer_wav = AudioSegment.from_wav(s.path + layer + s.ext)
if note == "note_mine":
print(debugprint)
finalwav = note_wav + line_wav + layer_wav
finalwav.export(s.path + "output\\" + note + "_" + line + "_" + layer + ".wav", format="wav")
debugprint = []
time.sleep(1)
break
else:
debugprint.append(cut)
layer_cut = AudioSegment.from_wav(s.path + cut + s.ext)
finalwav = note_wav + line_wav + layer_wav + layer_cut
finalwav.export(s.path + "output\\" + note + "_" + line + "_" + layer + "_" + cut + ".wav", format="wav")
print(debugprint)
debugprint = []
time.sleep(1)
def RenderObstacleWavs():
debugprint = []
for obstacle in s.obstacles:
for line in s.obstaclelines:
debugprint.append(obstacle)
debugprint.append(line)
obstacle_wav = AudioSegment.from_wav(s.path + obstacle + s.ext)
if obstacle == "obstacle_ceiling":
print(debugprint)
finalwav = obstacle_wav
finalwav.export(s.path + "output\\" + obstacle + ".wav", format="wav")
debugprint = []
time.sleep(1)
break
else:
debugprint.append(line)
line_wav = AudioSegment.from_wav(s.path + line + s.ext)
finalwav = obstacle_wav + line_wav
finalwav.export(s.path + "output\\" + obstacle + "_" + line + ".wav", format="wav")
print(debugprint)
debugprint = []
time.sleep(1)
def RenameReaperOutput(): #renames wavs exported as individual items note: specific order!
wavlist = [filename for filename in os.listdir(s.path) if filename.endswith(".wav")]
combined_audio = s.notes + s.lines + s.layers + s.cuts + s.obstacles + s.obstaclelines
for i, filename in enumerate(wavlist):
shutil.move(s.path + filename, s.path + combined_audio[i] + s.ext)
print(s.path + filename + " = " + s.path + combined_audio[i] + s.ext)
def CreateReaperNotenamesFile():
notekeylist = []
eventkeylist = []
notelist = s.input_tuple + s.obstacle_tuple
favorite_notelist = s.note_favorites
eventlist = s.lighting_tuple
favorite_eventlist = s.event_favorites
for thing in favorite_notelist:
num = thing[1]
list1 = thing[0].split("-")[0]
list2 = thing[0].split("-")[1]
list3 = thing[0].split("-")[2]
list4 = thing[0].split("-")[3]
print(str(num) + " " + "10 " + list1.split("_")[1].capitalize() + " " + list2.split("_")[1].capitalize() + " " + list3.split("_")[1].capitalize() + " " + list4.split("_")[1].capitalize())
notekeylist.append(str(num) + " " + "10 " + list1.split("_")[1].capitalize() + " " + list2.split("_")[1].capitalize() + " " + list3.split("_")[1].capitalize() + " " + list4.split("_")[1].capitalize())
for thing in notelist:
num = thing[1]
list1 = thing[0].split("-")[0]
list2 = thing[0].split("-")[1]
if thing[0].startswith("obstacle"):
print(str(num) + " " + list1.split("_")[1].capitalize() + " " + list2.split("_")[1].capitalize())
notekeylist.append(str(num) + " " + list1.split("_")[1].capitalize() + " " + list2.split("_")[1].capitalize())
with open(s.path + "reaper_keys_notes_10.txt", "w") as file: #favorites
file.write("//MIDI to Beat Saber map Reaper keys (Notes)\n")
for line in notekeylist:
file.write(line + "\n")
notechannels = []
notechannels.append([]) # up
notechannels.append([]) # down
notechannels.append([]) # left
notechannels.append([]) # right
notechannels.append([]) # upleft
notechannels.append([]) # upright
notechannels.append([]) # downleft
notechannels.append([]) # downright
notechannels.append([]) #any
mines = [] #11
for thing in favorite_notelist:
num = thing[1]
list1 = thing[0].split("-")[0]
list2 = thing[0].split("-")[1]
list3 = thing[0].split("-")[2]
cutdirection = s.cut_directions
for aoeu in cutdirection:
print(aoeu)
for i, cut in enumerate(cutdirection):
print(str(num) + " " + list1.split("_")[1].capitalize() + " " + list2.split("_")[1].capitalize() + " " + list3.split("_")[1].capitalize() + " " + cut[0].split("_")[1].capitalize())
notechannels[i].append(str(num) + " " + list1.split("_")[1].capitalize() + " " + list2.split("_")[1].capitalize() + " " + list3.split("_")[1].capitalize() + " " + cut[0].split("_")[1].capitalize())
cutdirection = s.cut_directions
for i, cut in enumerate(cutdirection):
for obstacle in notelist:
num = obstacle[1]
obstacle1 = obstacle[0].split("-")[0]
obstacle2 = obstacle[0].split("-")[1]
if obstacle[0].startswith("obstacle"):
print(str(num) + " " + obstacle1.split("_")[1].capitalize() + " " + obstacle2.split("_")[1].capitalize())
notechannels[i].append(str(num) + " " + obstacle1.split("_")[1].capitalize() + " " + obstacle2.split("_")[1].capitalize())
for thing in favorite_notelist:
num = thing[1]
list1 = "mine"
list2 = thing[0].split("-")[1]
list3 = thing[0].split("-")[2]
print(str(num) + " " + list1.capitalize() + " " + list2.split("_")[1].capitalize() + " " + list3.split("_")[1].capitalize())
mines.append(str(num) + " " + list1.capitalize() + " " + list2.split("_")[1].capitalize() + " " + list3.split("_")[1].capitalize())
for i, channel in enumerate(notechannels):
with open(s.path + "reaper_keys_notes_" + str(i+1) + ".txt", "w") as file:
file.write("//MIDI to Beat Saber map Reaper keys (Notes)\n")
for line in channel:
file.write(line + "\n")
with open(s.path + "reaper_keys_notes_11.txt", "w") as file:
file.write("//MIDI to Beat Saber map Reaper keys (Notes)\n")
for line in mines:
file.write(line + "\n")
for thing in favorite_eventlist:
num = thing[1]
list1 = thing[0].split("-")[0]
list2 = thing[0].split("-")[1]
print(str(num) + " " + list1.split("_")[1].capitalize() + " " + list2.split("_")[1].capitalize())
eventkeylist.append(str(num) + " " + list1.split("_")[1].capitalize() + " " + list2.split("_")[1].capitalize())
with open(s.path + "reaper_keys_events_10.txt", "w") as file:
file.write("//MIDI to Beat Saber map Reaper keys (Events)\n")
for line in eventkeylist:
file.write(line + "\n")
lighting_values = []
lighting_values.append([]) # off
lighting_values.append([]) # blue on
lighting_values.append([]) # blue flash stay
lighting_values.append([]) # blue flash fade
lighting_values.append([]) # none
lighting_values.append([]) # red on
lighting_values.append([]) # red flash stay
lighting_values.append([]) # red flash fade
lighting_rotation_values = []
lighting_rotation_values.append([]) # stop
lighting_rotation_values.append([]) # speed 1
lighting_rotation_values.append([]) # speed 2
lighting_rotation_values.append([]) # speed 3
lighting_rotation_values.append([]) # speed 4
lighting_rotation_values.append([]) # speed 5
lighting_rotation_values.append([]) # speed 6
lighting_rotation_values.append([]) # speed 7
lighting_rotation_values.append([]) # speed 8
lightvalues = s.lighting_lightvalues
rotvalues = s.lighting_rotationvalues
for thing in favorite_eventlist:
num = thing[1]
list1 = thing[0].split("-")[0]
list2 = thing[0].split("-")[1]
if list1 in ["speed_speedlaserleft", "speed_speedlaserright"]:
for i, rotvalue in enumerate(rotvalues):
print(str(num) + " " + list1.split("_")[1].capitalize() + " " + rotvalue[0].split("_")[1].capitalize())
lighting_rotation_values[i].append(str(num) + " " + list1.split("_")[1].capitalize() + " " + rotvalue[0].split("_")[1].capitalize())
else:
for i, lightvalue in enumerate(lightvalues):
print(str(num) + " " + list1.split("_")[1].capitalize() + " " + lightvalue[0].split("_")[1].capitalize())
lighting_values[i].append(str(num) + " " + list1.split("_")[1].capitalize() + " " + lightvalue[0].split("_")[1].capitalize())
for i, channel in enumerate(lighting_rotation_values):
with open(s.path + "reaper_keys_events_" + str(i+1) + ".txt", "w") as file:
file.write("//MIDI to Beat Saber map Reaper keys (Events)\n")
for line in channel:
file.write(line + "\n")
for i, channel in enumerate(lighting_values):
with open(s.path + "reaper_keys_events_" + str(i+1) + ".txt", "a") as file:
for line in channel:
file.write(line + "\n")
def CreateVisualizationFavoritesFile(): # crappy setup but it works for now
favorite_notelist = s.note_favorites
output = []
blue_num = []
blue_n_pointer = "200"
blue_n = []
blue_saber_start = "96"
blue_saber_end = "107"
blue_x_note_pointer = "1200"
blue_x_note = []
blue_y_note_pointer = "1500"
blue_y_note = []
blue_cut_direction_pointer = "1700"
blue_cut_direction = []
red_num = []
red_n_pointer = "700"
red_n = []
red_saber_start = "108"
red_saber_end = "119"
red_x_note_pointer = "2200"
red_x_note = []
red_y_note_pointer = "2500"
red_y_note = []
red_cut_direction_pointer = "2700"
red_cut_direction = []
for thing in favorite_notelist:
num = thing[1]
list1 = thing[0].split("-")[0]
list2 = thing[0].split("-")[1]
list3 = thing[0].split("-")[2]
list4 = thing[0].split("-")[3]
if list1 == "note_blue":
blue_num.append(num)
blue_n.append(list1)
blue_x_note.append(list2)
blue_y_note.append(list3)
blue_cut_direction.append(list4)
elif list1 == "note_red":
red_num.append(num)
red_n.append(list1)
red_x_note.append(list2)
red_y_note.append(list3)
red_cut_direction.append(list4)
output.append("blue_n = " + blue_n_pointer + ";")
output.append("blue_saber_start = " + blue_saber_start + ";")
output.append("blue_saber_end = " + blue_saber_end + ";")
output.append("blue_x_note = " + blue_x_note_pointer + ";")
output.append("blue_y_note = " + blue_y_note_pointer + ";")
output.append("blue_cut_direction = " + blue_cut_direction_pointer + ";")
for i, thing in enumerate(blue_n):
output.append("blue_n[" + str(i) + "] = " + str(blue_num[i]) + ";")
output.append("blue_x_note[" + str(i) + "] = " + blue_x_note[i] + ";")
output.append("blue_y_note[" + str(i) + "] = " + blue_y_note[i] + ";")
output.append("blue_cut_direction[" + str(i) + "] = " + blue_cut_direction[i] + ";")
output.append("red_n = " + red_n_pointer + ";")
output.append("red_saber_start = " + red_saber_start + ";")
output.append("red_saber_end = " + red_saber_end + ";")
output.append("red_x_note = " + red_x_note_pointer + ";")
output.append("red_y_note = " + red_y_note_pointer + ";")
output.append("red_cut_direction = " + red_cut_direction_pointer + ";")
for i, thing in enumerate(red_n):
output.append("red_n[" + str(i) + "] = " + str(red_num[i]) + ";")
output.append("red_x_note[" + str(i) + "] = " + red_x_note[i] + ";")
output.append("red_y_note[" + str(i) + "] = " + red_y_note[i] + ";")
output.append("red_cut_direction[" + str(i) + "] = " + red_cut_direction[i] + ";")
for line in output:
print(line)
with open(s.path + "visualization_effect_favorite_notes.txt", "w") as file:
for line in output:
file.write(line + "\n")
def ParseJSON():
mode = sys.argv[1]
fileindex = sys.argv[2]
typelist = []
resultlist = []
max = 0
path = "C:\\beatsaber\\OST\\"
filelist = glob.glob(path + "*.json")
#filelist = glob.glob(path + "**/" + "*.json")
file = filelist[int(fileindex)]
if mode == "--n":
print("notes for " + file)
with open(file, 'r') as jsonfile:
data = json.load(jsonfile)
for thing in data["_notes"]:
thing.pop("_time")
typelist.append((thing["_type"], thing["_lineIndex"], thing["_lineLayer"], thing["_cutDirection"]))
resultlist = Counter(typelist).most_common()
for value in resultlist:
max += value[1]
filelist = []
for key, value in resultlist:
notetype = [item[0] for item in s.note_types if key[0] == item[1]]
notetype_print = notetype[0].split("_")[1].capitalize()
lineindex = [item[0] for item in s.line_indices if key[1] == item[1]]
lineindex_print = lineindex[0].split("_")[1].capitalize()
linelayer = [item[0] for item in s.line_layers if key[2] == item[1]]
linelayer_print = linelayer[0].split("_")[1].capitalize()
cutdirection = [item[0] for item in s.cut_directions if key[3] == item[1]]
cutdirection_print = cutdirection[0].split("_")[1].capitalize()
print("{:>2}{:<4}".format(str(value), "x") + "{:<1}{:^5.1%}{:>1}".format("(", value/max, ")") + "{:>8} {:>15} {:>10} {:>10}".format(notetype_print, lineindex_print, linelayer_print, cutdirection_print))
filelist += notetype + list("-") + lineindex + list("-") + linelayer + list("-") + cutdirection + list(" " + str(value) + "x (" + "{:^5.1%}".format(value/max)) + list("\n")
with open(file.rsplit(".", 1)[0] + "_notes.txt", 'w') as txtfile:
for thing in filelist:
txtfile.write(str(thing))
elif mode == "--l":
print("lighting for " + file)
with open(file, 'r') as jsonfile:
data = json.load(jsonfile)
for thing in data["_events"]:
thing.pop("_time")
typelist.append((thing["_type"], thing["_value"]))
resultlist = Counter(typelist).most_common()
for value in resultlist:
max += value[1]
filelist = []
for key, value in resultlist:
lighttype = [item[0] for item in s.lighting_types if key[0] == item[1]]
lighttype_print = lighttype[0].split("_")[1].capitalize()
lightvalue = [item[0] for item in s.lighting_lightvalues if key[1] == item[1]]
lightvalue_print = lightvalue[0].split("_")[1].capitalize()
print("{:>2}{:<4}".format(str(value), "x") + "{:<1}{:^5.1%}{:>1}".format("(", value/max, ")") + "{:>15} {:>12}".format(lighttype_print, lightvalue_print))
filelist += lighttype + list("-") + lightvalue + list(" " + str(value) + "x (" + "{:^5.1%}".format(value/max)) + list("\n")
with open(file.rsplit(".", 1)[0] + "_events.txt", 'w') as txtfile:
for thing in filelist:
txtfile.write(str(thing))
elif mode == "--o":
print("obstacles for " + file)
with open(file, 'r') as jsonfile:
data = json.load(jsonfile)
for thing in data["_obstacles"]:
thing.pop("_time")
typelist.append((thing["_type"], thing["_lineIndex"], thing["_duration"], thing["_width"]))
resultlist = Counter(typelist).most_common()
for value in resultlist:
max += value[1]
filelist = []
for key, value in resultlist:
obstacletype = [item[0] for item in s.obstacle_types if key[0] == item[1]]
obstacletype_print = obstacletype[0].split("_")[1].capitalize()
obstaclelineindex = [item[0] for item in s.obstacle_line_indices if key[1] == item[1]]
obstaclelineindex_print = obstaclelineindex[0].split("_")[1].capitalize()
obstacleduration = [item[0] for item in s.obstacle_durations if key[2] == item[1]]
obstacleduration_print = obstacleduration[0].split("_")[1].capitalize()
obstaclewidth = [item[0] for item in s.obstacle_widths if key[3] == item[1]]
obstaclewidth_print = obstaclewidth[0].split("_")[1].capitalize()
print("{:>2}{:<4}".format(str(value), "x") + "{:<1}{:^5.1%}{:>1}".format("(", value/max, ")") + "{:>8} {:>15} {:>14} {:>10}".format(obstacletype_print, obstaclelineindex_print, obstacleduration_print, obstaclewidth_print))
filelist += obstacletype + list("-") + obstaclelineindex + list("-") + obstacleduration + list("-") + obstaclewidth + list(" " + str(value) + "x (" + "{:^5.1%}".format(value/max)) + list("\n")
with open(file.rsplit(".", 1)[0] + "_obstacles.txt", 'w') as txtfile:
for thing in filelist:
txtfile.write(str(thing))