asigalov61 commited on
Commit
2f31222
·
verified ·
1 Parent(s): 04e14ea

Upload TMIDIX.py

Browse files
Files changed (1) hide show
  1. TMIDIX.py +89 -1
TMIDIX.py CHANGED
@@ -51,7 +51,7 @@ r'''############################################################################
51
 
52
  ###################################################################################
53
 
54
- __version__ = "25.8.29"
55
 
56
  print('=' * 70)
57
  print('TMIDIX Python module')
@@ -1500,6 +1500,9 @@ from difflib import SequenceMatcher as SM
1500
 
1501
  import statistics
1502
  import math
 
 
 
1503
 
1504
  import matplotlib.pyplot as plt
1505
 
@@ -14538,6 +14541,91 @@ def align_integer_lists(seq1, seq2):
14538
 
14539
  ###################################################################################
14540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14541
  print('Module loaded!')
14542
  print('=' * 70)
14543
  print('Enjoy! :)')
 
51
 
52
  ###################################################################################
53
 
54
+ __version__ = "25.8.30"
55
 
56
  print('=' * 70)
57
  print('TMIDIX Python module')
 
1500
 
1501
  import statistics
1502
  import math
1503
+ from math import gcd
1504
+
1505
+ from functools import reduce
1506
 
1507
  import matplotlib.pyplot as plt
1508
 
 
14541
 
14542
  ###################################################################################
14543
 
14544
+ def most_common_delta_time(escore_notes):
14545
+
14546
+ dscore = delta_score_notes(escore_notes)
14547
+
14548
+ dtimes = [t[1] for t in dscore if t[1] != 0]
14549
+
14550
+ cdtime, count = Counter(dtimes).most_common(1)[0]
14551
+
14552
+ return [cdtime, count / len(dtimes)]
14553
+
14554
+ ###################################################################################
14555
+
14556
+ def delta_tones(escore_notes,
14557
+ ptcs_idx=4
14558
+ ):
14559
+
14560
+ pitches = [p[ptcs_idx] for p in escore_notes]
14561
+ tones = [p % 12 for p in pitches]
14562
+
14563
+ return [b-a for a, b in zip(tones[:-1], tones[1:])]
14564
+
14565
+ ###################################################################################
14566
+
14567
+ def find_divisors(val,
14568
+ reverse=False
14569
+ ):
14570
+
14571
+ if val == 0:
14572
+ return []
14573
+
14574
+ n = abs(val)
14575
+ divisors = set()
14576
+
14577
+ for i in range(1, int(n**0.5) + 1):
14578
+ if n % i == 0:
14579
+ divisors.add(i)
14580
+ divisors.add(n // i)
14581
+
14582
+ return sorted(divisors, reverse=reverse)
14583
+
14584
+ ###################################################################################
14585
+
14586
+ def find_common_divisors(values,
14587
+ reverse=False
14588
+ ):
14589
+
14590
+ if not values:
14591
+ return []
14592
+
14593
+ non_zero = [abs(v) for v in values if v != 0]
14594
+ if not non_zero:
14595
+ return []
14596
+
14597
+ overall_gcd = reduce(gcd, non_zero)
14598
+
14599
+ divisors = set()
14600
+
14601
+ for i in range(1, int(overall_gcd**0.5) + 1):
14602
+ if overall_gcd % i == 0:
14603
+ divisors.add(i)
14604
+ divisors.add(overall_gcd // i)
14605
+
14606
+ return sorted(divisors, reverse=reverse)
14607
+
14608
+ ###################################################################################
14609
+
14610
+ def strings_dict(list_of_strings,
14611
+ verbose=False
14612
+ ):
14613
+
14614
+ str_set = set()
14615
+
14616
+ for st in tqdm.tqdm(list_of_strings, disable=not verbose):
14617
+ for cha in st:
14618
+ str_set.add(cha)
14619
+
14620
+ str_lst = sorted(str_set)
14621
+
14622
+ str_dic = dict(zip(str_lst, range(len(str_lst))))
14623
+ rev_str_dic = {v: k for k, v in str_dic.items()}
14624
+
14625
+ return str_dic, rev_str_dic
14626
+
14627
+ ###################################################################################
14628
+
14629
  print('Module loaded!')
14630
  print('=' * 70)
14631
  print('Enjoy! :)')