read

read(source: str | Path | IO[bytes], graph_engine: GraphAdapter | None = None)

The score in a MusicXML file, as a new graph holding one Score.

source is a path or a binary stream; .mxl archives are recognised by their contents. Every musical fact the reader cannot place raises an OmkWarning naming the measure.

>>> import io
>>> from openmusickit.objects.note_event import NoteEvent
>>> from openmusickit.objects.score import Score
>>> doc = io.BytesIO(b'''<score-partwise version="4.0">
...   <work><work-title>Two notes</work-title></work>
...   <part-list><score-part id="P1"><part-name>Flute</part-name></score-part></part-list>
...   <part id="P1"><measure number="1">
...     <attributes><divisions>1</divisions>
...       <time><beats>2</beats><beat-type>4</beat-type></time></attributes>
...     <note><pitch><step>C</step><octave>4</octave></pitch>
...       <duration>1</duration><type>quarter</type></note>
...     <note><pitch><step>D</step><octave>4</octave></pitch>
...       <duration>1</duration><type>quarter</type></note>
...   </measure></part></score-partwise>''')
>>> graph = read(doc)
>>> score = next(graph.nodes(Score))
>>> score.title, [part.name for part in graph.score_parts(score)]
('Two notes', ['Flute'])
>>> head = next(graph.score_lines(score))
>>> [type(event).__name__ for event in graph.walk_line(head)]
['MeterEvent', 'NoteEvent', 'NoteEvent', 'DivisionEvent']

Raises

Name Type Description
MusicXmlError if source is not a partwise MusicXML score (see container.load).