Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,7 +47,7 @@ SOUDFONT_PATH = 'SGM-v2.01-YamahaGrand-Guit-Bass-v2.7.sf2'
|
|
| 47 |
#==================================================================================
|
| 48 |
|
| 49 |
print('Loading MIDI Loops Small Dataset...')
|
| 50 |
-
print('
|
| 51 |
|
| 52 |
midi_loops_dataset = TMIDIX.Tegridy_Any_Pickle_File_Reader('MIDI-Loops-Dataset-Small-CC-BY-NC-SA.pickle')
|
| 53 |
|
|
@@ -143,6 +143,8 @@ def Mix_Loops(input_midi,
|
|
| 143 |
|
| 144 |
#===============================================================================
|
| 145 |
|
|
|
|
|
|
|
| 146 |
chunk_len = 5
|
| 147 |
chunk_chords_set = 13
|
| 148 |
|
|
@@ -160,10 +162,15 @@ def Mix_Loops(input_midi,
|
|
| 160 |
|
| 161 |
all_chords_chunks = np.array(all_chords_chunks)
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
#==================================================================
|
| 164 |
|
|
|
|
| 165 |
print('=' * 70)
|
| 166 |
-
print('Generating...')
|
| 167 |
|
| 168 |
max_num_loops = 4
|
| 169 |
max_tries = 100
|
|
@@ -176,7 +183,8 @@ def Mix_Loops(input_midi,
|
|
| 176 |
while song_loops_counter < max_num_loops:
|
| 177 |
|
| 178 |
if stries % 25 == 0:
|
| 179 |
-
print('
|
|
|
|
| 180 |
stries += 1
|
| 181 |
|
| 182 |
midxs = []
|
|
@@ -229,8 +237,7 @@ def Mix_Loops(input_midi,
|
|
| 229 |
if midx not in rmidxs and midx not in song_midxs:
|
| 230 |
|
| 231 |
song_midxs.append(midx)
|
| 232 |
-
|
| 233 |
-
|
| 234 |
sidx = int(midx // loops_mult)
|
| 235 |
song_idxs.append(sidx)
|
| 236 |
|
|
@@ -241,7 +248,6 @@ def Mix_Loops(input_midi,
|
|
| 241 |
song_scores.append(song[2])
|
| 242 |
|
| 243 |
song_loops_counter += 1
|
| 244 |
-
#print(song_loops_counter)
|
| 245 |
|
| 246 |
else:
|
| 247 |
if len(rmidxs) > 1 and rtries < max_tries:
|
|
@@ -250,13 +256,11 @@ def Mix_Loops(input_midi,
|
|
| 250 |
song_names.pop()
|
| 251 |
song_chords.pop()
|
| 252 |
song_scores.pop()
|
| 253 |
-
#print('revert')
|
| 254 |
song_loops_counter -= 1
|
| 255 |
rtries += 1
|
| 256 |
rmidxs.append(midx)
|
| 257 |
|
| 258 |
else:
|
| 259 |
-
#print('end')
|
| 260 |
end = True
|
| 261 |
break
|
| 262 |
|
|
@@ -269,6 +273,10 @@ def Mix_Loops(input_midi,
|
|
| 269 |
|
| 270 |
#===============================================================================
|
| 271 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
final_song = []
|
| 273 |
last_max_dur = 0
|
| 274 |
last_dtime = 0
|
|
@@ -281,9 +289,9 @@ def Mix_Loops(input_midi,
|
|
| 281 |
|
| 282 |
score = copy.deepcopy(src_score)
|
| 283 |
|
| 284 |
-
for j in range(
|
| 285 |
|
| 286 |
-
if j
|
| 287 |
|
| 288 |
if i > 0:
|
| 289 |
last_chord = score[[e for e in range(len(score)) if score[e][0] > 0][-1]:]
|
|
@@ -301,6 +309,7 @@ def Mix_Loops(input_midi,
|
|
| 301 |
rscore = list(reversed(score))
|
| 302 |
|
| 303 |
ccount = 0
|
|
|
|
| 304 |
for r in range(len(rscore)):
|
| 305 |
if rscore[r][0] > 0:
|
| 306 |
ccount += 1
|
|
@@ -333,16 +342,19 @@ def Mix_Loops(input_midi,
|
|
| 333 |
|
| 334 |
final_song.extend(extended_score)
|
| 335 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
#===============================================================================
|
| 337 |
|
| 338 |
print('Rendering results...')
|
| 339 |
|
| 340 |
print('=' * 70)
|
| 341 |
-
print('Sample MIDI events:',
|
| 342 |
print('=' * 70)
|
| 343 |
|
| 344 |
-
final_song_abs = TMIDIX.delta_score_to_abs_score(final_song)
|
| 345 |
-
|
| 346 |
output_score, patches, overflow_patches = TMIDIX.patch_enhanced_score_notes(final_song_abs)
|
| 347 |
|
| 348 |
fn1 = "MIDI-Loops-Mixer-Composition"
|
|
|
|
| 47 |
#==================================================================================
|
| 48 |
|
| 49 |
print('Loading MIDI Loops Small Dataset...')
|
| 50 |
+
print('=' * 70)
|
| 51 |
|
| 52 |
midi_loops_dataset = TMIDIX.Tegridy_Any_Pickle_File_Reader('MIDI-Loops-Dataset-Small-CC-BY-NC-SA.pickle')
|
| 53 |
|
|
|
|
| 143 |
|
| 144 |
#===============================================================================
|
| 145 |
|
| 146 |
+
print('Prepping dataset...')
|
| 147 |
+
|
| 148 |
chunk_len = 5
|
| 149 |
chunk_chords_set = 13
|
| 150 |
|
|
|
|
| 162 |
|
| 163 |
all_chords_chunks = np.array(all_chords_chunks)
|
| 164 |
|
| 165 |
+
print('Done!')
|
| 166 |
+
print('=' * 70)
|
| 167 |
+
print('Number of chords chunks:', len(all_chords_chunks))
|
| 168 |
+
print('=' * 70)
|
| 169 |
+
|
| 170 |
#==================================================================
|
| 171 |
|
| 172 |
+
print('Mixing loops...')
|
| 173 |
print('=' * 70)
|
|
|
|
| 174 |
|
| 175 |
max_num_loops = 4
|
| 176 |
max_tries = 100
|
|
|
|
| 183 |
while song_loops_counter < max_num_loops:
|
| 184 |
|
| 185 |
if stries % 25 == 0:
|
| 186 |
+
print('Mixing attempt #', stries)
|
| 187 |
+
|
| 188 |
stries += 1
|
| 189 |
|
| 190 |
midxs = []
|
|
|
|
| 237 |
if midx not in rmidxs and midx not in song_midxs:
|
| 238 |
|
| 239 |
song_midxs.append(midx)
|
| 240 |
+
|
|
|
|
| 241 |
sidx = int(midx // loops_mult)
|
| 242 |
song_idxs.append(sidx)
|
| 243 |
|
|
|
|
| 248 |
song_scores.append(song[2])
|
| 249 |
|
| 250 |
song_loops_counter += 1
|
|
|
|
| 251 |
|
| 252 |
else:
|
| 253 |
if len(rmidxs) > 1 and rtries < max_tries:
|
|
|
|
| 256 |
song_names.pop()
|
| 257 |
song_chords.pop()
|
| 258 |
song_scores.pop()
|
|
|
|
| 259 |
song_loops_counter -= 1
|
| 260 |
rtries += 1
|
| 261 |
rmidxs.append(midx)
|
| 262 |
|
| 263 |
else:
|
|
|
|
| 264 |
end = True
|
| 265 |
break
|
| 266 |
|
|
|
|
| 273 |
|
| 274 |
#===============================================================================
|
| 275 |
|
| 276 |
+
print('Creating final MIDI score...')
|
| 277 |
+
|
| 278 |
+
loops_mult = 2
|
| 279 |
+
|
| 280 |
final_song = []
|
| 281 |
last_max_dur = 0
|
| 282 |
last_dtime = 0
|
|
|
|
| 289 |
|
| 290 |
score = copy.deepcopy(src_score)
|
| 291 |
|
| 292 |
+
for j in range(loops_mult):
|
| 293 |
|
| 294 |
+
if j > 0:
|
| 295 |
|
| 296 |
if i > 0:
|
| 297 |
last_chord = score[[e for e in range(len(score)) if score[e][0] > 0][-1]:]
|
|
|
|
| 309 |
rscore = list(reversed(score))
|
| 310 |
|
| 311 |
ccount = 0
|
| 312 |
+
|
| 313 |
for r in range(len(rscore)):
|
| 314 |
if rscore[r][0] > 0:
|
| 315 |
ccount += 1
|
|
|
|
| 342 |
|
| 343 |
final_song.extend(extended_score)
|
| 344 |
|
| 345 |
+
final_song_abs = TMIDIX.delta_score_to_abs_score(final_song)
|
| 346 |
+
|
| 347 |
+
print('Done!')
|
| 348 |
+
print('=' * 70)
|
| 349 |
+
|
| 350 |
#===============================================================================
|
| 351 |
|
| 352 |
print('Rendering results...')
|
| 353 |
|
| 354 |
print('=' * 70)
|
| 355 |
+
print('Sample MIDI events:', final_song_abs[:3])
|
| 356 |
print('=' * 70)
|
| 357 |
|
|
|
|
|
|
|
| 358 |
output_score, patches, overflow_patches = TMIDIX.patch_enhanced_score_notes(final_song_abs)
|
| 359 |
|
| 360 |
fn1 = "MIDI-Loops-Mixer-Composition"
|