asigalov61 commited on
Commit
6e5ba03
·
verified ·
1 Parent(s): d67e599

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -30
app.py CHANGED
@@ -131,46 +131,51 @@ def render_midi_output(final_composition):
131
  return (16000, midi_audio), midi_plot, fname + '.mid', time_val
132
 
133
  def remove_duplicate_pitches(tokens):
134
-
135
  chords = []
136
- cho = []
137
-
138
- for t in tokens:
139
- if t < 256:
140
- if cho:
141
- chords.append(cho)
 
 
 
 
 
 
 
 
142
 
143
- cho = [t]
 
 
144
 
145
- else:
146
- cho.append(t)
147
-
148
- if cho:
149
- chords.append(cho)
150
 
151
- checked_tokens = []
152
 
153
- for c in chords:
154
 
155
- tchord = [t for t in c if 256 < t < 18816]
 
 
 
 
 
 
 
 
 
 
156
 
157
- nchord = []
158
- seen = set()
159
 
160
- for i in range(0, len(tchord), 2):
161
- tup = tchord[i: i+2]
162
- if tup[0] not in seen:
163
- nchord.extend(tup)
164
- seen.add(tup[0])
165
 
166
- fchord = chords[0]
167
- fchord.extend(nchord)
168
- fchord.extend([t for t in c if c > 18815])
169
-
170
- checked_tokens.extend(fchord)
171
 
172
- return checked_tokens
173
-
174
  # -----------------------------
175
  # MIDI PROCESSING FUNCTIONS
176
  # -----------------------------
 
131
  return (16000, midi_audio), midi_plot, fname + '.mid', time_val
132
 
133
  def remove_duplicate_pitches(tokens):
134
+
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 t > 18815]
 
174
 
175
+ result.extend([header] + deduped + high_tokens)
 
 
 
 
176
 
177
+ return result
 
 
 
 
178
 
 
 
179
  # -----------------------------
180
  # MIDI PROCESSING FUNCTIONS
181
  # -----------------------------