def test_equality_all1(): #import score1 score1_path = Path("test_scores/multivoice_score_1a.mei") with open(score1_path, 'r') as f: mei_string = f.read() conv = m21.mei.MeiToM21Converter(mei_string) score1 = conv.run() #import score2 score2_path = Path("test_scores/multivoice_score_1b.mei") with open(score2_path, 'r') as f: mei_string = f.read() conv = m21.mei.MeiToM21Converter(mei_string) score2 = conv.run() #create scores s1 = nlin.Score(score1) s2 = nlin.Score(score2) #select voices1 v1 = s1.part_list[0].bar_list[0].voices_list[0] v2 = s2.part_list[0].bar_list[0].voices_list[0] #change the ids for an in v1.annot_notes: an.general_note.id = 344 for an in v2.annot_notes: an.general_note.id = 345 assert (v1 == v2) assert (repr(v1) == repr(v1)) assert (repr(v2) == repr(v2)) assert (repr(v1) != repr(v2))
def test_equality_an2(): n1 = m21.note.Note(nameWithOctave='D5', quarterLength=2) n1.id = 344 n1.tie = m21.tie.Tie('stop') n2 = m21.note.Note(nameWithOctave='D5', quarterLength=2) n2.id = 344 n2.tie = m21.tie.Tie('stop') #create annotated note anote1 = nlin.AnnotatedNote(n1, [], []) anote2 = nlin.AnnotatedNote(n2, [], []) assert (anote1 == anote2) assert (repr(anote1) == repr(anote2))
def test_pitches_diff1(): n1 = m21.note.Note(nameWithOctave='D#5', quarterLength=1) n2 = m21.note.Note(nameWithOctave='D--5', quarterLength=1) #create AnnotatedNotes note1 = nlin.AnnotatedNote(n1, [], []) note2 = nlin.AnnotatedNote(n2, [], []) #pitches to compare pitch1 = note1.pitches[0] pitch2 = note2.pitches[0] #compare op_list, cost = scl.pitches_diff(pitch1, pitch2, note1, note2, (0, 0)) assert (cost == 1) assert (op_list == [("accidentedit", note1, note2, 1, (0, 0))])
def test_pitches_diff2(): n1 = m21.note.Note(nameWithOctave='E5', quarterLength=2) n2 = m21.note.Note(nameWithOctave='D--5', quarterLength=1) note1 = nlin.AnnotatedNote(n1, [], []) note2 = nlin.AnnotatedNote(n2, [], []) #pitches to compare pitch1 = note1.pitches[0] pitch2 = note2.pitches[0] #compare op_list, cost = scl.pitches_diff(pitch1, pitch2, note1, note2, (0, 0)) assert (cost == 2) assert (len(op_list) == 2) assert (("accidentins", None, note2, 1, (0, 0)) in op_list) assert (("pitchnameedit", note1, note2, 1, (0, 0)) in op_list)
def test_pitches_diff4(): n1 = m21.note.Note(nameWithOctave='D5', quarterLength=2) n1.tie = m21.tie.Tie('stop') n2 = m21.note.Note(nameWithOctave='D#5', quarterLength=3) n2.tie = m21.tie.Tie('stop') note1 = nlin.AnnotatedNote(n1, [], []) note2 = nlin.AnnotatedNote(n2, [], []) #pitches to compare pitch1 = note1.pitches[0] pitch2 = note2.pitches[0] #compare op_list, cost = scl.pitches_diff(pitch1, pitch2, note1, note2, (0, 0)) assert (cost == 1) assert (len(op_list) == 1) assert (("accidentins", None, note2, 1, (0, 0)) in op_list)
def test_pitches_diff3(): n1 = m21.note.Note(nameWithOctave='D--5', quarterLength=2) n1.tie = m21.tie.Tie('stop') n2 = m21.note.Rest(quarterLength=0.5) note1 = nlin.AnnotatedNote(n1, [], []) note2 = nlin.AnnotatedNote(n2, [], []) #pitches to compare pitch1 = note1.pitches[0] pitch2 = note2.pitches[0] #compare op_list, cost = scl.pitches_diff(pitch1, pitch2, note1, note2, (0, 0)) assert (cost == 3) assert (len(op_list) == 3) assert (("accidentdel", note1, None, 1, (0, 0)) in op_list) assert (("pitchtypeedit", note1, note2, 1, (0, 0)) in op_list) assert (("tiedel", note1, None, 1, (0, 0)) in op_list)
def test_annotNote1(): n1 = m21.note.Note(nameWithOctave='D#5', quarterLength=1) n1.id = 344 #create annotated note anote = nlin.AnnotatedNote(n1, [], []) assert (anote.__repr__() == "[('D5', 'sharp', False)],4,0,[],[],344") assert (str(anote) == "[D5sharp]4")
def test_annotNote2(): n1 = m21.note.Note(nameWithOctave='E#5', quarterLength=0.5) n1.id = 344 #create annotated note anote = nlin.AnnotatedNote(n1, ["start"], ["start"]) assert (anote.__repr__() == "[('E5', 'sharp', False)],4,0,['start'],['start'],344") assert (str(anote) == "[E5sharp]4BsrTsr")
def test_complete_scorelin_diff1(): score1_path = Path("test_scores/monophonic_score_1a.mei") with open(score1_path, 'r') as f: mei_string = f.read() conv = m21.mei.MeiToM21Converter(mei_string) score1 = conv.run() score2_path = Path("test_scores/monophonic_score_1b.mei") with open(score2_path, 'r') as f: mei_string = f.read() conv = m21.mei.MeiToM21Converter(mei_string) score2 = conv.run() #build ScoreTrees score_lin1 = nlin.Score(score1) score_lin2 = nlin.Score(score2) #compute the complete score diff op_list, cost = scl.complete_scorelin_diff(score_lin1, score_lin2) assert (cost == 8)
def test_annotNote3(): n1 = m21.note.Note(nameWithOctave='D5', quarterLength=2) n1.id = 344 n1.tie = m21.tie.Tie('stop') #create annotated note anote = nlin.AnnotatedNote(n1, [], []) assert (anote.__repr__() == "[('D5', 'None', True)],2,0,[],[],344") assert (str(anote) == "[D5T]2")
def test_json_production2(): score1_path = Path("test_scores/polyphonic_score_2a.mei") with open(score1_path, 'r') as f: mei_string = f.read() conv = m21.mei.MeiToM21Converter(mei_string) score1 = conv.run() score2_path = Path("test_scores/polyphonic_score_2b.mei") with open(score2_path, 'r') as f: mei_string = f.read() conv = m21.mei.MeiToM21Converter(mei_string) score2 = conv.run() #build ScoreTrees score_lin1 = nlin.Score(score1) score_lin2 = nlin.Score(score2) #compute the complete score diff op_list, cost=scl.complete_scorelin_diff(score_lin1,score_lin2) operation_json = scl.op_list2json(op_list) assert(1==1)
def test_block_diff1(): score1_path = Path("test_scores/monophonic_score_1a.mei") with open(score1_path, 'r') as f: mei_string = f.read() conv = m21.mei.MeiToM21Converter(mei_string) score1 = conv.run() score2_path = Path("test_scores/monophonic_score_1b.mei") with open(score2_path, 'r') as f: mei_string = f.read() conv = m21.mei.MeiToM21Converter(mei_string) score2 = conv.run() #build ScoreTrees score_lin1 = nlin.Score(score1) score_lin2 = nlin.Score(score2) # compute the blockdiff between all the bars (just for test, in practise we will run on non common subseq) op_list, cost = scl.block_diff_lin(score_lin1.measures_from_part(0), score_lin2.measures_from_part(0)) assert (cost == 8)
def test_noteNode_size4(): n1 = m21.note.Note(nameWithOctave='D5') n2 = m21.note.Note(nameWithOctave='F#5') n2.tie = m21.tie.Tie('stop') n3 = m21.note.Note(nameWithOctave='G#5') d = m21.duration.Duration(1.75) chord = m21.chord.Chord([n1, n2, n3], duration=d) #create annotated note anote = nlin.AnnotatedNote(chord, [], []) assert (anote.notation_size() == 12)
def test_non_common_subsequences6(): #import scores score1_path = Path("test_scores/polyphonic_score_1a.mei") with open(score1_path, 'r') as f: mei_string = f.read() conv = m21.mei.MeiToM21Converter(mei_string) score1 = conv.run() score2_path = Path("test_scores/polyphonic_score_1b.mei") with open(score2_path, 'r') as f: mei_string = f.read() conv = m21.mei.MeiToM21Converter(mei_string) score2 = conv.run() #build ScoreTrees score_tree1 = nlin.Score(score1) score_tree2 = nlin.Score(score2) #compute the non common_subsequences for part 0 part = 0 non_common_subsequences = scl.non_common_subsequences( score_tree1.part_list[part].bar_list, score_tree2.part_list[part].bar_list) assert (len(non_common_subsequences) == 2)
def test_annotation_production5(): score1_path = Path("test_scores/chord_score_3a.mei") with open(score1_path, 'r') as f: mei_string = f.read() conv = m21.mei.MeiToM21Converter(mei_string) score1 = conv.run() score2_path = Path("test_scores/chord_score_3b.mei") with open(score2_path, 'r') as f: mei_string = f.read() conv = m21.mei.MeiToM21Converter(mei_string) score2 = conv.run() #build ScoreTrees score_lin1 = nlin.Score(score1) score_lin2 = nlin.Score(score2) #compute the complete score diff op_list, cost=scl.complete_scorelin_diff(score_lin1,score_lin2) ann1, ann2 = sv.oplist2annotations(op_list) sv.setResourchesPath(Path(RESOURCES_PATH)) sv.produce_annnot_svg(score1_path,ann1,out_path=Path("output/chord_score_3a.svg")) sv.produce_annnot_svg(score2_path,ann2,out_path=Path("output/chord_score_3b.svg")) assert(1==1)
def test_non_common_subsequences7(): #import scores score1_path = Path("test_scores/monophonic_score_1a.mei") with open(score1_path, 'r') as f: mei_string = f.read() conv = m21.mei.MeiToM21Converter(mei_string) score1 = conv.run() score2_path = Path("test_scores/monophonic_score_1b.mei") with open(score2_path, 'r') as f: mei_string = f.read() conv = m21.mei.MeiToM21Converter(mei_string) score2 = conv.run() #build ScoreTrees score_tree1 = nlin.Score(score1) score_tree2 = nlin.Score(score2) #compute the non common_subsequences for part 0 part = 0 non_common_subsequences = scl.non_common_subsequences( score_tree1.part_list[part].bar_list, score_tree2.part_list[part].bar_list) expected_non_common1 = { "original": [score_tree1.part_list[0].bar_list[1]], "compare_to": [score_tree2.part_list[0].bar_list[1]] } expected_non_common2 = { "original": [ score_tree1.part_list[0].bar_list[5], score_tree1.part_list[0].bar_list[6], score_tree1.part_list[0].bar_list[7], score_tree1.part_list[0].bar_list[8] ], "compare_to": [ score_tree2.part_list[0].bar_list[5], score_tree2.part_list[0].bar_list[6], score_tree2.part_list[0].bar_list[7] ] } assert (len(non_common_subsequences) == 2) assert (non_common_subsequences[0] == expected_non_common1) assert (non_common_subsequences[1] == expected_non_common2)
def test_scorelin2(): #import score score1_path = Path("test_scores/monophonic_score_1a.mei") with open(score1_path, 'r') as f: mei_string = f.read() conv = m21.mei.MeiToM21Converter(mei_string) score1 = conv.run() #produce a ScoreTree score_lin1 = nlin.Score(score1) #number of parts assert (len(score_lin1.part_list) == 1) #number of measures for each part assert (len(score_lin1.part_list[0].bar_list) == 11) #number of voices for each measure in part 0 for m in score_lin1.part_list[0].bar_list: assert (len(m.voices_list) == 1)
def test_ties1(): #import score score1_path = Path("test_scores/tie_score_1a.mei") with open(score1_path, 'r') as f: mei_string = f.read() conv = m21.mei.MeiToM21Converter(mei_string) score1 = conv.run() #produce a ScoreTree score_lin1 = nlin.Score(score1) #number of parts assert (len(score_lin1.part_list) == 1) #number of measures for each part assert (len(score_lin1.part_list[0].bar_list) == 1) #number of voices for each measure in part 0 for m in score_lin1.part_list[0].bar_list: assert (len(m.voices_list) == 1) expected_tree_repr = "[[E4]4Bsr,[E4T]4Bcosr,[D4]4Bspsp,[C4,E4]4Bsr,[C4T]4Bcosr,[D4]4Bspsp,[E4,G4,C5]4,[E4]4Bsr,[F4]4Bsp]" assert (str(score_lin1.part_list[0].bar_list[0].voices_list[0]) == expected_tree_repr) assert (score_lin1.part_list[0].bar_list[0].voices_list[0].notation_size() == 26)
def test_equality_all2(): #import score1 score1_path = Path("test_scores/polyphonic_score_2b.mei") with open(score1_path, 'r') as f: mei_string = f.read() conv = m21.mei.MeiToM21Converter(mei_string) score1 = conv.run() #create score s = nlin.Score(score1) #select bars b1 = s.part_list[0].bar_list[11] b2 = s.part_list[0].bar_list[12] assert (b1 == b2) assert (repr(b1) == repr(b1)) assert (repr(b2) == repr(b2)) assert (repr(b1) != repr(b2)) #select voices v1 = s.part_list[0].bar_list[11].voices_list[0] v2 = s.part_list[0].bar_list[12].voices_list[0] assert (v1 == v2) assert (repr(v1) == repr(v1)) assert (repr(v2) == repr(v2)) assert (repr(v1) != repr(v2))
mei_string = f.read() conv = m21.mei.MeiToM21Converter(mei_string) score1 = conv.run() #load score2 in music21 score2_path = Path("test_scores/polyphonic_score_1b.mei") with open(score2_path, 'r') as f: mei_string = f.read() conv = m21.mei.MeiToM21Converter(mei_string) score2 = conv.run() #add the correct folder for resourches. Uncomment if needed # sv.setResourchesPath(Path("C:/Users/example/Desktop/verovio/data" )) #build the linear representation of the score score_lin1 = nlin.Score(score1) score_lin2 = nlin.Score(score2) #compute the complete score diff op_list, cost = scl.complete_scorelin_diff(score_lin1, score_lin2) #generate the list of annotations in json format operation_json = scl.op_list2json(op_list) #save them to a file with open(Path('output/operations_test.json'), 'w') as outfile: json.dump(operation_json, outfile) #compute the annotations for the two scores ann1, ann2 = sv.oplist2annotations(op_list) #display the annotations on the scores (color the involved elements) sv.produce_annnot_svg(score1_path, ann1, out_path=Path("output/test1.svg")) sv.produce_annnot_svg(score2_path, ann2, out_path=Path("output/test2.svg"))
def test_annotNote_size2(): n1 = m21.note.Note(nameWithOctave='D#5', quarterLength=1.5) n1.tie = m21.tie.Tie('stop') #create annotated note anote = nlin.AnnotatedNote(n1, [], []) assert (anote.notation_size() == 4)
def test_noteNode_size3(): d = m21.duration.Duration(1.5) n1 = m21.chord.Chord(['D', 'F#', 'A'], duration=d) #create annotated note anote = nlin.AnnotatedNote(n1, [], []) assert (anote.notation_size() == 7)