asigalov61 commited on
Commit
14bc3eb
·
verified ·
1 Parent(s): 6db317f

Upload TMIDIX.py

Browse files
Files changed (1) hide show
  1. TMIDIX.py +100 -0
TMIDIX.py CHANGED
@@ -8423,6 +8423,106 @@ def proportions_counter(list_of_values):
8423
 
8424
  return [[c[0], c[1], c[1] / clen] for c in counts]
8425
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8426
  ###################################################################################
8427
  #
8428
  # This is the end of the TMIDI X Python module
 
8423
 
8424
  return [[c[0], c[1], c[1] / clen] for c in counts]
8425
 
8426
+ ###################################################################################
8427
+
8428
+ def smooth_escore_notes(escore_notes):
8429
+
8430
+ values = [e[4] % 24 for e in escore_notes]
8431
+
8432
+ smoothed = [values[0]]
8433
+
8434
+ for i in range(1, len(values)):
8435
+ if abs(smoothed[-1] - values[i]) >= 12:
8436
+ if smoothed[-1] < values[i]:
8437
+ smoothed.append(values[i] - 12)
8438
+ else:
8439
+ smoothed.append(values[i] + 12)
8440
+ else:
8441
+ smoothed.append(values[i])
8442
+
8443
+ smoothed_score = copy.deepcopy(escore_notes)
8444
+
8445
+ for i, e in enumerate(smoothed_score):
8446
+ esn_octave = escore_notes[i][4] // 12
8447
+ e[4] = (esn_octave * 12) + smoothed[i]
8448
+
8449
+ return smoothed_score
8450
+
8451
+ ###################################################################################
8452
+
8453
+ def add_base_to_escore_notes(escore_notes,
8454
+ base_octave=2,
8455
+ base_channel=2,
8456
+ base_patch=35,
8457
+ base_max_velocity=120,
8458
+ return_base=False
8459
+ ):
8460
+
8461
+
8462
+ score = copy.deepcopy(escore_notes)
8463
+
8464
+ cscore = chordify_score([1000, score])
8465
+
8466
+ base_score = []
8467
+
8468
+ for c in cscore:
8469
+ chord = sorted([e for e in c if e[3] != 9], key=lambda x: x[4], reverse=True)
8470
+ base_score.append(chord[-1])
8471
+
8472
+ base_score = smooth_escore_notes(base_score)
8473
+
8474
+ for e in base_score:
8475
+ e[3] = base_channel
8476
+ e[4] = (base_octave * 12) + (e[4] % 12)
8477
+ e[5] = e[4]
8478
+ e[6] = base_patch
8479
+
8480
+ adjust_score_velocities(base_score, base_max_velocity)
8481
+
8482
+ if return_base:
8483
+ final_score = sorted(base_score, key=lambda x: (x[1], -x[4], x[6]))
8484
+
8485
+ else:
8486
+ final_score = sorted(escore_notes + base_score, key=lambda x: (x[1], -x[4], x[6]))
8487
+
8488
+ return final_score
8489
+
8490
+ ###################################################################################
8491
+
8492
+ def add_drums_to_escore_notes(escore_notes,
8493
+ heavy_drums_pitches=[36, 38, 47],
8494
+ heavy_drums_velocity=110,
8495
+ light_drums_pitches=[51, 54],
8496
+ light_drums_velocity=127,
8497
+ drums_max_velocity=127,
8498
+ drums_ratio_time_divider=4,
8499
+ return_drums=False
8500
+ ):
8501
+
8502
+ score = copy.deepcopy([e for e in escore_notes if e[3] != 9])
8503
+
8504
+ cscore = chordify_score([1000, score])
8505
+
8506
+ drums_score = []
8507
+
8508
+ for c in cscore:
8509
+ min_dur = max(1, min([e[2] for e in c]))
8510
+ if not (c[0][1] % drums_ratio_time_divider):
8511
+ drum_note = ['note', c[0][1], min_dur, 9, heavy_drums_pitches[c[0][4] % len(heavy_drums_pitches)], heavy_drums_velocity, 128]
8512
+ else:
8513
+ drum_note = ['note', c[0][1], min_dur, 9, light_drums_pitches[c[0][4] % len(light_drums_pitches)], light_drums_velocity, 128]
8514
+ drums_score.append(drum_note)
8515
+
8516
+ adjust_score_velocities(drums_score, drums_max_velocity)
8517
+
8518
+ if return_drums:
8519
+ final_score = sorted(drums_score, key=lambda x: (x[1], -x[4], x[6]))
8520
+
8521
+ else:
8522
+ final_score = sorted(score + drums_score, key=lambda x: (x[1], -x[4], x[6]))
8523
+
8524
+ return final_score
8525
+
8526
  ###################################################################################
8527
  #
8528
  # This is the end of the TMIDI X Python module