Update app.py
Browse files
app.py
CHANGED
|
@@ -85,109 +85,119 @@ def GenerateAccompaniment(input_midi, input_num_tokens, input_conditioning_type)
|
|
| 85 |
|
| 86 |
escore_notes = TMIDIX.advanced_score_processor(raw_score, return_enhanced_score_notes=True)[0]
|
| 87 |
|
| 88 |
-
|
| 89 |
|
| 90 |
-
if len(
|
| 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 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
print('=' * 70)
|
| 193 |
|
|
@@ -269,50 +279,37 @@ def GenerateAccompaniment(input_midi, input_num_tokens, input_conditioning_type)
|
|
| 269 |
song_f = []
|
| 270 |
|
| 271 |
time = 0
|
| 272 |
-
|
| 273 |
-
ndur = 0
|
| 274 |
vel = 90
|
| 275 |
-
|
| 276 |
channel = 0
|
| 277 |
-
|
| 278 |
patches = [0] * 16
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
for
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
if 128 <= s < 256:
|
| 301 |
-
|
| 302 |
-
dur = (s-128) * 32
|
| 303 |
-
|
| 304 |
-
if 256 <= s < 384:
|
| 305 |
-
|
| 306 |
-
pitch = (s-256)
|
| 307 |
-
|
| 308 |
-
vel = max(40, pitch)
|
| 309 |
-
|
| 310 |
-
song_f.append(['note', time, dur, 0, pitch, vel, accompaniment_MIDI_patch_number])
|
| 311 |
|
| 312 |
-
fn1 = "
|
| 313 |
|
| 314 |
detailed_stats = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(song_f,
|
| 315 |
-
output_signature = '
|
| 316 |
output_file_name = fn1,
|
| 317 |
track_name='Project Los Angeles',
|
| 318 |
list_of_MIDI_patches=patches
|
|
|
|
| 85 |
|
| 86 |
escore_notes = TMIDIX.advanced_score_processor(raw_score, return_enhanced_score_notes=True)[0]
|
| 87 |
|
| 88 |
+
no_drums_escore_notes = [e for e in escore_notes if e[6] < 80]
|
| 89 |
|
| 90 |
+
if len(no_drums_escore_notes) > 0:
|
| 91 |
|
| 92 |
+
#=======================================================
|
| 93 |
+
# PRE-PROCESSING
|
| 94 |
+
|
| 95 |
+
#===============================================================================
|
| 96 |
+
# Augmented enhanced score notes
|
| 97 |
+
|
| 98 |
+
no_drums_escore_notes = TMIDIX.augment_enhanced_score_notes(no_drums_escore_notes)
|
| 99 |
+
|
| 100 |
+
cscore = TMIDIX.chordify_score([1000, no_drums_escore_notes])
|
| 101 |
+
|
| 102 |
+
clean_cscore = []
|
| 103 |
+
|
| 104 |
+
for c in cscore:
|
| 105 |
+
pitches = []
|
| 106 |
+
cho = []
|
| 107 |
+
for cc in c:
|
| 108 |
+
if cc[4] not in pitches:
|
| 109 |
+
cho.append(cc)
|
| 110 |
+
pitches.append(cc[4])
|
| 111 |
+
|
| 112 |
+
clean_cscore.append(cho)
|
| 113 |
+
|
| 114 |
+
#=======================================================
|
| 115 |
+
# FINAL PROCESSING
|
| 116 |
+
|
| 117 |
+
melody_chords = []
|
| 118 |
+
chords = []
|
| 119 |
+
times = [0]
|
| 120 |
+
durs = []
|
| 121 |
+
|
| 122 |
+
#=======================================================
|
| 123 |
+
# MAIN PROCESSING CYCLE
|
| 124 |
+
#=======================================================
|
| 125 |
+
|
| 126 |
+
pe = clean_cscore[0][0]
|
| 127 |
+
|
| 128 |
+
first_chord = True
|
| 129 |
+
|
| 130 |
+
for c in clean_cscore:
|
| 131 |
+
|
| 132 |
+
# Chords
|
| 133 |
+
|
| 134 |
+
c.sort(key=lambda x: x[4], reverse=True)
|
| 135 |
+
|
| 136 |
+
tones_chord = sorted(set([cc[4] % 12 for cc in c]))
|
| 137 |
+
|
| 138 |
+
try:
|
| 139 |
+
chord_token = TMIDIX.ALL_CHORDS_SORTED.index(tones_chord)
|
| 140 |
+
except:
|
| 141 |
+
checked_tones_chord = TMIDIX.check_and_fix_tones_chord(tones_chord)
|
| 142 |
+
chord_token = TMIDIX.ALL_CHORDS_SORTED.index(checked_tones_chord)
|
| 143 |
+
|
| 144 |
+
melody_chords.extend([chord_token+384])
|
| 145 |
+
|
| 146 |
+
if strip_notes_from_composition:
|
| 147 |
+
if len(tones_chord) > 1:
|
| 148 |
+
chords.extend([chord_token+384])
|
| 149 |
+
|
| 150 |
+
else:
|
| 151 |
+
chords.extend([chord_token+384])
|
| 152 |
+
|
| 153 |
+
if first_chord:
|
| 154 |
+
melody_chords.extend([0])
|
| 155 |
+
first_chord = False
|
| 156 |
+
|
| 157 |
+
for e in c:
|
| 158 |
+
|
| 159 |
+
#=======================================================
|
| 160 |
+
# Timings...
|
| 161 |
+
|
| 162 |
+
time = e[1]-pe[1]
|
| 163 |
+
|
| 164 |
+
dur = e[2]
|
| 165 |
+
|
| 166 |
+
if time != 0 and time % 2 != 0:
|
| 167 |
+
time += 1
|
| 168 |
+
if dur % 2 != 0:
|
| 169 |
+
dur += 1
|
| 170 |
+
|
| 171 |
+
delta_time = int(max(0, min(255, time)) / 2)
|
| 172 |
+
|
| 173 |
+
# Durations
|
| 174 |
+
|
| 175 |
+
dur = int(max(0, min(255, dur)) / 2)
|
| 176 |
+
|
| 177 |
+
# Pitches
|
| 178 |
+
|
| 179 |
+
ptc = max(1, min(127, e[4]))
|
| 180 |
+
|
| 181 |
+
#=======================================================
|
| 182 |
+
# FINAL NOTE SEQ
|
| 183 |
+
|
| 184 |
+
# Writing final note asynchronously
|
| 185 |
+
|
| 186 |
+
if delta_time != 0:
|
| 187 |
+
melody_chords.extend([delta_time, dur+128, ptc+256])
|
| 188 |
+
if strip_notes_from_composition:
|
| 189 |
+
if len(c) > 1:
|
| 190 |
+
times.append(delta_time)
|
| 191 |
+
durs.append(dur+128)
|
| 192 |
+
else:
|
| 193 |
+
times.append(delta_time)
|
| 194 |
+
durs.append(dur+128)
|
| 195 |
+
else:
|
| 196 |
+
melody_chords.extend([dur+128, ptc+256])
|
| 197 |
+
|
| 198 |
+
pe = e
|
| 199 |
+
|
| 200 |
+
#==================================================================
|
| 201 |
|
| 202 |
print('=' * 70)
|
| 203 |
|
|
|
|
| 279 |
song_f = []
|
| 280 |
|
| 281 |
time = 0
|
| 282 |
+
dur = 0
|
|
|
|
| 283 |
vel = 90
|
| 284 |
+
pitch = 0
|
| 285 |
channel = 0
|
| 286 |
+
|
| 287 |
patches = [0] * 16
|
| 288 |
+
|
| 289 |
+
channel = 0
|
| 290 |
+
|
| 291 |
+
for ss in song:
|
| 292 |
+
|
| 293 |
+
if 0 <= ss < 128:
|
| 294 |
+
|
| 295 |
+
time += ss * 32
|
| 296 |
+
|
| 297 |
+
if 128 <= ss < 256:
|
| 298 |
+
|
| 299 |
+
dur = (ss-128) * 32
|
| 300 |
+
|
| 301 |
+
if 256 <= ss < 384:
|
| 302 |
+
|
| 303 |
+
pitch = (ss-256)
|
| 304 |
+
|
| 305 |
+
vel = max(40, pitch)
|
| 306 |
+
|
| 307 |
+
song_f.append(['note', time, dur, channel, pitch, vel, 0])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
|
| 309 |
+
fn1 = "Chords-Progressions-Transformer-Composition"
|
| 310 |
|
| 311 |
detailed_stats = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(song_f,
|
| 312 |
+
output_signature = 'Chords Progressions Transformer',
|
| 313 |
output_file_name = fn1,
|
| 314 |
track_name='Project Los Angeles',
|
| 315 |
list_of_MIDI_patches=patches
|