asigalov61 commited on
Commit
380eee4
·
verified ·
1 Parent(s): 6b831b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -57
app.py CHANGED
@@ -130,57 +130,11 @@ def render_midi_output(final_composition):
130
  )
131
  return (16000, midi_audio), midi_plot, fname + '.mid', time_val
132
 
133
- def remove_duplicate_pitches(tokens):
134
- """Remove duplicate notes from tokens seq"""
135
- chords = []
136
- current_chord = []
137
-
138
- for token in tokens:
139
- if token < 256:
140
- if current_chord:
141
- chords.append(current_chord)
142
-
143
- current_chord = [token]
144
-
145
- else:
146
- current_chord.append(token)
147
-
148
- if current_chord:
149
- chords.append(current_chord)
150
-
151
- result = []
152
-
153
- for chord in chords:
154
-
155
- header = chord[0]
156
-
157
- deduped = []
158
-
159
- if len(chord) > 1:
160
-
161
- mid_tokens = [t for t in chord if 256 < t < 18816]
162
-
163
- seen = set()
164
-
165
- for i in range(0, len(mid_tokens), 2):
166
-
167
- pair = mid_tokens[i:i + 2]
168
-
169
- if pair and pair[0] not in seen:
170
- seen.add(pair[0])
171
- deduped.extend(pair)
172
-
173
- high_tokens = [t for t in chord if 18816 < t < 18819]
174
-
175
- result.extend([header] + deduped + high_tokens)
176
-
177
- return result
178
-
179
  # -----------------------------
180
  # MIDI PROCESSING FUNCTIONS
181
  # -----------------------------
182
  def load_midi(input_midi):
183
- """Process the input MIDI file and create a token sequence using without velocity logic."""
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)
@@ -232,8 +186,6 @@ def load_midi(input_midi):
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
 
@@ -241,8 +193,7 @@ def load_midi(input_midi):
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).
245
- The output MIDI file name incorporates a date-time stamp.
246
  """
247
 
248
  time = 0
@@ -259,8 +210,6 @@ def save_midi(tokens):
259
 
260
  song_f = []
261
 
262
- tokens = remove_duplicate_pitches(tokens)
263
-
264
  for ss in tokens:
265
 
266
  if 0 <= ss < 256:
@@ -338,13 +287,10 @@ def generate_music(prime, num_gen_tokens, num_mem_tokens, num_gen_batches, model
338
  )
339
 
340
  outputs = []
341
-
342
- for o in out.tolist():
343
- outputs.append(remove_duplicate_pitches(o))
344
 
345
  print("Done!")
346
  print_sep()
347
- return outputs
348
 
349
  def generate_music_and_state(input_midi, num_prime_tokens, num_gen_tokens, num_mem_tokens,
350
  model_temperature, final_composition, generated_batches, block_lines):
 
130
  )
131
  return (16000, midi_audio), midi_plot, fname + '.mid', time_val
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  # -----------------------------
134
  # MIDI PROCESSING FUNCTIONS
135
  # -----------------------------
136
  def load_midi(input_midi):
137
+ """Process the input MIDI file and create a token sequence."""
138
  raw_score = TMIDIX.midi2single_track_ms_score(input_midi.name)
139
 
140
  escore_notes = TMIDIX.advanced_score_processor(raw_score, return_enhanced_score_notes=True, apply_sustain=True)
 
186
  dur_vel = (8 * dur) + velocity
187
 
188
  melody_chords.extend([pat_ptc+256, dur_vel+16768])
 
 
189
 
190
  return melody_chords
191
 
 
193
  return [18816]
194
 
195
  def save_midi(tokens):
196
+ """Convert token sequence back to a MIDI score and write it using TMIDIX.
 
197
  """
198
 
199
  time = 0
 
210
 
211
  song_f = []
212
 
 
 
213
  for ss in tokens:
214
 
215
  if 0 <= ss < 256:
 
287
  )
288
 
289
  outputs = []
 
 
 
290
 
291
  print("Done!")
292
  print_sep()
293
+ return out.tolist(
294
 
295
  def generate_music_and_state(input_midi, num_prime_tokens, num_gen_tokens, num_mem_tokens,
296
  model_temperature, final_composition, generated_batches, block_lines):