Update app.py
Browse files
app.py
CHANGED
|
@@ -69,6 +69,81 @@ print('Done!')
|
|
| 69 |
print('=' * 70)
|
| 70 |
|
| 71 |
# =================================================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
@spaces.GPU
|
| 74 |
def Convert_Score_to_Performance(input_midi,
|
|
|
|
| 69 |
print('=' * 70)
|
| 70 |
|
| 71 |
# =================================================================================================
|
| 72 |
+
|
| 73 |
+
def load_midi(midi_file)
|
| 74 |
+
|
| 75 |
+
raw_score = TMIDIX.midi2single_track_ms_score(midi_file)
|
| 76 |
+
|
| 77 |
+
escore_notes = TMIDIX.advanced_score_processor(raw_score, return_enhanced_score_notes=True)
|
| 78 |
+
|
| 79 |
+
if escore_notes[0]:
|
| 80 |
+
|
| 81 |
+
escore_notes = TMIDIX.augment_enhanced_score_notes(escore_notes[0], timings_divider=16)
|
| 82 |
+
|
| 83 |
+
pe = escore_notes[0]
|
| 84 |
+
|
| 85 |
+
melody_chords = []
|
| 86 |
+
|
| 87 |
+
seen = []
|
| 88 |
+
|
| 89 |
+
for e in escore_notes:
|
| 90 |
+
|
| 91 |
+
if e[3] != 9:
|
| 92 |
+
|
| 93 |
+
#=======================================================
|
| 94 |
+
|
| 95 |
+
dtime = max(0, min(255, e[1]-pe[1]))
|
| 96 |
+
|
| 97 |
+
if dtime != 0:
|
| 98 |
+
seen = []
|
| 99 |
+
|
| 100 |
+
# Durations
|
| 101 |
+
dur = max(1, min(255, e[2]))
|
| 102 |
+
|
| 103 |
+
# Pitches
|
| 104 |
+
ptc = max(1, min(127, e[4]))
|
| 105 |
+
|
| 106 |
+
vel = max(1, min(127, e[5]))
|
| 107 |
+
|
| 108 |
+
if ptc not in seen:
|
| 109 |
+
|
| 110 |
+
melody_chords.append([dtime, dur, ptc, vel])
|
| 111 |
+
|
| 112 |
+
seen.append(ptc)
|
| 113 |
+
|
| 114 |
+
pe = e
|
| 115 |
+
|
| 116 |
+
print('=' * 70)
|
| 117 |
+
print('Number of notes in a composition:', len(melody_chords))
|
| 118 |
+
print('=' * 70)
|
| 119 |
+
|
| 120 |
+
src_melody_chords_f = []
|
| 121 |
+
melody_chords_f = []
|
| 122 |
+
|
| 123 |
+
for i in range(0, len(melody_chords), 300):
|
| 124 |
+
|
| 125 |
+
chunk = melody_chords[i:i+300]
|
| 126 |
+
|
| 127 |
+
src = []
|
| 128 |
+
src1 = []
|
| 129 |
+
trg = []
|
| 130 |
+
|
| 131 |
+
if len(chunk) == 300:
|
| 132 |
+
|
| 133 |
+
for mm in chunk:
|
| 134 |
+
src.extend([mm[0], mm[2]+256])
|
| 135 |
+
src1.append([mm[0], mm[2]+256, mm[1]+384, mm[3]+640])
|
| 136 |
+
trg.extend([mm[0], mm[2]+256, mm[1]+384, mm[3]+640])
|
| 137 |
+
|
| 138 |
+
src_melody_chords_f.append(src1)
|
| 139 |
+
melody_chords_f.append([768] + src + [769] + trg + [770])
|
| 140 |
+
|
| 141 |
+
print('Done!')
|
| 142 |
+
print('=' * 70)
|
| 143 |
+
print('Number of composition chunks:', len(melody_chords_f))
|
| 144 |
+
print('=' * 70)
|
| 145 |
+
|
| 146 |
+
return melody_chords_f, src_melody_chords_f
|
| 147 |
|
| 148 |
@spaces.GPU
|
| 149 |
def Convert_Score_to_Performance(input_midi,
|