asigalov61 commited on
Commit
7019974
·
verified ·
1 Parent(s): 165385c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -78
app.py CHANGED
@@ -235,6 +235,91 @@ def read_MIDI(input_midi):
235
 
236
  # =================================================================================================
237
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
 
239
  @spaces.GPU
240
  def CompareMIDIs(input_midi, input_num_of_notes, input_patch_number):
@@ -320,85 +405,7 @@ def CompareMIDIs(input_midi, input_num_of_notes, input_patch_number):
320
  print('=' * 70)
321
 
322
  #===============================================================================
323
- print('Rendering results...')
324
-
325
- print('=' * 70)
326
- print('Sample INTs', out2[:12])
327
- print('=' * 70)
328
-
329
- if len(out2) != 0:
330
-
331
- song = out2
332
- song_f = []
333
-
334
- time = 0
335
- dur = 0
336
- vel = 90
337
- pitch = 0
338
- channel = 0
339
-
340
- patches = [-1] * 16
341
-
342
- channels = [0] * 16
343
- channels[9] = 1
344
-
345
- for ss in song:
346
-
347
- if 0 <= ss < 256:
348
-
349
- time += ss * 16
350
-
351
- if 256 <= ss < 2304:
352
-
353
- dur = ((ss-256) // 8) * 16
354
- vel = (((ss-256) % 8)+1) * 15
355
-
356
- if 2304 <= ss < 18945:
357
-
358
- patch = (ss-2304) // 129
359
-
360
- if patch < 128:
361
-
362
- if patch not in patches:
363
- if 0 in channels:
364
- cha = channels.index(0)
365
- channels[cha] = 1
366
- else:
367
- cha = 15
368
-
369
- patches[cha] = patch
370
- channel = patches.index(patch)
371
- else:
372
- channel = patches.index(patch)
373
-
374
- if patch == 128:
375
- channel = 9
376
-
377
- pitch = (ss-2304) % 129
378
-
379
- song_f.append(['note', time, dur, channel, pitch, vel, patch ])
380
 
381
- patches = [0 if x==-1 else x for x in patches]
382
-
383
- detailed_stats = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(song_f,
384
- output_signature = 'Giant Music Transformer',
385
- output_file_name = fn1,
386
- track_name='Project Los Angeles',
387
- list_of_MIDI_patches=patches
388
- )
389
-
390
- new_fn = fn1+'.mid'
391
-
392
-
393
- audio = midi_to_colab_audio(new_fn,
394
- soundfont_path=soundfont,
395
- sample_rate=16000,
396
- volume_scale=10,
397
- output_for_gradio=True
398
- )
399
-
400
- print('Done!')
401
- print('=' * 70)
402
 
403
  #========================================================
404
 
 
235
 
236
  # =================================================================================================
237
 
238
+ def tokens_to_MIDI(tokens, MIDI_name):
239
+
240
+ print('Rendering results...')
241
+
242
+ print('=' * 70)
243
+ print('Sample INTs', tokens[:12])
244
+ print('=' * 70)
245
+
246
+ if len(tokens) != 0:
247
+
248
+ song = tokens
249
+ song_f = []
250
+
251
+ time = 0
252
+ dur = 0
253
+ vel = 90
254
+ pitch = 0
255
+ channel = 0
256
+
257
+ patches = [-1] * 16
258
+
259
+ channels = [0] * 16
260
+ channels[9] = 1
261
+
262
+ for ss in song:
263
+
264
+ if 0 <= ss < 256:
265
+
266
+ time += ss * 16
267
+
268
+ if 256 <= ss < 2304:
269
+
270
+ dur = ((ss-256) // 8) * 16
271
+ vel = (((ss-256) % 8)+1) * 15
272
+
273
+ if 2304 <= ss < 18945:
274
+
275
+ patch = (ss-2304) // 129
276
+
277
+ if patch < 128:
278
+
279
+ if patch not in patches:
280
+ if 0 in channels:
281
+ cha = channels.index(0)
282
+ channels[cha] = 1
283
+ else:
284
+ cha = 15
285
+
286
+ patches[cha] = patch
287
+ channel = patches.index(patch)
288
+ else:
289
+ channel = patches.index(patch)
290
+
291
+ if patch == 128:
292
+ channel = 9
293
+
294
+ pitch = (ss-2304) % 129
295
+
296
+ song_f.append(['note', time, dur, channel, pitch, vel, patch ])
297
+
298
+ patches = [0 if x==-1 else x for x in patches]
299
+
300
+ detailed_stats = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(song_f,
301
+ output_signature = 'Intelligent MIDI Comparator',
302
+ output_file_name = MIDI_name,
303
+ track_name='Project Los Angeles',
304
+ list_of_MIDI_patches=patches
305
+ )
306
+
307
+ new_fn = MIDI_name+'.mid'
308
+
309
+
310
+ audio = midi_to_colab_audio(new_fn,
311
+ soundfont_path=soundfont,
312
+ sample_rate=16000,
313
+ volume_scale=10,
314
+ output_for_gradio=True
315
+ )
316
+
317
+ print('Done!')
318
+ print('=' * 70)
319
+
320
+ return audio, new_fn
321
+
322
+ # =================================================================================================
323
 
324
  @spaces.GPU
325
  def CompareMIDIs(input_midi, input_num_of_notes, input_patch_number):
 
405
  print('=' * 70)
406
 
407
  #===============================================================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
408
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
409
 
410
  #========================================================
411