@@ -37,7 +37,7 @@ def randosu(path, content):
37
37
if content_split [6 ] == '1' :
38
38
bpms .append ({
39
39
# {ms, mpb}
40
- 'ms' : content_split [0 ],
40
+ 'ms' : float ( content_split [0 ]) ,
41
41
'mpb' : float (content_split [1 ])
42
42
})
43
43
@@ -46,16 +46,14 @@ def randosu(path, content):
46
46
# Ignore comments and blanks
47
47
if c .startswith ('//' ) or c == '\n ' :
48
48
continue
49
-
49
+
50
50
# Regular Note: col,192,ms,1,0,0:0:0:0:
51
51
# Long Note: col,192,startms,128,0,endms:0:0:0:0:
52
52
content_split = c .split (',' )
53
53
note_colvalue = int (content_split [0 ])
54
- print (note_colvalue , end = ' ' )
55
54
for i in range (keys ):
56
55
if colrange [i ] < note_colvalue <= colrange [i + 1 ]:
57
56
note_col = i
58
- print (note_col )
59
57
break
60
58
if note_colvalue == 0 :
61
59
note_col = 0
@@ -89,24 +87,6 @@ def randosu(path, content):
89
87
90
88
randnotes = []
91
89
92
- # Boolean List for checking if the column is occupied or not
93
- # Defaults to [False, False, ..., False]
94
- Occupied = keys * [False ]
95
-
96
- # Int, Boolean List for checking the previous occupation (used for Scatter)
97
- # Defaults to [False, False, ..., False]
98
- LastOccupied = keys * [False ]
99
-
100
- # Int, Boolean List for checking the previous occupation for the last 16th beat (used for Scatter)
101
- # Defaults to [False, False, ..., False]
102
- Last16Occupied = keys * [False ]
103
-
104
- # Tracking LastOccupied's ms
105
- lastms = 0
106
-
107
- # Checking if not placing jacks is impossible
108
- Impossible = False
109
-
110
90
# Dictionary List tracking the end time of occupation
111
91
# {col, endms}
112
92
occtime = []
@@ -162,83 +142,94 @@ def randosu(path, content):
162
142
filename = f'{ os .path .dirname (path )} \\ { rand } ({ switch } )_{ randseed } _{ sanitize_filename (diffname )} .osu'
163
143
164
144
i = 0
145
+
146
+ f = open ('test.log' ,mode = 'w' ,encoding = 'utf-8' )
147
+
148
+ # Int, Boolean List for checking the previous occupation (used for Scatter)
149
+ # Defaults to [False, False, ..., False]
150
+ LastOccupied = keys * [False ]
151
+
152
+ # Tracking LastOccupied's ms
153
+ lastms = 0
165
154
166
155
# Randomize position of the notes
167
156
for n in notes :
157
+ # Boolean List for checking if the column is occupied or not
158
+ # Defaults to [False, False, ..., False]
159
+ Occupied = keys * [False ]
160
+
161
+ # Int, Boolean List for checking the previous occupation for the last 16th beat (used for Scatter)
162
+ # Defaults to [False, False, ..., False]
163
+ Last16Occupied = keys * [False ]
164
+
168
165
# Get current ms per beat
169
166
mpb = - 1
170
167
171
168
for b in bpms :
172
169
if n ['ms' ] < b ['ms' ]:
173
170
mpb = bpms [bpms .index (b )- 1 ]['mpb' ]
171
+ break
174
172
175
173
if mpb == - 1 :
176
174
mpb = bpms [- 1 ]['mpb' ]
177
175
178
176
# Copy Occupied if Scatter and it's the next notes
179
177
if (i != 0 ) and Scatter :
180
- if n ['ms' ] > lastms :
178
+ # +5 just in case of unsnapped notes
179
+ if n ['ms' ] > lastms + 5 :
181
180
lastms = n ['ms' ]
182
- k = 0
183
- for lo in Occupied :
184
- LastOccupied [k ] = lo
185
- k += 1
181
+ LastOccupied = keys * [False ]
182
+ for o in occtime [:]:
183
+ LastOccupied [o ['col' ]] = True
186
184
187
185
# If current ms > endms, Unoccupy the column
188
186
# Doing this the first because the program gets stuck often
187
+ # Also occupy the column meanwhile
189
188
for o in occtime [:]:
190
189
if n ['ms' ] > o ['endms' ]:
191
190
occtime .remove (o )
192
- Occupied [o ['col' ]] = False
191
+ for o in occtime [:]:
192
+ Occupied [o ['col' ]] = True
193
193
194
194
for o in occ16time [:]:
195
195
if n ['ms' ] > o ['endms' ]:
196
196
occ16time .remove (o )
197
- Last16Occupied [o ['col' ]] = False
197
+ for o in occ16time [:]:
198
+ Last16Occupied [o ['col' ]] = True
198
199
199
200
# If no switch, (and if scatter, if not last16occupied,) keep the column
200
201
if not Switch [i ] and not Occupied [n ['col' ]] and (not Scatter or not Last16Occupied [n ['col' ]]):
201
202
randcol = n ['col' ]
202
203
# If switch, Get an unoccupied column
203
204
else :
204
- while True :
205
- randcol = randint (0 , keys - 1 )
206
- if not Occupied [randcol ]:
207
- if Scatter :
208
- if not Last16Occupied [randcol ]:
209
- break
210
-
211
- # Checking if ignoring 16th jack is impossible
212
- # Keep Impossible True if all Occupied and Last16Occupied is True
213
- Impossible = True
214
- for j in range (keys ):
215
- if not Occupied [j ] or not Last16Occupied [j ]:
216
- Impossible = False
205
+ # leftcol: not Occupied, possible columns
206
+ # goodcol: not Occupied AND not LastOccupied, desired columns
207
+ # bestcol: not Occupied AND not Last16Occupied, most desired columns
208
+ bestcol = []
209
+ goodcol = []
210
+ leftcol = []
217
211
218
- # If it is not impossible, just try again
219
- # If impossible however, prioritize not LastOccupied column
220
- if Impossible :
221
- # Check if every column is LastOccupied (e.g. Chords with all keys)
222
- # leftcol: not Occupied, possible columns
223
- # goodcol: not Occupied AND not LastOccupied, desired columns
224
- leftcol = []
225
- goodcol = []
226
- for j in range (keys ):
227
- if not Occupied [j ]:
228
- leftcol .append (j )
229
- if not LastOccupied [j ]:
230
- goodcol .append (j )
231
- Impossible = False
212
+ for j in range (keys ):
213
+ if not Occupied [j ]:
214
+ leftcol .append (j )
215
+ if not Last16Occupied [j ]:
216
+ bestcol .append (j )
217
+ if not LastOccupied [j ]:
218
+ goodcol .append (j )
232
219
233
- if not Impossible :
234
- randcol = choice (goodcol )
235
-
236
- else :
237
- randcol = choice (leftcol )
238
-
239
- break
220
+ if len (bestcol ) > 0 :
221
+ randcol = choice (bestcol )
222
+
223
+ else :
224
+ if len (goodcol ) > 0 :
225
+ randcol = choice (goodcol )
226
+
227
+ else :
228
+ if len (leftcol ) > 0 :
229
+ randcol = choice (leftcol )
230
+
240
231
else :
241
- break
232
+ randcol = randint ( 0 , keys - 1 )
242
233
243
234
# if LN:
244
235
if 'endms' in n :
@@ -253,8 +244,8 @@ def randosu(path, content):
253
244
})
254
245
occ16time .append ({
255
246
'col' : randcol ,
256
- # Getting the ceil value just in case
257
- 'endms' : n ['endms ' ] + ceil (mpb / 4 )
247
+ # Getting the ceil value just in case of an unsnapped note
248
+ 'endms' : n ['ms ' ] + ceil (mpb / 4 )
258
249
})
259
250
260
251
# if regular note:
@@ -269,17 +260,15 @@ def randosu(path, content):
269
260
})
270
261
occ16time .append ({
271
262
'col' : randcol ,
272
- # Getting the ceil value just in case
263
+ # Getting the ceil value just in case of an unsnapped note
273
264
'endms' : n ['ms' ] + ceil (mpb / 4 )
274
265
})
275
-
276
- # Occupy the column
277
- Occupied [randcol ] = True
278
- Last16Occupied [randcol ] = True
279
266
280
267
i += 1
281
-
282
268
269
+ f .write (f'{ randcol } | { n ["ms" ]} , { ceil (mpb / 4 )} , { bestcol } , { goodcol } , { leftcol } \n ' )
270
+
271
+ f .close ()
283
272
with open (filename ,'w' ,encoding = 'utf-8' ) as osu :
284
273
col = [int (512 * (2 * column + 1 )/ (2 * keys )) for column in range (keys )]
285
274
0 commit comments