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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py CHANGED
@@ -130,6 +130,47 @@ def render_midi_output(final_composition):
130
  )
131
  return (16000, midi_audio), midi_plot, fname + '.mid', time_val
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  # -----------------------------
134
  # MIDI PROCESSING FUNCTIONS
135
  # -----------------------------
 
130
  )
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
  # -----------------------------