Exemple #1
0
def test_reconstruct():
    s = m21.stream.Score(id="mainScore")

    p1 = m21.stream.Part(id="part1")
    s.append(
        [m21.note.Note("C", type="whole"),
         m21.note.Note("C", type="whole")])

    m11 = m21.stream.Measure(number=1)
    m11.append(m21.note.Note("E", type="whole"))
    m12 = m21.stream.Measure(number=2)
    m12.append(m21.note.Note("F", type="whole"))
    p1.append([m11, m12])
    s.insert(0, p1)
    reconstruct(s)

    for el in s.recurse():
        if isinstance(el, m21.stream.Score):
            assert el.hasPartLikeStreams()
        elif isinstance(el, m21.stream.Part):
            assert el.hasMeasures()
        elif isinstance(el, m21.stream.Measure):
            assert el.hasVoices()
        elif isinstance(el, m21.stream.Voice):
            assert len(el.notes) > 0
Exemple #2
0
def test_reconstruct3():
    score = m21.converter.parse(
        str(Path("tests/test_musicxml/test_score2.musicxml")))
    reconstruct(score)
    expected_num_voices = [2, 1, 2, 1]
    for i, measure in enumerate(score.parts[0].getElementsByClass(
            m21.stream.Measure)):
        assert (len(measure.getElementsByClass(
            m21.stream.Voice)) == expected_num_voices[i])
Exemple #3
0
def test_m21_2_notationtree3():
    # test from lamarque dataset. It has problems in the xml encoding of the gracenotes
    score = m21.converter.parse(
        str(Path("tests/test_musicxml/101-Beethoven-bagatelle4op33.musicxml")))
    reconstruct(score)
    measures = score.parts[0].getElementsByClass("Measure")
    # third measure is problematic because of grace notes
    m = measures[2]
    voice = m.getElementsByClass("Voice")[0]
    gns_m3 = voice.getElementsByClass("GeneralNote")
    nt_bt = m21_2_notationtree(gns_m3, "beamings")
    nt_tt = m21_2_notationtree(gns_m3, "tuplets")
Exemple #4
0
def test_m21_2_notationtree4():
    score = m21.converter.parse(
        str(
            Path("tests/test_musicxml/51_fantasiestucke_op.12-2_aufschwung.xml"
                 )))
    reconstruct(score)
    measures = score.parts[0].getElementsByClass("Measure")
    # third measure is problematic because of grace notes
    m = measures[5]
    voice = m.getElementsByClass("Voice")[0]
    gns_m3 = voice.getElementsByClass("GeneralNote")
    nt_bt = m21_2_notationtree(gns_m3, "beamings")
    nt_tt = m21_2_notationtree(gns_m3, "tuplets")
Exemple #5
0
    def __init__(self,
                 musicxml_path: str,
                 auto_format: bool = True,
                 produce_trees: bool = False):
        """Initialize the ScoreModel from a music21 score object.

        Args:
            musicxml_path: the path of the music_xml to import
            auto_format (bool, optional): Auto format the score with the hierarchy score, parts, measures, voices. Defaults to True.
            produce_trees (bool, optional): Produce the BT and TT for each measure. Defaults to False.
        """
        self.m21_score = m21.converter.parse(str(Path(musicxml_path)))
        self.produce_trees = produce_trees
        if auto_format:
            m21u.reconstruct(self.m21_score)
Exemple #6
0
def test_reconstruct2():
    score = m21.converter.parse(
        str(Path("tests/test_musicxml/test_score1.musicxml")))
    reconstruct(score)
    for measure in score.parts[0].getElementsByClass(m21.stream.Measure):
        assert len(measure.getElementsByClass(m21.stream.Voice)) == 1