Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -135,86 +135,18 @@ def Match_Cores(input_midi,
|
|
| 135 |
|
| 136 |
#===============================================================================
|
| 137 |
|
| 138 |
-
|
| 139 |
|
| 140 |
#===============================================================================
|
| 141 |
|
| 142 |
-
print('Prepping chords chunks...')
|
| 143 |
-
|
| 144 |
-
chunk_len = chords_chunks_len
|
| 145 |
-
|
| 146 |
-
all_chords_chunks = Counter()
|
| 147 |
-
|
| 148 |
-
for i in range(0, len(tones_chords)):
|
| 149 |
-
chunk = tones_chords[i:i+chunk_len]
|
| 150 |
-
if len(chunk) == chunk_len:
|
| 151 |
-
all_chords_chunks[tuple(chunk)] += 1
|
| 152 |
-
|
| 153 |
-
print('Done!')
|
| 154 |
-
print('=' * 70)
|
| 155 |
-
print('Number of chords chunks:', len(all_chords_chunks))
|
| 156 |
-
print('=' * 70)
|
| 157 |
-
|
| 158 |
#==================================================================
|
| 159 |
|
| 160 |
-
print('
|
| 161 |
print('=' * 70)
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
all_match_chunks = {}
|
| 166 |
-
|
| 167 |
-
for mc_chunk in other_chunks:
|
| 168 |
-
chunk_lens = fuzzy_find([len(l) for l in split_by_sublist(tones_chords, mc_chunk) if len(l) > chunk_len])
|
| 169 |
-
match_chunks = [l for l in split_by_sublist(tones_chords, mc_chunk) if len(l) in chunk_lens]
|
| 170 |
-
all_match_chunks[tuple(mc_chunk)] = match_chunks
|
| 171 |
-
|
| 172 |
-
#==================================================================
|
| 173 |
-
|
| 174 |
-
chunks_map = random.choices(other_chunks, k=num_mix_chunks)
|
| 175 |
-
|
| 176 |
-
#==================================================================
|
| 177 |
-
|
| 178 |
-
matched_chunks = []
|
| 179 |
-
start_chunk = []
|
| 180 |
-
res = -1
|
| 181 |
-
tries = 0
|
| 182 |
-
while res == -1 and len(start_chunk[:res]) < chunk_len and tries < 100:
|
| 183 |
-
|
| 184 |
-
start_chunk = random.choice(all_match_chunks[tuple(chunks_map[0])])
|
| 185 |
-
res = kmp_search(start_chunk, chunks_map[1])[0]
|
| 186 |
-
|
| 187 |
-
tries += 1
|
| 188 |
-
|
| 189 |
-
#print(res)
|
| 190 |
-
if tries < 100:
|
| 191 |
-
matched_chunks.append(start_chunk[:res])
|
| 192 |
-
|
| 193 |
-
else:
|
| 194 |
-
print('FAIL!')
|
| 195 |
-
|
| 196 |
-
#==================================================================
|
| 197 |
|
| 198 |
-
|
| 199 |
-
tries = 0
|
| 200 |
-
while -1 in mchunks and tries < 100:
|
| 201 |
-
|
| 202 |
-
mchunks = []
|
| 203 |
-
|
| 204 |
-
for i, chunk in enumerate(chunks_map[1:-1]):
|
| 205 |
-
start_chunk = random.choice(all_match_chunks[tuple(chunk)])
|
| 206 |
-
res = kmp_search(start_chunk, chunks_map[i+2])[0]
|
| 207 |
-
|
| 208 |
-
#print(res)
|
| 209 |
-
mchunks.append(start_chunk[:res])
|
| 210 |
-
|
| 211 |
-
tries += 1
|
| 212 |
-
|
| 213 |
-
if tries < 100:
|
| 214 |
-
matched_chunks.extend(mchunks)
|
| 215 |
-
|
| 216 |
-
else:
|
| 217 |
-
print('FAIL!')
|
| 218 |
|
| 219 |
#==================================================================
|
| 220 |
|
|
|
|
| 135 |
|
| 136 |
#===============================================================================
|
| 137 |
|
| 138 |
+
src_core_chords = load_midi(input_midi.name)
|
| 139 |
|
| 140 |
#===============================================================================
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
#==================================================================
|
| 143 |
|
| 144 |
+
print('Matching MIDI cores...')
|
| 145 |
print('=' * 70)
|
| 146 |
|
| 147 |
+
match_idx = find_max_exact_match(src_core_chords, all_core_chords)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
+
print('MATCH IDX', match_idx)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
#==================================================================
|
| 152 |
|