Spaces:
Running
on
Zero
Running
on
Zero
Upload TMIDIX.py
Browse files
TMIDIX.py
CHANGED
@@ -51,7 +51,7 @@ r'''############################################################################
|
|
51 |
|
52 |
###################################################################################
|
53 |
|
54 |
-
__version__ = "25.
|
55 |
|
56 |
print('=' * 70)
|
57 |
print('TMIDIX Python module')
|
@@ -12961,12 +12961,12 @@ def ordered_groups_unsorted(data, key_index):
|
|
12961 |
|
12962 |
###################################################################################
|
12963 |
|
12964 |
-
def ordered_groups(data,
|
12965 |
|
12966 |
groups = OrderedDict()
|
12967 |
|
12968 |
for sublist in data:
|
12969 |
-
key = sublist[
|
12970 |
|
12971 |
if key not in groups:
|
12972 |
groups[key] = []
|
@@ -13110,13 +13110,14 @@ def fix_escore_notes_durations(escore_notes,
|
|
13110 |
times_idx=1,
|
13111 |
durs_idx=2,
|
13112 |
channels_idx = 3,
|
13113 |
-
pitches_idx=4
|
|
|
13114 |
):
|
13115 |
|
13116 |
notes = [e for e in escore_notes if e[channels_idx] != 9]
|
13117 |
drums = [e for e in escore_notes if e[channels_idx] == 9]
|
13118 |
|
13119 |
-
escore_groups = ordered_groups(notes, pitches_idx)
|
13120 |
|
13121 |
merged_score = []
|
13122 |
|
@@ -13142,6 +13143,69 @@ def fix_escore_notes_durations(escore_notes,
|
|
13142 |
|
13143 |
###################################################################################
|
13144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13145 |
print('Module loaded!')
|
13146 |
print('=' * 70)
|
13147 |
print('Enjoy! :)')
|
|
|
51 |
|
52 |
###################################################################################
|
53 |
|
54 |
+
__version__ = "25.6.25"
|
55 |
|
56 |
print('=' * 70)
|
57 |
print('TMIDIX Python module')
|
|
|
12961 |
|
12962 |
###################################################################################
|
12963 |
|
12964 |
+
def ordered_groups(data, ptc_idx, pat_idx):
|
12965 |
|
12966 |
groups = OrderedDict()
|
12967 |
|
12968 |
for sublist in data:
|
12969 |
+
key = tuple([sublist[ptc_idx], sublist[pat_idx]])
|
12970 |
|
12971 |
if key not in groups:
|
12972 |
groups[key] = []
|
|
|
13110 |
times_idx=1,
|
13111 |
durs_idx=2,
|
13112 |
channels_idx = 3,
|
13113 |
+
pitches_idx=4,
|
13114 |
+
patches_idx=6
|
13115 |
):
|
13116 |
|
13117 |
notes = [e for e in escore_notes if e[channels_idx] != 9]
|
13118 |
drums = [e for e in escore_notes if e[channels_idx] == 9]
|
13119 |
|
13120 |
+
escore_groups = ordered_groups(notes, pitches_idx, patches_idx)
|
13121 |
|
13122 |
merged_score = []
|
13123 |
|
|
|
13143 |
|
13144 |
###################################################################################
|
13145 |
|
13146 |
+
def create_nested_chords_tree(chords_list):
|
13147 |
+
|
13148 |
+
tree = {}
|
13149 |
+
|
13150 |
+
for chord in chords_list:
|
13151 |
+
|
13152 |
+
node = tree
|
13153 |
+
|
13154 |
+
for semitone in chord:
|
13155 |
+
if semitone not in node:
|
13156 |
+
node[semitone] = {}
|
13157 |
+
|
13158 |
+
node = node[semitone]
|
13159 |
+
|
13160 |
+
node.setdefault(-1, []).append(chord)
|
13161 |
+
|
13162 |
+
return tree
|
13163 |
+
|
13164 |
+
###################################################################################
|
13165 |
+
|
13166 |
+
def get_chords_with_prefix(nested_chords_tree, prefix):
|
13167 |
+
|
13168 |
+
node = nested_chords_tree
|
13169 |
+
|
13170 |
+
for semitone in prefix:
|
13171 |
+
if semitone in node:
|
13172 |
+
node = node[semitone]
|
13173 |
+
|
13174 |
+
else:
|
13175 |
+
return []
|
13176 |
+
|
13177 |
+
collected_chords = []
|
13178 |
+
|
13179 |
+
def recursive_collect(subnode):
|
13180 |
+
if -1 in subnode:
|
13181 |
+
collected_chords.extend(subnode[-1])
|
13182 |
+
|
13183 |
+
for key, child in subnode.items():
|
13184 |
+
if key != -1:
|
13185 |
+
recursive_collect(child)
|
13186 |
+
|
13187 |
+
recursive_collect(node)
|
13188 |
+
|
13189 |
+
return collected_chords
|
13190 |
+
|
13191 |
+
###################################################################################
|
13192 |
+
|
13193 |
+
def get_chords_by_semitones(chords_list, chord_semitones):
|
13194 |
+
|
13195 |
+
query_set = set(chord_semitones)
|
13196 |
+
results = []
|
13197 |
+
|
13198 |
+
for chord in chords_list:
|
13199 |
+
|
13200 |
+
chord_set = set(chord)
|
13201 |
+
|
13202 |
+
if query_set.issubset(chord_set):
|
13203 |
+
results.append(sorted(set(chord)))
|
13204 |
+
|
13205 |
+
return results
|
13206 |
+
|
13207 |
+
###################################################################################
|
13208 |
+
|
13209 |
print('Module loaded!')
|
13210 |
print('=' * 70)
|
13211 |
print('Enjoy! :)')
|