Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
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 |
-
|
137 |
-
|
138 |
-
for
|
139 |
-
if
|
140 |
-
if
|
141 |
-
chords.append(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
-
|
|
|
|
|
144 |
|
145 |
-
|
146 |
-
cho.append(t)
|
147 |
-
|
148 |
-
if cho:
|
149 |
-
chords.append(cho)
|
150 |
|
151 |
-
|
152 |
|
153 |
-
|
154 |
|
155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
|
157 |
-
|
158 |
-
seen = set()
|
159 |
|
160 |
-
|
161 |
-
tup = tchord[i: i+2]
|
162 |
-
if tup[0] not in seen:
|
163 |
-
nchord.extend(tup)
|
164 |
-
seen.add(tup[0])
|
165 |
|
166 |
-
|
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 |
# -----------------------------
|