asigalov61
commited on
Commit
•
48bf7f7
1
Parent(s):
cb09f1e
Update app.py
Browse files
app.py
CHANGED
@@ -278,137 +278,13 @@ if __name__ == "__main__":
|
|
278 |
soundfont = "SGM-v2.01-YamahaGrand-Guit-Bass-v2.7.sf2"
|
279 |
|
280 |
print('=' * 70)
|
281 |
-
print('Loading Pitches Chords Progressions dataset...')
|
282 |
print('=' * 70)
|
283 |
-
|
284 |
-
|
285 |
-
print('=' * 70)
|
286 |
-
print('Done!')
|
287 |
-
print('=' * 70)
|
288 |
-
|
289 |
-
#===============================================================================
|
290 |
-
|
291 |
-
minimum_chords_chunk_length = 4 # @param {"type":"slider","min":4,"max":8,"step":1}
|
292 |
-
chords_chunks_overlap_value = 4 # @param {"type":"slider","min":2,"max":8,"step":1}
|
293 |
-
|
294 |
-
print('=' * 70)
|
295 |
-
print('Selecting chords chunks...')
|
296 |
-
print('=' * 70)
|
297 |
-
|
298 |
-
chunk_size = minimum_chords_chunk_length
|
299 |
-
|
300 |
-
long_chords_chunks = []
|
301 |
-
|
302 |
-
for c in tqdm(good_chords_chunks):
|
303 |
-
if chunk_size + chords_chunks_overlap_value <= len(c):
|
304 |
-
long_chords_chunks.append(c)
|
305 |
-
|
306 |
-
print('Done!')
|
307 |
-
print('=' * 70)
|
308 |
-
print('Selected chords chunks of minimum length:', minimum_chords_chunk_length+chords_chunks_overlap_value)
|
309 |
-
print('=' * 70)
|
310 |
-
print('Total number of selected chord chunks:', len(long_chords_chunks))
|
311 |
-
print('=' * 70)
|
312 |
-
|
313 |
-
chords_chunks_multiplicatrion_factor = 6 # @param {"type":"slider","min":1,"max":6,"step":1}
|
314 |
-
|
315 |
-
#===============================================================================
|
316 |
-
# Helper chord function
|
317 |
-
#===============================================================================
|
318 |
-
|
319 |
-
def check_chord(chord):
|
320 |
-
|
321 |
-
tones_chord = sorted(set([p % 12 for p in chord]))
|
322 |
-
|
323 |
-
new_tones_chord = []
|
324 |
-
|
325 |
-
if 0 in tones_chord and 11 in tones_chord:
|
326 |
-
tones_chord.remove(11)
|
327 |
-
|
328 |
-
for t in tones_chord:
|
329 |
-
if t+1 in tones_chord:
|
330 |
-
tones_chord.remove(t+1)
|
331 |
-
if t-1 in tones_chord:
|
332 |
-
tones_chord.remove(t-1)
|
333 |
-
|
334 |
-
new_chord = tuple()
|
335 |
-
|
336 |
-
for p in chord:
|
337 |
-
if p % 12 in tones_chord:
|
338 |
-
new_chord += tuple([p])
|
339 |
-
|
340 |
-
if len(new_chord) > 2:
|
341 |
-
return new_chord
|
342 |
-
|
343 |
-
else:
|
344 |
-
return None
|
345 |
-
|
346 |
-
#===============================================================================
|
347 |
-
|
348 |
-
print('=' * 70)
|
349 |
-
print('Multiplying chords chunks...')
|
350 |
-
print('=' * 70)
|
351 |
-
print('Chords chunks will be multiplied', chords_chunks_multiplicatrion_factor * 2, 'times' )
|
352 |
-
print('=' * 70)
|
353 |
-
|
354 |
-
long_chords_chunks_mult = set()
|
355 |
-
|
356 |
-
for c in tqdm(long_chords_chunks):
|
357 |
-
|
358 |
-
for tv in range(-chords_chunks_multiplicatrion_factor, chords_chunks_multiplicatrion_factor):
|
359 |
-
gc = []
|
360 |
-
for cc in c:
|
361 |
-
chord = [max(1, min(127, p+tv)) for p in cc]
|
362 |
-
checked_chord = check_chord(chord)
|
363 |
-
if checked_chord is not None:
|
364 |
-
gc.append(checked_chord)
|
365 |
-
if len(gc) == len(c) or (len(gc) >= chunk_size + chords_chunks_overlap_value and gc == c[:len(gc)]) or (len(gc) >= chunk_size + chords_chunks_overlap_value and gc == c[len(gc):]):
|
366 |
-
long_chords_chunks_mult.add(tuple(gc))
|
367 |
-
|
368 |
-
print('Done!')
|
369 |
-
print('=' * 70)
|
370 |
-
print('Total number of multiplied chords chunks:', len(long_chords_chunks_mult))
|
371 |
-
print('=' * 70)
|
372 |
-
|
373 |
-
#===============================================================================
|
374 |
-
|
375 |
-
print('=' * 70)
|
376 |
-
print('Creating chords dictionary...')
|
377 |
-
print('=' * 70)
|
378 |
-
|
379 |
-
long_tones_chords_dict = set()
|
380 |
-
|
381 |
-
for a in tqdm(long_chords_chunks_mult):
|
382 |
-
for aa in a:
|
383 |
-
tones_chord = tuple(sorted(set([p % 12 for p in aa])))
|
384 |
-
long_tones_chords_dict.add(tones_chord)
|
385 |
-
|
386 |
-
long_tones_chords_dict = list(long_tones_chords_dict)
|
387 |
|
388 |
print('=' * 70)
|
389 |
print('Resulting chords dictionary size:', len(long_tones_chords_dict))
|
390 |
print('=' * 70)
|
391 |
-
print('Preparing chords chunks...')
|
392 |
-
print('=' * 70)
|
393 |
-
|
394 |
-
all_long_chords_tokens_chunks = []
|
395 |
-
all_long_good_chords_chunks = []
|
396 |
-
|
397 |
-
for a in tqdm(long_chords_chunks_mult):
|
398 |
-
|
399 |
-
chunk = []
|
400 |
-
|
401 |
-
for aa in a:
|
402 |
-
|
403 |
-
tones_chord = tuple(sorted(set([p % 12 for p in aa])))
|
404 |
-
chunk.append(long_tones_chords_dict.index(tones_chord))
|
405 |
-
|
406 |
-
if chunk:
|
407 |
-
all_long_chords_tokens_chunks.append(chunk)
|
408 |
-
all_long_good_chords_chunks.append(a)
|
409 |
-
|
410 |
-
print('Done!')
|
411 |
-
print('=' * 70)
|
412 |
print('Loading chords chunks...')
|
413 |
|
414 |
src_long_chunks = np.array([a[:chunk_size] for a in all_long_chords_tokens_chunks])
|
|
|
278 |
soundfont = "SGM-v2.01-YamahaGrand-Guit-Bass-v2.7.sf2"
|
279 |
|
280 |
print('=' * 70)
|
281 |
+
print('Loading processed Pitches Chords Progressions dataset data...')
|
282 |
print('=' * 70)
|
283 |
+
long_tones_chords_dict, all_long_chords_tokens_chunks, all_long_good_chords_chunks = TMIDIX.Tegridy_Any_Pickle_File_Reader('processed_chords_progressions_chunks_data')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
|
285 |
print('=' * 70)
|
286 |
print('Resulting chords dictionary size:', len(long_tones_chords_dict))
|
287 |
print('=' * 70)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
print('Loading chords chunks...')
|
289 |
|
290 |
src_long_chunks = np.array([a[:chunk_size] for a in all_long_chords_tokens_chunks])
|