Ejemplo n.º 1
0
def test_notenode1():
    n1 = m21.note.Note("E--5")
    n1.duration.quarterLength = 3
    n2 = m21.note.Note("D4")
    n_grace = n2.getGrace()
    root = Root()
    node1 = LeafNode(root, [gn2label(gn) for gn in [n_grace, n1]])
    assert node1.label == [
        ([{
            "npp": "D4",
            "acc": None,
            "tie": False
        }], 4, 0, True),
        ([{
            "npp": "E5",
            "acc": -2,
            "tie": False
        }], 2, 1, False),
    ]
    assert str(node1) == str([
        ([{
            "npp": "D4",
            "acc": None,
            "tie": False
        }], 4, 0, True),
        ([{
            "npp": "E5",
            "acc": -2,
            "tie": False
        }], 2, 1, False),
    ])
    assert root.complete()
    assert node1.complete()
Ejemplo n.º 2
0
def test_gn2label_musicxml2():
    score = m21.converter.parse(
        str(Path("tests/test_musicxml/test_score2.musicxml")))
    measures = score.parts[0].getElementsByClass("Measure")
    # measure 3 (grace note)
    gns_m3 = measures[3].getElementsByClass("GeneralNote")
    label_gns_m3 = [gn2label(gn) for gn in gns_m3]
    expected_label_gns_m3 = [
        ([{
            "npp": "F4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "E4",
            "acc": None,
            "tie": False
        }], 4, 0, True),
        ([{
            "npp": "E4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ("R", 2, 0, False),
    ]
    assert label_gns_m3 == expected_label_gns_m3
Ejemplo n.º 3
0
def test_gn2label():
    n1 = m21.note.Note("E--5")
    n1.duration.quarterLength = 3
    assert gn2label(n1) == ([{
        "npp": "E5",
        "acc": -2,
        "tie": False
    }], 2, 1, False)
Ejemplo n.º 4
0
def test_nt2general_notes2():
    score = m21.converter.parse(
        str(Path("tests/test_musicxml/test_score3.musicxml")))
    measures = score.parts[0].getElementsByClass("Measure")
    for m in measures:
        gns = m.getElementsByClass("GeneralNote")
        bt = m21_2_notationtree(gns, "beamings")
        tt = m21_2_notationtree(gns, "tuplets")
        out_gns = nt2general_notes(bt, tt)
        # check beamings and tuplets
        assert m21_2_seq_struct(gns, "beamings") == m21_2_seq_struct(
            out_gns, "beamings")
        assert (correct_tuplet(m21_2_seq_struct(
            gns, "tuplets")[0]) == m21_2_seq_struct(out_gns, "tuplets")[0])
        assert (m21_2_seq_struct(gns, "tuplets")[1] == m21_2_seq_struct(
            out_gns, "tuplets")[1])
        for n1, n2 in zip(gns, out_gns):
            assert gn2label(n1) == gn2label(n2)
            # check m21 proprieties without the modifications that we do for importing
            assert get_type_number(n1) == get_type_number(n2)
Ejemplo n.º 5
0
def test_notationtree1():
    n1 = m21.note.Note("E--5")
    n1.duration.quarterLength = 3
    n2 = m21.note.Note("D4")
    root = Root()
    node1 = InternalNode(root, "")
    node3 = LeafNode(node1, gn2label(n1))
    node4 = LeafNode(node1, gn2label(n2))
    nt1 = NotationTree(root, tree_type="beaming")
    assert nt1.get_leaf_nodes() == [node3, node4]
    assert nt1.get_nodes(local_root=node1) == [node1, node3, node4]
    assert nt1.get_nodes() == [root, node1, node3, node4]
    assert nt1.get_depth(root) == 0
    assert nt1.get_depth(node1) == 1
    assert nt1.get_depth(node3) == 2
    assert nt1.get_ancestors(root) == []
    assert nt1.get_ancestors(node4) == [node1, root]
    assert nt1.get_lca(node3, node4) == node1
    assert nt1.get_lca(node4, node3) == node1
    assert nt1.get_lca(root, node4) == root
    assert nt1.get_lca(node4, root) == root
    assert root.complete()
Ejemplo n.º 6
0
def test_gn2label_musicxml1():
    score = m21.converter.parse(
        str(Path("tests/test_musicxml/test_score1.musicxml")))
    measures = score.parts[0].getElementsByClass("Measure")
    # measure 0
    gns_m0 = measures[0].getElementsByClass("GeneralNote")
    label_gns_m0 = [gn2label(gn) for gn in gns_m0]
    expected_label_gns_m0 = [([{
        "npp": "G4",
        "acc": None,
        "tie": False
    }], 1, 0, False)]
    assert label_gns_m0 == expected_label_gns_m0
    # measure 1
    gns_m1 = measures[1].getElementsByClass("GeneralNote")
    label_gns_m1 = [gn2label(gn) for gn in gns_m1]
    expected_label_gns_m1 = [
        ([{
            "npp": "E4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "F4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "G4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "A4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "C5",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "B4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "A4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "G4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
    ]
    assert label_gns_m1 == expected_label_gns_m1
    # measure 2
    gns_m2 = measures[2].getElementsByClass("GeneralNote")
    label_gns_m2 = [gn2label(gn) for gn in gns_m2]
    expected_label_gns_m2 = [
        ([{
            "npp": "F4",
            "acc": None,
            "tie": False
        }], 4, 1, False),
        ([{
            "npp": "E4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "F4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "G4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "B4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "B4",
            "acc": None,
            "tie": True
        }], 4, 0, False),
    ]
    assert label_gns_m2 == expected_label_gns_m2
    # measure 3
    gns_m3 = measures[3].getElementsByClass("GeneralNote")
    label_gns_m3 = [gn2label(gn) for gn in gns_m3]
    expected_label_gns_m3 = [
        ([{
            "npp": "E4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "F4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "G4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "A4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "C5",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "G4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "F4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "E4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
    ]
    assert label_gns_m3 == expected_label_gns_m3
    # measure 4
    gns_m4 = measures[4].getElementsByClass("GeneralNote")
    label_gns_m4 = [gn2label(gn) for gn in gns_m4]
    expected_label_gns_m4 = [
        (
            [
                {
                    "npp": "D4",
                    "acc": None,
                    "tie": False
                },
                {
                    "npp": "F4",
                    "acc": None,
                    "tie": False
                },
                {
                    "npp": "A4",
                    "acc": None,
                    "tie": False
                },
            ],
            4,
            0,
            False,
        ),
        (
            [
                {
                    "npp": "D4",
                    "acc": None,
                    "tie": True
                },
                {
                    "npp": "F4",
                    "acc": None,
                    "tie": True
                },
                {
                    "npp": "A4",
                    "acc": None,
                    "tie": True
                },
            ],
            4,
            0,
            False,
        ),
        (
            [
                {
                    "npp": "D4",
                    "acc": None,
                    "tie": False
                },
                {
                    "npp": "F4",
                    "acc": None,
                    "tie": False
                },
                {
                    "npp": "C5",
                    "acc": None,
                    "tie": False
                },
            ],
            4,
            0,
            False,
        ),
        (
            [
                {
                    "npp": "C4",
                    "acc": None,
                    "tie": False
                },
                {
                    "npp": "E4",
                    "acc": None,
                    "tie": False
                },
                {
                    "npp": "C5",
                    "acc": None,
                    "tie": True
                },
            ],
            4,
            0,
            False,
        ),
    ]
    assert label_gns_m4 == expected_label_gns_m4
    # measure 5
    gns_m5 = measures[5].getElementsByClass("GeneralNote")
    label_gns_m5 = [gn2label(gn) for gn in gns_m5]
    expected_label_gns_m5 = [
        ("R", 4, 0, False),
        ([{
            "npp": "D4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ("R", 4, 1, False),
        ([{
            "npp": "G4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ([{
            "npp": "A4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
        ("R", 4, 0, False),
        ([{
            "npp": "G4",
            "acc": None,
            "tie": False
        }], 4, 0, False),
    ]
    assert label_gns_m5 == expected_label_gns_m5
Ejemplo n.º 7
0
def test_simplify_label2():
    n1 = m21.note.Note("D4")
    n_grace = n1.getGrace()
    n2 = m21.note.Note("E#5")
    assert simplify_label(gn2label(n_grace)) == "[D4]4gn"
Ejemplo n.º 8
0
def test_simplify_label1():
    n1 = m21.note.Note("E--5")
    n1.duration.quarterLength = 3
    assert simplify_label(gn2label(n1)) == "[E5bb]2*"