-
Notifications
You must be signed in to change notification settings - Fork 0
/
BMSFactory9.py
181 lines (145 loc) · 8.14 KB
/
BMSFactory9.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
import ImageProcessor as ip
from Note import *
import sys
from operator import attrgetter
class BMSFactory:
MUSIC_NAME = 'GO!GO!MANIAC(expert)'
ARTIST = '放課後ティータイム'
BPM = 250
PLAY_LEVEL: int = 26
BAR_NUM = 106
FILE_NAME = 'GO!GO!MANIAC(expert).bms'
def __init__(self):
with open(self.FILE_NAME, mode='w') as f: # 新規作成または上書きモードで開く
f.write('\n*---------------------- HEADER FIELD\n')
f.write('\n#PLAYER 1\n')
f.write('#TITLE ' + self.MUSIC_NAME + '\n')
f.write('#ARTIST ' + self.ARTIST + '\n')
f.write('#BPM ' + str(self.BPM) + '\n')
f.write('#PLAYLEVEL ' + str(self.PLAY_LEVEL) + '\n')
# f.write('\n#LNTYPE 1\n')
# f.write('\n#WAV01 タップ.mp3\n')
# f.write('#WAV02 フリック.mp3\n')
# f.write('#WAV03 始め1.mp3\n')
# f.write('#WAV04 途中1.mp3\n')
# f.write('#WAV05 離し1.mp3\n')
# f.write('#WAV06 フリック離し1.mp3\n')
# f.write('#WAV07 始め2.mp3\n')
# f.write('#WAV08 途中2.mp3\n')
# f.write('#WAV09 離し2.mp3\n')
# f.write('#WAV0A フリック離し2.mp3\n')
# f.write('#WAV10 ' + self.MUSIC_NAME + '.mp3\n')
# f.write('#WAV11 15sec.mp3\n')
f.write('\n*---------------------- MAIN DATA FIELD\n')
def write_main(self, notes):
# print(notes[0])
with open(self.FILE_NAME, mode='a') as f: # 追記モードで開く
# 曲の始まりを指定(現時点では適当)
f.write('\n#00201:00100000000000000000000000000000\n')
start_indexes = [0, 0, 0, 0, 0, 0, 0]
for bar in range(1, ip.ImageProcessor.BAR_NUM + 1): # 小節ループ
# if bar == 5: # BPM変更
# f.write('\n#00503:BA\n')
for lane_index in range(0, 7): # レーンループ
lane_num = lane_index+1
# 1行(1小節)分のノーツを取得し、一行分書き込み
bar_notes = list()
# bar_num = int(notes[lane_index][start_indexes[lane_index]].pos / 4.0) + 1
for note in notes[lane_index][start_indexes[lane_index]:]:
if note.pos/4.0 < bar:
bar_notes.append(note)
# print(note)
if notes[lane_index].index(note) == len(notes[lane_index])-1:
start_indexes[lane_index] = len(notes[lane_index])
else:
start_indexes[lane_index] = notes[lane_index].index(note)
break
if len(bar_notes) == 0:
continue
bar_notes = sorted(bar_notes, key=lambda n: n.pos) # pos順ではない事があるのでソートする
# if bar == 6:
# print(sorted(bar_notes, key=lambda n: n.pos))
# for note in bar_notes:
# print(note.pos)
# 1行あたりのユニット数を数える
is_writable = False
unit_num = 1
# print(unit_num)
had_multiplied_three = False
while not is_writable:
is_writable = True
for note in bar_notes:
if abs(note.pos/4.0*unit_num - int(note.pos/4*unit_num)) > 0.01: #場合分け?
dif = note.pos/4.0*unit_num - int(note.pos/4*unit_num)
# print('dif:' + str(dif))
is_writable = False
if not had_multiplied_three:
if abs(dif - 1.0/3.0) < 0.01:
unit_num *= 3
had_multiplied_three = True
# print(note.pos)
# print(note.pos/4.0*unit_num - int(note.pos/4*unit_num))
elif abs(dif - 2.0/3.0) < 0.01:
unit_num *= 3
had_multiplied_three = True
# print(note.pos)
# print(note.pos / 4.0 * unit_num - int(note.pos / 4 * unit_num))
else:
unit_num *= 2
else:
unit_num *= 2
break
if lane_num < 6:
row_str = '\n#' + '{0:03d}'.format(int(bar)) + '1' + str(lane_num) + ':'
else:
row_str = '\n#' + '{0:03d}'.format(int(bar)) + '1' + str(lane_num+2) + ':'
writing_note_index = 0
# print(unit_num)
# if unit_num > 32:
# for note in bar_notes:
# print('pos:' + str(note.pos))
for i in range(1, unit_num+1):
# if lane_index + 1 == 5 and bar == 4 and i == 10:
# print(abs((bar_notes[writing_note_index].pos - (bar-1) * 4) * unit_num / 4.0 + 1 - i))
# print(str((bar_notes[writing_note_index].pos - (bar-1) * 4) * unit_num / 4.0 + 1))
# print(str((bar_notes[writing_note_index+1].pos - (bar - 1) * 4) * unit_num / 4.0 + 1))
# print(writing_note_index > len(bar_notes)-1)
# for j in bar_notes:
# print(j.pos)
if writing_note_index > len(bar_notes)-1:
row_str += '00'
continue
if abs((bar_notes[writing_note_index].pos - (bar-1) * 4) * unit_num / 4.0 + 1 - i) < 0.01:
note_type = bar_notes[writing_note_index].note_type
if note_type == NoteType.TAP:
row_str += '01'
elif note_type == NoteType.FLICK:
row_str += '02'
elif note_type == NoteType.START:
row_str += '03'
elif note_type == NoteType.MIDDLE:
row_str += '04'
elif note_type == NoteType.TAP_END:
row_str += '05'
elif note_type == NoteType.FLICK_END:
row_str += '06'
elif note_type == NoteType.START2:
row_str += '07'
elif note_type == NoteType.MIDDLE2:
row_str += '08'
elif note_type == NoteType.TAP_END2:
row_str += '09'
elif note_type == NoteType.FLICK_END2:
row_str += '0A'
writing_note_index += 1
else:
# print('dif2:' + str((bar_notes[writing_note_index].pos - (bar-1) * 4) * unit_num / 4.0 + 1 - i))
row_str += '00'
if writing_note_index != len(bar_notes):
print('書き込まれていないノーツがあります.@レーン, 小節:' + str(lane_index+1) + ', ' + str(bar))
for j in bar_notes[writing_note_index:]:
print(str(j.note_type) + ', ' + str((j.pos - (bar-1) * 4) * unit_num / 4.0 + 1))
print('unit_num:' + str(unit_num))
sys.exit("エラー終了")
row_str += '\n'
f.write(row_str)