asigalov61 commited on
Commit
3c5d93e
1 Parent(s): 06b8dc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +136 -139
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
- escore_notes = [e for e in escore_notes if e[3] != 9]
89
 
90
- if len(escore_notes) > 0:
91
 
92
- #=======================================================
93
- # PRE-PROCESSING
94
-
95
- #===============================================================================
96
- # Augmented enhanced score notes
97
-
98
- escore_notes = TMIDIX.augment_enhanced_score_notes(escore_notes, timings_divider=32)
99
-
100
- cscore = TMIDIX.chordify_score([1000, escore_notes])
101
-
102
- melody = TMIDIX.fix_monophonic_score_durations([sorted(e, key=lambda x: x[4], reverse=True)[0] for e in cscore])
103
-
104
- #=======================================================
105
- # FINAL PROCESSING
106
-
107
- melody_chords = []
108
-
109
- #=======================================================
110
- # MAIN PROCESSING CYCLE
111
- #=======================================================
112
-
113
- pe = cscore[0][0]
114
-
115
- mpe = melody[0]
116
-
117
- midx = 1
118
-
119
- for i, c in enumerate(cscore):
120
-
121
- c.sort(key=lambda x: (x[3], x[4]), reverse=True)
122
-
123
- # Next melody note
124
-
125
- if midx < len(melody):
126
-
127
- # Time
128
- mtime = melody[midx][1]-mpe[1]
129
-
130
- mdur = melody[midx][2]
131
-
132
- mdelta_time = max(0, min(127, mtime))
133
-
134
- # Durations
135
- mdur = max(0, min(127, mdur))
136
-
137
- # Pitch
138
- mptc = melody[midx][4]
139
-
140
- else:
141
- mtime = 127-mpe[1]
142
-
143
- mdur = mpe[2]
144
-
145
- mdelta_time = max(0, min(127, mtime))
146
-
147
- # Durations
148
- mdur = max(0, min(127, mdur))
149
-
150
- # Pitch
151
- mptc = mpe[4]
152
-
153
-
154
- e = melody[i]
155
-
156
- #=======================================================
157
- # Timings...
158
-
159
- time = e[1]-pe[1]
160
-
161
- dur = e[2]
162
-
163
- delta_time = max(0, min(127, time))
164
-
165
- # Durations
166
-
167
- dur = max(0, min(127, dur))
168
-
169
- # Pitches
170
-
171
- ptc = max(1, min(127, e[4]))
172
-
173
- if ptc < 60:
174
- ptc = 60 + (ptc % 12)
175
-
176
- cha = e[3]
177
-
178
- #=======================================================
179
- # FINAL NOTE SEQ
180
-
181
- if midx < len(melody):
182
- melody_chords.append([delta_time, dur+128, ptc+384, mdelta_time+512, mptc+640])
183
- mpe = melody[midx]
184
- midx += 1
185
- else:
186
- melody_chords.append([delta_time, dur+128, ptc+384, mdelta_time+512, mptc+640])
187
-
188
- pe = e
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
- ntime = 0
273
- ndur = 0
274
  vel = 90
275
- npitch = 0
276
  channel = 0
277
-
278
  patches = [0] * 16
279
- patches[0] = accompaniment_MIDI_patch_number
280
- patches[3] = melody_MIDI_patch_number
281
-
282
- for i, ss in enumerate(song):
283
-
284
- ntime += melody_chords[i][0] * 32
285
- ndur = (melody_chords[i][1]-128) * 32
286
- nchannel = 1
287
- npitch = (melody_chords[i][2]-256) % 128
288
- vel = max(40, npitch)+20
289
-
290
- song_f.append(['note', ntime, ndur, 3, npitch, vel, melody_MIDI_patch_number ])
291
-
292
- time = ntime
293
-
294
- for s in ss:
295
-
296
- if 0 <= s < 128:
297
-
298
- time += s * 32
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 = "Ultimate-Accompaniment-Transformer-Composition"
313
 
314
  detailed_stats = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(song_f,
315
- output_signature = 'Ultimate Accompaniment Transformer',
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