asigalov61
commited on
Commit
•
f3a0ea5
1
Parent(s):
19b530f
Update app.py
Browse files
app.py
CHANGED
@@ -160,6 +160,8 @@ if __name__ == "__main__":
|
|
160 |
print('App start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
161 |
print('=' * 70)
|
162 |
|
|
|
|
|
163 |
soundfont = "SGM-v2.01-YamahaGrand-Guit-Bass-v2.7.sf2"
|
164 |
|
165 |
print('=' * 70)
|
@@ -171,6 +173,140 @@ if __name__ == "__main__":
|
|
171 |
print('Done!')
|
172 |
print('=' * 70)
|
173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
app = gr.Blocks()
|
175 |
with app:
|
176 |
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>Chords Progressions Generator</h1>")
|
|
|
160 |
print('App start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
161 |
print('=' * 70)
|
162 |
|
163 |
+
#===============================================================================
|
164 |
+
|
165 |
soundfont = "SGM-v2.01-YamahaGrand-Guit-Bass-v2.7.sf2"
|
166 |
|
167 |
print('=' * 70)
|
|
|
173 |
print('Done!')
|
174 |
print('=' * 70)
|
175 |
|
176 |
+
#===============================================================================
|
177 |
+
|
178 |
+
minimum_chords_chunk_length = 4 # @param {"type":"slider","min":4,"max":8,"step":1}
|
179 |
+
chords_chunks_overlap_value = 4 # @param {"type":"slider","min":2,"max":8,"step":1}
|
180 |
+
|
181 |
+
print('=' * 70)
|
182 |
+
print('Selecting chords chunks...')
|
183 |
+
print('=' * 70)
|
184 |
+
|
185 |
+
chunk_size = minimum_chords_chunk_length
|
186 |
+
|
187 |
+
long_chords_chunks = []
|
188 |
+
|
189 |
+
for c in tqdm(good_chords_chunks):
|
190 |
+
if chunk_size + chords_chunks_overlap_value <= len(c):
|
191 |
+
long_chords_chunks.append(c)
|
192 |
+
|
193 |
+
print('Done!')
|
194 |
+
print('=' * 70)
|
195 |
+
print('Selected chords chunks of minimum length:', minimum_chords_chunk_length+chords_chunks_overlap_value)
|
196 |
+
print('=' * 70)
|
197 |
+
print('Total number of selected chord chunks:', len(long_chords_chunks))
|
198 |
+
print('=' * 70)
|
199 |
+
|
200 |
+
chords_chunks_multiplicatrion_factor = 6 # @param {"type":"slider","min":1,"max":6,"step":1}
|
201 |
+
|
202 |
+
#===============================================================================
|
203 |
+
# Helper chord function
|
204 |
+
#===============================================================================
|
205 |
+
|
206 |
+
def check_chord(chord):
|
207 |
+
|
208 |
+
tones_chord = sorted(set([p % 12 for p in chord]))
|
209 |
+
|
210 |
+
new_tones_chord = []
|
211 |
+
|
212 |
+
if 0 in tones_chord and 11 in tones_chord:
|
213 |
+
tones_chord.remove(11)
|
214 |
+
|
215 |
+
for t in tones_chord:
|
216 |
+
if t+1 in tones_chord:
|
217 |
+
tones_chord.remove(t+1)
|
218 |
+
if t-1 in tones_chord:
|
219 |
+
tones_chord.remove(t-1)
|
220 |
+
|
221 |
+
new_chord = tuple()
|
222 |
+
|
223 |
+
for p in chord:
|
224 |
+
if p % 12 in tones_chord:
|
225 |
+
new_chord += tuple([p])
|
226 |
+
|
227 |
+
if len(new_chord) > 2:
|
228 |
+
return new_chord
|
229 |
+
|
230 |
+
else:
|
231 |
+
return None
|
232 |
+
|
233 |
+
#===============================================================================
|
234 |
+
|
235 |
+
print('=' * 70)
|
236 |
+
print('Multiplying chords chunks...')
|
237 |
+
print('=' * 70)
|
238 |
+
print('Chords chunks will be multiplied', chords_chunks_multiplicatrion_factor * 2, 'times' )
|
239 |
+
print('=' * 70)
|
240 |
+
|
241 |
+
long_chords_chunks_mult = set()
|
242 |
+
|
243 |
+
for c in tqdm(long_chords_chunks):
|
244 |
+
|
245 |
+
for tv in range(-chords_chunks_multiplicatrion_factor, chords_chunks_multiplicatrion_factor):
|
246 |
+
gc = []
|
247 |
+
for cc in c:
|
248 |
+
chord = [max(1, min(127, p+tv)) for p in cc]
|
249 |
+
checked_chord = check_chord(chord)
|
250 |
+
if checked_chord is not None:
|
251 |
+
gc.append(checked_chord)
|
252 |
+
if len(gc) == len(c) or (len(gc) >= chunk_size + chords_chunks_overlap_value and gc == c[:len(gc)]) or (len(gc) >= chunk_size + chords_chunks_overlap_value and gc == c[len(gc):]):
|
253 |
+
long_chords_chunks_mult.add(tuple(gc))
|
254 |
+
|
255 |
+
print('Done!')
|
256 |
+
print('=' * 70)
|
257 |
+
print('Total number of multiplied chords chunks:', len(long_chords_chunks_mult))
|
258 |
+
print('=' * 70)
|
259 |
+
|
260 |
+
#===============================================================================
|
261 |
+
|
262 |
+
print('=' * 70)
|
263 |
+
print('Creating chords dictionary...')
|
264 |
+
print('=' * 70)
|
265 |
+
|
266 |
+
long_tones_chords_dict = set()
|
267 |
+
|
268 |
+
for a in tqdm(long_chords_chunks_mult):
|
269 |
+
for aa in a:
|
270 |
+
tones_chord = tuple(sorted(set([p % 12 for p in aa])))
|
271 |
+
long_tones_chords_dict.add(tones_chord)
|
272 |
+
|
273 |
+
long_tones_chords_dict = list(long_tones_chords_dict)
|
274 |
+
|
275 |
+
print('=' * 70)
|
276 |
+
print('Resulting chords dictionary size:', len(long_tones_chords_dict))
|
277 |
+
print('=' * 70)
|
278 |
+
print('Preparing chords chunks...')
|
279 |
+
print('=' * 70)
|
280 |
+
|
281 |
+
all_long_chords_tokens_chunks = []
|
282 |
+
all_long_good_chords_chunks = []
|
283 |
+
|
284 |
+
for a in tqdm(long_chords_chunks_mult):
|
285 |
+
|
286 |
+
chunk = []
|
287 |
+
|
288 |
+
for aa in a:
|
289 |
+
|
290 |
+
tones_chord = tuple(sorted(set([p % 12 for p in aa])))
|
291 |
+
chunk.append(long_tones_chords_dict.index(tones_chord))
|
292 |
+
|
293 |
+
if chunk:
|
294 |
+
all_long_chords_tokens_chunks.append(chunk)
|
295 |
+
all_long_good_chords_chunks.append(a)
|
296 |
+
|
297 |
+
print('Done!')
|
298 |
+
print('=' * 70)
|
299 |
+
print('Loading chords chunks...')
|
300 |
+
|
301 |
+
src_long_chunks = np.array([a[:chunk_size] for a in all_long_chords_tokens_chunks])
|
302 |
+
|
303 |
+
print('Done!')
|
304 |
+
print('=' * 70)
|
305 |
+
print('Total chords chunks count:', len(all_long_good_chords_chunks))
|
306 |
+
print('=' * 70)
|
307 |
+
|
308 |
+
#===============================================================================
|
309 |
+
|
310 |
app = gr.Blocks()
|
311 |
with app:
|
312 |
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>Chords Progressions Generator</h1>")
|