sildater / parangonar

alignment of symbolic music
Apache License 2.0
25 stars 1 forks source link

Some Note ID duplicates show up as both `match`and `deletion` in case of spurious score IDs #3

Open sildater opened 1 year ago

sildater commented 1 year ago
import parangonar as pa
import partitura as pt
import pandas as pd

midi_address = PATH_S
score_address = PATH_M

score = pt.load_score(filename= PATH_S)
performance = pt.load_performance_midi(filename= PATH_M)

#unfolding to a version that best matches the number of notes in performance
part_score = score[0]
score_variants = pt.score.make_score_variants(part_score)
score_part_variants_lengths = [score_variant.create_variant_part().note_array().shape[0] for score_variant in score_variants]
best_match = min(score_part_variants_lengths,
                        key=lambda x: abs(x - len(performance.note_array())))
best_match_idx = score_part_variants_lengths.index(best_match)
best_match_score_part = score_variants[best_match_idx].create_variant_part()

pna = performance.note_array()

#alignment without unfolding without updating ids
sna1 = part_score.note_array()
sdm1 = pa.AutomaticNoteMatcher()
pred_alignment1 = sdm1(sna1, pna)
pd.DataFrame(pred_alignment1).to_csv('a1.csv')

#alignment with unfolding without updating ids
sna2 = best_match_score_part.note_array()
sdm2 = pa.AutomaticNoteMatcher()
pred_alignment2 = sdm2(sna2, pna)
pd.DataFrame(pred_alignment2).to_csv('a2.csv')

#alignment with unfolding with updating ids
pt.utils.update_note_ids_after_unfolding(best_match_score_part)
sna3 = best_match_score_part.note_array()
sdm3 = pa.AutomaticNoteMatcher()
pred_alignment3 = sdm3(sna3, pna)
pd.DataFrame(pred_alignment3).to_csv('a3.csv')

alignment2 contains some (~50) duplicate score note IDs for piece K310-2. The score was unfolded but its IDs were not updated, so this score contains several hundred (unplayed) duplicate notes.