Package: partitura
Partiturais a Python package for handling symbolic musical information. It
supports loading from and exporting toMusicXMLandMIDIfiles. It also supports loading fromHumdrumkernandMEI.The full documentation forpartiturais available online atreadthedocs.org.User InstallationThe easiest way to install the package is viapipfrom thePyPI (Python
Package Index):pipinstallpartituraThis will install the latest release of the package and will install all dependencies automatically.QuickstartA detailed tutorial with some hands-on MIR applications is availablehere.The following code loads the contents of an example MusicXML file included in
the package:importpartituraasptmy_xml_file=pt.EXAMPLE_MUSICXMLscore=pt.load_score(my_xml_file)The partituraload_scorefunction will import any score format, i.e. (Musicxml, Kern, MIDI or MEI) to apartitura.Scoreobject.
The score object will contain all the information in the score, including the score parts.
The following shows the contents of the first part of the score:part=score.parts[0]print(part.pretty())Output:Partid="P1"name="Piano"│├─TimePointt=0quarter=12│││└─startingobjects│││├─0--48Measurenumber=1│├─0--48Noteid=n01voice=1staff=2type=wholepitch=A4│├─0--48Pagenumber=1│├─0--24Restid=r01voice=2staff=1type=half│├─0--48Systemnumber=1│└─0--TimeSignature4/4│├─TimePointt=24quarter=12│││├─endingobjects│││││└─0--24Restid=r01voice=2staff=1type=half│││└─startingobjects│││├─24--48Noteid=n02voice=2staff=1type=halfpitch=C5│└─24--48Noteid=n03voice=2staff=1type=halfpitch=E5│└─TimePointt=48quarter=12│└─endingobjects│├─0--48Measurenumber=1├─0--48Noteid=n01voice=1staff=2type=wholepitch=A4├─24--48Noteid=n02voice=2staff=1type=halfpitch=C5├─24--48Noteid=n03voice=2staff=1type=halfpitch=E5├─0--48Pagenumber=1└─0--48Systemnumber=1IflilypondorMuseScoreare installed on the system, the following command
renders the part to an image and displays it:pt.render(part)The notes in this part can be accessed through the propertypart.notes:part.notes>[<partitura.score.Noteobjectat0x...>,<partitura.score.Noteobjectat0x...>,><partitura.score.Noteobjectat0x...>]The following code stores the start, end, and midi pitch of the notes in a numpy
array:importnumpyasnppianoroll=np.array([(n.start.t,n.end.t,n.midi_pitch)forninpart.notes])print(pianoroll)>[[04869]>[244872]>[244876]]The note start and end times are in the units specified by thedivisionselement of the MusicXML file. This element specifies the
duration of a quarter note. Thedivisionsvalue can vary within an
MusicXML file, so it is generally better to work with musical time in
beats.The part object has a property :part.beat_mapthat converts timeline
times into beat times:beat_map=part.beat_mapprint(beat_map(pianoroll[:,0]))>[0.2.2.]print(beat_map(pianoroll[:,1]))>[4.4.4.]The following commands save the part to MIDI and MusicXML, or export it as a WAV file (usingadditive synthesis), respectively:# Save Score MIDI to file.pt.save_score_midi(part,'mypart.mid')# Save Score MusicXML to file.pt.save_musicxml(part,'mypart.musicxml')# Save as audio file using additive synthesispt.save_wav(part,'mypart.wav')More elaborate examples can be found in thedocumentation <https://partitura.readthedocs.io/en/latest/index.html>_.Import other formatsForMusicXMLfiles do:importpartituraasptmy_xml_file=pt.EXAMPLE_MUSICXMLscore=pt.load_musicxml(my_xml_file)ForKernfiles do:importpartituraasptmy_kern_file=pt.EXAMPLE_KERNscore=pt.load_kern(my_kern_file)ForMEIfiles do:importpartituraasptmy_mei_file=pt.EXAMPLE_MEIscore=pt.load_mei(my_mei_file)One can also import any of the above formats by just using:importpartituraasptany_score_format_path=pt.EXAMPLE_MUSICXMLscore=pt.load_score(any_score_format_path)LicenseThe code in this package is licensed under the Apache 2.0 License. For details,
please see theLICENSEfile.Citing PartituraIf you find Partitura useful, we would appreciate if you could cite us!@inproceedings{partitura_mec,
  title={{Partitura: A Python Package for Symbolic Music Processing}},
  author={Cancino-Chac\'{o}n, Carlos Eduardo and Peter, Silvan David and Karystinaios, Emmanouil and Foscarin, Francesco and Grachten, Maarten and Widmer, Gerhard},
  booktitle={{Proceedings of the Music Encoding Conference (MEC2022)}},
  address={Halifax, Canada},
  year={2022}
}AcknowledgmentsThis project receives funding from the European Research Council (ERC) under
the European Union's Horizon 2020 research and innovation programme under grant
agreement No 101019375"Whither Music?".This work has received support from the European Research Council (ERC) under
the European Union’s Horizon 2020 research and innovation programme under grant
agreement No. 670035 project"Con Espressione"and the Austrian Science Fund (FWF) under grant P 29840-G26 (project"Computer-assisted Analysis of Herbert von Karajan's Musical Conducting Style")