示例#1
0
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))
示例#2
0
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)
示例#3
0
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)
示例#4
0
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)
示例#5
0
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)
示例#6
0
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)
示例#7
0
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)
示例#8
0
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)
示例#9
0
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)
示例#10
0
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))
示例#11
0
    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"))