asigalov61 commited on
Commit
6521a1f
·
verified ·
1 Parent(s): 8fb14e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -44
app.py CHANGED
@@ -184,56 +184,61 @@ def load_midi(input_midi):
184
  raw_score = TMIDIX.midi2single_track_ms_score(input_midi.name)
185
 
186
  escore_notes = TMIDIX.advanced_score_processor(raw_score, return_enhanced_score_notes=True, apply_sustain=True)
 
 
187
 
188
- escore_notes = TMIDIX.augment_enhanced_score_notes(escore_notes[0], sort_drums_last=True)
189
-
190
- dscore = TMIDIX.delta_score_notes(escore_notes)
191
-
192
- dcscore = TMIDIX.chordify_score([d[1:] for d in dscore])
193
-
194
- melody_chords = [18816]
195
-
196
- #=======================================================
197
- # MAIN PROCESSING CYCLE
198
- #=======================================================
199
-
200
- for i, c in enumerate(dcscore):
201
-
202
- delta_time = c[0][0]
203
-
204
- melody_chords.append(delta_time)
205
-
206
- for e in c:
207
 
208
- #=======================================================
 
 
209
 
210
- # Durations
211
- dur = max(1, min(255, e[1]))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
 
213
- # Patches
214
- pat = max(0, min(128, e[5]))
215
-
216
- # Pitches
217
- ptc = max(1, min(127, e[3]))
218
-
219
- # Velocities
220
- # Calculating octo-velocity
221
- vel = max(8, min(127, e[4]))
222
- velocity = round(vel / 15)-1
223
-
224
- #=======================================================
225
- # FINAL NOTE SEQ
226
- #=======================================================
227
 
228
- # Writing final note
229
- pat_ptc = (128 * pat) + ptc
230
- dur_vel = (8 * dur) + velocity
231
-
232
- melody_chords.extend([pat_ptc+256, dur_vel+16768])
233
 
234
- melody_chords = remove_duplicate_pitches(melody_chords)
235
-
236
- return melody_chords
237
 
238
  def save_midi(tokens):
239
  """Convert token sequence back to a MIDI score and write it using TMIDIX (without velocity).
 
184
  raw_score = TMIDIX.midi2single_track_ms_score(input_midi.name)
185
 
186
  escore_notes = TMIDIX.advanced_score_processor(raw_score, return_enhanced_score_notes=True, apply_sustain=True)
187
+
188
+ if escore_notes:
189
 
190
+ escore_notes = TMIDIX.augment_enhanced_score_notes(escore_notes[0], sort_drums_last=True)
191
+
192
+ dscore = TMIDIX.delta_score_notes(escore_notes)
193
+
194
+ dcscore = TMIDIX.chordify_score([d[1:] for d in dscore])
195
+
196
+ melody_chords = [18816]
197
+
198
+ #=======================================================
199
+ # MAIN PROCESSING CYCLE
200
+ #=======================================================
201
+
202
+ for i, c in enumerate(dcscore):
203
+
204
+ delta_time = c[0][0]
 
 
 
 
205
 
206
+ melody_chords.append(delta_time)
207
+
208
+ for e in c:
209
 
210
+ #=======================================================
211
+
212
+ # Durations
213
+ dur = max(1, min(255, e[1]))
214
+
215
+ # Patches
216
+ pat = max(0, min(128, e[5]))
217
+
218
+ # Pitches
219
+ ptc = max(1, min(127, e[3]))
220
+
221
+ # Velocities
222
+ # Calculating octo-velocity
223
+ vel = max(8, min(127, e[4]))
224
+ velocity = round(vel / 15)-1
225
+
226
+ #=======================================================
227
+ # FINAL NOTE SEQ
228
+ #=======================================================
229
+
230
+ # Writing final note
231
+ pat_ptc = (128 * pat) + ptc
232
+ dur_vel = (8 * dur) + velocity
233
+
234
+ melody_chords.extend([pat_ptc+256, dur_vel+16768])
235
 
236
+ melody_chords = remove_duplicate_pitches(melody_chords)
 
 
 
 
 
 
 
 
 
 
 
 
 
237
 
238
+ return melody_chords
 
 
 
 
239
 
240
+ else:
241
+ return [18816]
 
242
 
243
  def save_midi(tokens):
244
  """Convert token sequence back to a MIDI score and write it using TMIDIX (without velocity).