asigalov61 commited on
Commit
b05e64c
·
verified ·
1 Parent(s): 19d483f

Upload TMIDIX.py

Browse files
Files changed (1) hide show
  1. TMIDIX.py +182 -3
TMIDIX.py CHANGED
@@ -51,7 +51,7 @@ r'''############################################################################
51
 
52
  ###################################################################################
53
 
54
- __version__ = "26.2.17"
55
 
56
  print('=' * 70)
57
  print('TMIDIX Python module')
@@ -16439,11 +16439,11 @@ def humanize_velocities_in_escore_notes(escore_notes):
16439
 
16440
  ###################################################################################
16441
 
16442
- def most_common_ordered_set(values):
16443
 
16444
  freq = Counter(values)
16445
 
16446
- top_vals = {v for v, _ in freq.most_common()}
16447
 
16448
  result = []
16449
  seen = set()
@@ -16452,6 +16452,8 @@ def most_common_ordered_set(values):
16452
  if v in top_vals and v not in seen:
16453
  result.append(v)
16454
  seen.add(v)
 
 
16455
 
16456
  return result
16457
 
@@ -16479,6 +16481,183 @@ def escore_notes_velocities(escore_notes, chan_idx=3, vels_idx=5):
16479
 
16480
  ###################################################################################
16481
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16482
  print('Module loaded!')
16483
  print('=' * 70)
16484
  print('Enjoy! :)')
 
51
 
52
  ###################################################################################
53
 
54
+ __version__ = "26.2.27"
55
 
56
  print('=' * 70)
57
  print('TMIDIX Python module')
 
16439
 
16440
  ###################################################################################
16441
 
16442
+ def most_common_ordered_set(values, top_k):
16443
 
16444
  freq = Counter(values)
16445
 
16446
+ top_vals = {v for v, _ in freq.most_common(top_k)}
16447
 
16448
  result = []
16449
  seen = set()
 
16452
  if v in top_vals and v not in seen:
16453
  result.append(v)
16454
  seen.add(v)
16455
+ if len(result) >= top_k:
16456
+ break
16457
 
16458
  return result
16459
 
 
16481
 
16482
  ###################################################################################
16483
 
16484
+ Patch2octave = {
16485
+ 'Acoustic Grand': 60,
16486
+ 'Bright Acoustic': 60,
16487
+ 'Electric Grand': 60,
16488
+ 'Honky-Tonk': 60,
16489
+ 'Electric Piano 1': 60,
16490
+ 'Electric Piano 2': 60,
16491
+ 'Harpsichord': 60,
16492
+ 'Clav': 60,
16493
+ 'Celesta': 72,
16494
+ 'Glockenspiel': 84,
16495
+ 'Music Box': 72,
16496
+ 'Vibraphone': 60,
16497
+ 'Marimba': 48,
16498
+ 'Xylophone': 72,
16499
+ 'Tubular Bells': 72,
16500
+ 'Dulcimer': 72,
16501
+ 'Drawbar Organ': 60,
16502
+ 'Percussive Organ': 60,
16503
+ 'Rock Organ': 60,
16504
+ 'Church Organ': 48,
16505
+ 'Reed Organ': 60,
16506
+ 'Accordion': 60,
16507
+ 'Harmonica': 60,
16508
+ 'Tango Accordion': 60,
16509
+ 'Acoustic Guitar(nylon)': 48,
16510
+ 'Acoustic Guitar(steel)': 48,
16511
+ 'Electric Guitar(jazz)': 48,
16512
+ 'Electric Guitar(clean)': 48,
16513
+ 'Electric Guitar(muted)': 48,
16514
+ 'Overdriven Guitar': 48,
16515
+ 'Distortion Guitar': 48,
16516
+ 'Guitar Harmonics': 60,
16517
+ 'Acoustic Bass': 36,
16518
+ 'Electric Bass(finger)': 36,
16519
+ 'Electric Bass(pick)': 36,
16520
+ 'Fretless Bass': 36,
16521
+ 'Slap Bass 1': 36,
16522
+ 'Slap Bass 2': 36,
16523
+ 'Synth Bass 1': 36,
16524
+ 'Synth Bass 2': 36,
16525
+ 'Violin': 72,
16526
+ 'Viola': 60,
16527
+ 'Cello': 48,
16528
+ 'Contrabass': 36,
16529
+ 'Tremolo Strings': 60,
16530
+ 'Pizzicato Strings': 60,
16531
+ 'Orchestral Harp': 60,
16532
+ 'Timpani': 36,
16533
+ 'String Ensemble 1': 60,
16534
+ 'String Ensemble 2': 60,
16535
+ 'SynthStrings 1': 60,
16536
+ 'SynthStrings 2': 60,
16537
+ 'Choir Aahs': 60,
16538
+ 'Voice Oohs': 60,
16539
+ 'Synth Voice': 60,
16540
+ 'Orchestra Hit': 60,
16541
+ 'Trumpet': 60,
16542
+ 'Trombone': 48,
16543
+ 'Tuba': 36,
16544
+ 'Muted Trumpet': 60,
16545
+ 'French Horn': 48,
16546
+ 'Brass Section': 48,
16547
+ 'SynthBrass 1': 60,
16548
+ 'SynthBrass 2': 60,
16549
+ 'Soprano Sax': 72,
16550
+ 'Alto Sax': 60,
16551
+ 'Tenor Sax': 48,
16552
+ 'Baritone Sax': 36,
16553
+ 'Oboe': 72,
16554
+ 'English Horn': 60,
16555
+ 'Bassoon': 48,
16556
+ 'Clarinet': 60,
16557
+ 'Piccolo': 84,
16558
+ 'Flute': 72,
16559
+ 'Recorder': 72,
16560
+ 'Pan Flute': 72,
16561
+ 'Blown Bottle': 60,
16562
+ 'Skakuhachi': 60,
16563
+ 'Whistle': 72,
16564
+ 'Ocarina': 60,
16565
+ 'Lead 1 (square)': 60,
16566
+ 'Lead 2 (sawtooth)': 60,
16567
+ 'Lead 3 (calliope)': 60,
16568
+ 'Lead 4 (chiff)': 60,
16569
+ 'Lead 5 (charang)': 60,
16570
+ 'Lead 6 (voice)': 60,
16571
+ 'Lead 7 (fifths)': 60,
16572
+ 'Lead 8 (bass+lead)': 60,
16573
+ 'Pad 1 (new age)': 60,
16574
+ 'Pad 2 (warm)': 60,
16575
+ 'Pad 3 (polysynth)': 60,
16576
+ 'Pad 4 (choir)': 60,
16577
+ 'Pad 5 (bowed)': 60,
16578
+ 'Pad 6 (metallic)': 60,
16579
+ 'Pad 7 (halo)': 60,
16580
+ 'Pad 8 (sweep)': 60,
16581
+ 'FX 1 (rain)': 72,
16582
+ 'FX 2 (soundtrack)': 72,
16583
+ 'FX 3 (crystal)': 72,
16584
+ 'FX 4 (atmosphere)': 72,
16585
+ 'FX 5 (brightness)': 72,
16586
+ 'FX 6 (goblins)': 72,
16587
+ 'FX 7 (echoes)': 72,
16588
+ 'FX 8 (sci-fi)': 72,
16589
+ 'Sitar': 60,
16590
+ 'Banjo': 60,
16591
+ 'Shamisen': 60,
16592
+ 'Koto': 60,
16593
+ 'Kalimba': 60,
16594
+ 'Bagpipe': 60,
16595
+ 'Fiddle': 72,
16596
+ 'Shanai': 60,
16597
+ 'Tinkle Bell': 84,
16598
+ 'Agogo': 60,
16599
+ 'Steel Drums': 72,
16600
+ 'Woodblock': 72,
16601
+ 'Taiko Drum': 36,
16602
+ 'Melodic Tom': 48,
16603
+ 'Synth Drum': 48,
16604
+ 'Reverse Cymbal': 72,
16605
+ 'Guitar Fret Noise': 60,
16606
+ 'Breath Noise': 60,
16607
+ 'Seashore': 60,
16608
+ 'Bird Tweet': 84,
16609
+ 'Telephone Ring': 72,
16610
+ 'Helicopter': 60,
16611
+ 'Applause': 60,
16612
+ 'Gunshot': 60
16613
+ }
16614
+
16615
+ ###################################################################################
16616
+
16617
+ reverse_dict_grouped = lambda dic: {v: [k for k, _v in dic.items() if _v == v] for v in set(dic.values())}
16618
+
16619
+ ###################################################################################
16620
+
16621
+ reverse_dict = lambda dic: {v: k for k, v in dic.items()}
16622
+
16623
+ ###################################################################################
16624
+
16625
+ def trim_list_trail_range(lst, low, high):
16626
+ return lst[: next((i for i in range(len(lst)-1, -1, -1) if low <= lst[i] <= high), -1) + 1]
16627
+
16628
+ ###################################################################################
16629
+
16630
+ def merge_text_files(files,
16631
+ output_path,
16632
+ title,
16633
+ sep_char='=',
16634
+ sep_len=120,
16635
+ verbose=False
16636
+ ):
16637
+
16638
+ sep = sep_char * sep_len
16639
+
16640
+ if os.path.exists(output_path):
16641
+ os.remove(output_path)
16642
+
16643
+ with open(output_path, "w", encoding="utf-8") as out:
16644
+ out.write(f"{sep} {title} {sep}\n\n")
16645
+
16646
+ for path in files:
16647
+ name = os.path.basename(path)
16648
+ out.write(f"{sep} {name} {sep}\n\n")
16649
+
16650
+ with open(path, "r", encoding="utf-8") as inp:
16651
+ for line in inp:
16652
+ out.write(line.rstrip("\n") + "\n")
16653
+
16654
+ out.write("\n")
16655
+
16656
+ if verbose:
16657
+ print(f"Merged {len(files)} files into {output_path}")
16658
+
16659
+ ###################################################################################
16660
+
16661
  print('Module loaded!')
16662
  print('=' * 70)
16663
  print('Enjoy! :)')