asigalov61 commited on
Commit
aa2c141
·
verified ·
1 Parent(s): 25c9433

Upload TMIDIX.py

Browse files
Files changed (1) hide show
  1. TMIDIX.py +88 -15
TMIDIX.py CHANGED
@@ -51,7 +51,7 @@ r'''############################################################################
51
 
52
  ###################################################################################
53
 
54
- __version__ = "25.5.2"
55
 
56
  print('=' * 70)
57
  print('TMIDIX Python module')
@@ -1488,6 +1488,7 @@ from itertools import groupby
1488
 
1489
  from collections import Counter
1490
  from collections import defaultdict
 
1491
 
1492
  from operator import itemgetter
1493
 
@@ -1510,6 +1511,8 @@ import shutil
1510
 
1511
  import hashlib
1512
 
 
 
1513
  ###################################################################################
1514
  #
1515
  # Original TMIDI Tegridy helper functions
@@ -3862,7 +3865,10 @@ def chordify_score(score,
3862
  else:
3863
  return None
3864
 
3865
- def fix_monophonic_score_durations(monophonic_score):
 
 
 
3866
 
3867
  fixed_score = []
3868
 
@@ -3874,15 +3880,17 @@ def fix_monophonic_score_durations(monophonic_score):
3874
  nmt = monophonic_score[i+1][1]
3875
 
3876
  if note[1]+note[2] >= nmt:
3877
- note_dur = max(1, nmt-note[1]-1)
3878
  else:
3879
  note_dur = note[2]
3880
 
3881
  new_note = [note[0], note[1], note_dur] + note[3:]
3882
-
3883
- fixed_score.append(new_note)
3884
-
3885
- fixed_score.append(monophonic_score[-1])
 
 
3886
 
3887
  elif type(monophonic_score[0][0]) == int:
3888
 
@@ -3892,15 +3900,17 @@ def fix_monophonic_score_durations(monophonic_score):
3892
  nmt = monophonic_score[i+1][0]
3893
 
3894
  if note[0]+note[1] >= nmt:
3895
- note_dur = max(1, nmt-note[0]-1)
3896
  else:
3897
  note_dur = note[1]
3898
-
3899
  new_note = [note[0], note_dur] + note[2:]
3900
-
3901
- fixed_score.append(new_note)
3902
-
3903
- fixed_score.append(monophonic_score[-1])
 
 
3904
 
3905
  return fixed_score
3906
 
@@ -12933,7 +12943,7 @@ def find_next(pitches, cur_ptc):
12933
 
12934
  ###################################################################################
12935
 
12936
- def ordered_groups(data, key_index):
12937
 
12938
  def keyfunc(sublist):
12939
  return sublist[key_index]
@@ -12947,9 +12957,25 @@ def ordered_groups(data, key_index):
12947
 
12948
  ###################################################################################
12949
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12950
  def merge_melody_notes(escore_notes, pitches_idx=4, max_dur=255):
12951
 
12952
- groups = ordered_groups(escore_notes, pitches_idx)
12953
 
12954
  merged_melody_notes = []
12955
 
@@ -13045,6 +13071,53 @@ def add_expressive_melody_to_enhanced_score_notes(escore_notes,
13045
  return song_f
13046
 
13047
  ###################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13048
 
13049
  print('Module loaded!')
13050
  print('=' * 70)
 
51
 
52
  ###################################################################################
53
 
54
+ __version__ = "25.5.4"
55
 
56
  print('=' * 70)
57
  print('TMIDIX Python module')
 
1488
 
1489
  from collections import Counter
1490
  from collections import defaultdict
1491
+ from collections import OrderedDict
1492
 
1493
  from operator import itemgetter
1494
 
 
1511
 
1512
  import hashlib
1513
 
1514
+ from array import array
1515
+
1516
  ###################################################################################
1517
  #
1518
  # Original TMIDI Tegridy helper functions
 
3865
  else:
3866
  return None
3867
 
3868
+ def fix_monophonic_score_durations(monophonic_score,
3869
+ notes_min_gap=1,
3870
+ min_notes_dur=1
3871
+ ):
3872
 
3873
  fixed_score = []
3874
 
 
3880
  nmt = monophonic_score[i+1][1]
3881
 
3882
  if note[1]+note[2] >= nmt:
3883
+ note_dur = max(1, nmt-note[1]-notes_min_gap)
3884
  else:
3885
  note_dur = note[2]
3886
 
3887
  new_note = [note[0], note[1], note_dur] + note[3:]
3888
+
3889
+ if new_note[2] >= min_notes_dur:
3890
+ fixed_score.append(new_note)
3891
+
3892
+ if monophonic_score[-1][2] >= min_notes_dur:
3893
+ fixed_score.append(monophonic_score[-1])
3894
 
3895
  elif type(monophonic_score[0][0]) == int:
3896
 
 
3900
  nmt = monophonic_score[i+1][0]
3901
 
3902
  if note[0]+note[1] >= nmt:
3903
+ note_dur = max(1, nmt-note[0]-notes_min_gap)
3904
  else:
3905
  note_dur = note[1]
3906
+
3907
  new_note = [note[0], note_dur] + note[2:]
3908
+
3909
+ if new_note[1] >= min_notes_dur:
3910
+ fixed_score.append(new_note)
3911
+
3912
+ if monophonic_score[-1][1] >= min_notes_dur:
3913
+ fixed_score.append(monophonic_score[-1])
3914
 
3915
  return fixed_score
3916
 
 
12943
 
12944
  ###################################################################################
12945
 
12946
+ def ordered_groups_unsorted(data, key_index):
12947
 
12948
  def keyfunc(sublist):
12949
  return sublist[key_index]
 
12957
 
12958
  ###################################################################################
12959
 
12960
+ def ordered_groups(data, key_index):
12961
+
12962
+ groups = OrderedDict()
12963
+
12964
+ for sublist in data:
12965
+ key = sublist[key_index]
12966
+
12967
+ if key not in groups:
12968
+ groups[key] = []
12969
+
12970
+ groups[key].append(sublist)
12971
+
12972
+ return list(groups.items())
12973
+
12974
+ ###################################################################################
12975
+
12976
  def merge_melody_notes(escore_notes, pitches_idx=4, max_dur=255):
12977
 
12978
+ groups = ordered_groups_unsorted(escore_notes, pitches_idx)
12979
 
12980
  merged_melody_notes = []
12981
 
 
13071
  return song_f
13072
 
13073
  ###################################################################################
13074
+
13075
+ def int_list_md5_hash(int_list):
13076
+
13077
+ arr = array('H', int_list)
13078
+ binary_data = arr.tobytes()
13079
+
13080
+ return hashlib.md5(binary_data).hexdigest()
13081
+
13082
+ ###################################################################################
13083
+
13084
+ def merge_escore_notes_durations(escore_notes,
13085
+ notes_min_gap=1,
13086
+ min_notes_dur=2,
13087
+ times_idx=1,
13088
+ durs_idx=2,
13089
+ channels_idx = 3,
13090
+ pitches_idx=4
13091
+ ):
13092
+
13093
+ notes = [e for e in escore_notes if e[channels_idx] != 9]
13094
+ drums = [e for e in escore_notes if e[channels_idx] == 9]
13095
+
13096
+ escore_groups = ordered_groups(notes, pitches_idx)
13097
+
13098
+ merged_score = []
13099
+
13100
+ for k, g in escore_groups:
13101
+ if len(g) > 2:
13102
+ fg = fix_monophonic_score_durations(g,
13103
+ notes_min_gap=notes_min_gap,
13104
+ min_notes_dur=min_notes_dur
13105
+ )
13106
+ merged_score.extend(fg)
13107
+
13108
+ elif len(g) == 2:
13109
+
13110
+ if g[0][times_idx]+g[0][durs_idx] >= g[1][times_idx]:
13111
+ g[0][durs_idx] = max(1, g[1][times_idx] - g[0][times_idx] - 1)
13112
+
13113
+ merged_score.extend(g)
13114
+
13115
+ else:
13116
+ merged_score.extend(g)
13117
+
13118
+ return sorted(merged_score + drums, key=lambda x: x[times_idx])
13119
+
13120
+ ###################################################################################
13121
 
13122
  print('Module loaded!')
13123
  print('=' * 70)