-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimd_helper.py
292 lines (258 loc) · 8.83 KB
/
imd_helper.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
import json
import struct
def convert_imd_to_mc_slide(song, ch_name):
f = open(f"节奏大师官方谱/{song}_4k_hd.imd", 'rb')
f.seek(0, 0)
length = struct.unpack('i', f.read(4))[0]
print(length)
count = struct.unpack('i', f.read(4))[0]
print(count)
for i in range(count):
t = struct.unpack('i', f.read(4))
bpm = struct.unpack('d', f.read(8))
if i == 0:
print(t, bpm)
flag = struct.unpack('h', f.read(2))[0]
count = struct.unpack('i', f.read(4))[0]
key = 0
print(flag, count)
d = []
for i in range(count):
action = struct.unpack('h', f.read(2))[0]
time = struct.unpack('i', f.read(4))[0]
track = struct.unpack('b', f.read(1))[0]
param = struct.unpack('i', f.read(4))[0]
if (time > 0) and (time <= length):
if action == 0x00:
if key < track:
key = track
elif action in [0x01, 0x61, 0x21, 0xA1]:
if key < track + param:
key = track + param
elif action in [0x02, 0x62, 0x22, 0xA2]:
if (time + param > length):
param = length - time
if key < track:
key = track
d.append([time, track, action, param])
key += 1
f.close()
print("key", key)
print(d)
bpm = bpm[0]
col_list = [32, 96, 160, 224]
one_beat = int(60*1000 / bpm)
notes = []
index = 0
note = {}
slide_notes = []
while index < len(d):
[time, track, action, param] = d[index]
which_beat = [int(time / one_beat), int((time % one_beat) / one_beat * 1000), 1000]
note = {
"beat": which_beat,
"x": col_list[track],
# "w": 62
}
if action == 0:
notes.append(note)
elif action == 1:
notes.append(note)
_notes = []
span = param*64
for i in range(1, 3):
x = int(col_list[track] + span*i/2)
t = time + int(i*one_beat/16)
_notes.append({
"beat": [int(t / one_beat), int((t % one_beat) / one_beat * 1000), 1000],
"x": x,
"w": 62,
"type": 4
})
notes += _notes
elif action == 2:
note["seg"] = [{
"beat": [int(param / one_beat), int((param % one_beat) / one_beat * 1000), 1000],
"x": 0,
}]
notes.append(note)
else:
slide_notes.append([time, track, action, param])
index += 1
print(slide_notes)
id_selected = []
slides = []
while len(id_selected) != len(slide_notes):
one_slide = []
for i, note in enumerate(slide_notes):
if i in id_selected:
continue
if len(one_slide) == 0:
one_slide.append(note)
id_selected.append(i)
else:
last_note = one_slide[-1]
if last_note[2] == note[2]:
continue
if note[3] <= 3:
if ((last_note[0] + last_note[3]) == note[0]) and (last_note[1] == note[1]):
one_slide.append(note)
id_selected.append(i)
elif ((last_note[0] + last_note[3] + 1) == note[0]) and (last_note[1] == note[1]):
one_slide.append(note)
id_selected.append(i)
elif ((last_note[0] + last_note[3] - 1) == note[0]) and (last_note[1] == note[1]):
one_slide.append(note)
id_selected.append(i)
else:
if (last_note[0] == note[0]) and ((last_note[1] + last_note[3]) == note[1]):
one_slide.append(note)
id_selected.append(i)
if (note[2] == 162) or (note[2] == 161):
break
slides.append(one_slide)
# print(slides)
col_list_slide = [44, 99, 154, 210]
# col_list_slide = [32, 96, 160, 224]
for one_slide in slides:
_len = len(one_slide)
index = 0
[time, track, action, param] = one_slide[index]
which_beat = [int(time / one_beat), int((time % one_beat) / one_beat * 1000), 1000]
note = {
"beat": which_beat,
"x": col_list_slide[track],
"w": 90,
"seg": []
}
index += 1
if _len == 1:
del note["seg"]
notes.append(note)
_notes = []
span = param * 55
for i in range(1, 3):
x = int(col_list[track] + span*i/2)
t = time + int(i*one_beat/16)
_notes.append({
"beat": [int(t / one_beat), int((t % one_beat) / one_beat * 1000), 1000],
"x": x,
"w": 62,
"type": 4
})
notes += _notes
continue
next_note = one_slide[index]
start_offset = 0
start_t = time
while index < _len:
if param < 3: # 如果是滑长条
offset = param * 55
start_offset += offset
_t = next_note[0] + next_note[3] - time
if _t > (one_beat*0.3):
_t = time + (one_beat*0.3) - start_t
note["seg"].append({
"beat": [int(_t / one_beat), int((_t % one_beat) / one_beat * 1000), 1000],
"x": start_offset,
"w": 90,
})
if _t > (one_beat * 0.3):
_t = next_note[0] + next_note[3] - start_t
note["seg"].append({
"beat": [int(_t / one_beat), int((_t % one_beat) / one_beat * 1000), 1000],
"x": start_offset,
"w": 90,
})
else:
offset_t = param - int(0.3 * one_beat)
if offset_t > 0:
_t = time - start_t + offset_t
note["seg"].append({
"beat": [int(_t / one_beat), int((_t % one_beat) / one_beat * 1000), 1000],
"x": start_offset,
"w": 90,
})
offset_t = 0
offset = next_note[3] * 64
start_offset += offset
_t = time + param - start_t
note["seg"].append({
"beat": [int(_t / one_beat), int((_t % one_beat) / one_beat * 1000), 1000],
"x": start_offset,
"w": 90,
})
index += 1
if index >= _len:
[time, track, action, param] = next_note
if param < 3:
pass
else:
_t = time + param - start_t
note["seg"].append({
"beat": [int(_t / one_beat), int((_t % one_beat) / one_beat * 1000), 1000],
"x": start_offset,
"w": 90,
})
break
[time, track, action, param] = one_slide[index]
index += 1
if index >= _len:
if param < 3:
pass
else:
_t = time + param - start_t
note["seg"].append({
"beat": [int(_t / one_beat), int((_t % one_beat) / one_beat * 1000), 1000],
"x": start_offset,
"w": 90,
})
break
else:
next_note = one_slide[index]
# print(note)
# exit()
notes.append(note)
# print(notes)
# exit()
# print(notes)
notes.append({
"beat": [0, 0, 1],
"sound": f"{song}.mp3",
"vol": 100,
"type": 1
})
data = {
"meta": {
"$ver": 0,
"creator": "nladuo",
"background": f"{song}.jpg",
"version": f"{ch_name}_4k_Hard",
"id": 0,
"mode": 7,
"time": 1553609049,
"song": {
"title": "节奏大师4k官谱转谱",
# "title": f"{ch_name}",
"artist": "节奏大师",
"id": 0
},
"mode_ext": {}
},
"time": [{
"beat": [0, 0, 1],
"bpm": bpm
}],
"effect": [],
"note": notes,
"extra": {
"test": {
"divide": 4,
"speed": 100,
"save": 0,
"lock": 0,
"edit_mode": 0
}
}
}
return data