• Stars
    star
    229
  • Rank 174,639 (Top 4 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created about 5 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A python package for handling modern staff notation of music

Latest Release Pypi Package Unittest Status CodeCov Status Contributor Covenant

Partitura is a Python package for handling symbolic musical information. It supports loading from and exporting to MusicXML and MIDI files. It also supports loading from Humdrum kern and MEI.

The full documentation for partitura is available online at readthedocs.org.

User Installation

The easiest way to install the package is via pip from the PyPI (Python Package Index):

pip install partitura

This will install the latest release of the package and will install all dependencies automatically.

Quickstart

A detailed tutorial with some hands-on MIR applications is available here.

The following code loads the contents of an example MusicXML file included in the package:

import partitura as pt
my_xml_file = pt.EXAMPLE_MUSICXML
score = pt.load_score(my_xml_file)

The partitura load_score function will import any score format, i.e. (Musicxml, Kern, MIDI or MEI) to a partitura.Score object. 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:

Part id="P1" name="Piano"
 β”‚
 β”œβ”€ TimePoint t=0 quarter=12
 β”‚   β”‚
 β”‚   └─ starting objects
 β”‚       β”‚
 β”‚       β”œβ”€ 0--48 Measure number=1
 β”‚       β”œβ”€ 0--48 Note id=n01 voice=1 staff=2 type=whole pitch=A4
 β”‚       β”œβ”€ 0--48 Page number=1
 β”‚       β”œβ”€ 0--24 Rest id=r01 voice=2 staff=1 type=half
 β”‚       β”œβ”€ 0--48 System number=1
 β”‚       └─ 0-- TimeSignature 4/4
 β”‚
 β”œβ”€ TimePoint t=24 quarter=12
 β”‚   β”‚
 β”‚   β”œβ”€ ending objects
 β”‚   β”‚   β”‚
 β”‚   β”‚   └─ 0--24 Rest id=r01 voice=2 staff=1 type=half
 β”‚   β”‚
 β”‚   └─ starting objects
 β”‚       β”‚
 β”‚       β”œβ”€ 24--48 Note id=n02 voice=2 staff=1 type=half pitch=C5
 β”‚       └─ 24--48 Note id=n03 voice=2 staff=1 type=half pitch=E5
 β”‚
 └─ TimePoint t=48 quarter=12
     β”‚
     └─ ending objects
         β”‚
         β”œβ”€ 0--48 Measure number=1
         β”œβ”€ 0--48 Note id=n01 voice=1 staff=2 type=whole pitch=A4
         β”œβ”€ 24--48 Note id=n02 voice=2 staff=1 type=half pitch=C5
         β”œβ”€ 24--48 Note id=n03 voice=2 staff=1 type=half pitch=E5
         β”œβ”€ 0--48 Page number=1
         └─ 0--48 System number=1
  

If lilypond or MuseScore are installed on the system, the following command renders the part to an image and displays it:

pt.render(part)

Score example

The notes in this part can be accessed through the property part.notes:

part.notes
> [<partitura.score.Note object at 0x...>, <partitura.score.Note object at 0x...>, 
> <partitura.score.Note object at 0x...>]

The following code stores the start, end, and midi pitch of the notes in a numpy array:

import numpy as np
pianoroll = np.array([(n.start.t, n.end.t, n.midi_pitch) for n in part.notes])
print(pianoroll)
> [[ 0 48 69]
>  [24 48 72]
>  [24 48 76]]

The note start and end times are in the units specified by the divisions element of the MusicXML file. This element specifies the duration of a quarter note. The divisions value 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_map that converts timeline times into beat times:

beat_map = part.beat_map
print(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 (using additive 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 synthesis
pt.save_wav(part, 'mypart.wav')

More elaborate examples can be found in the documentation <https://partitura.readthedocs.io/en/latest/index.html>_.

Import other formats

For MusicXML files do:

import partitura as pt
my_xml_file = pt.EXAMPLE_MUSICXML
score = pt.load_musicxml(my_xml_file)

For Kern files do:

import partitura as pt
my_kern_file = pt.EXAMPLE_KERN
score = pt.load_kern(my_kern_file)

For MEI files do:

import partitura as pt
my_mei_file = pt.EXAMPLE_MEI
score = pt.load_mei(my_mei_file)

One can also import any of the above formats by just using:

import partitura as pt
any_score_format_path = pt.EXAMPLE_MUSICXML
score = pt.load_score(any_score_format_path)

License

The code in this package is licensed under the Apache 2.0 License. For details, please see the LICENSE file.

Citing Partitura

If 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}
}

Acknowledgments

This 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")

More Repositories

1

madmom

Python audio and music signal processing library
Python
1,289
star
2

msmd

A Multimodal Audio Sheet Music Dataset
Jupyter Notebook
77
star
3

wechsel

Code for WECHSEL: Effective initialization of subword embeddings for cross-lingual transfer of monolingual language models.
Python
73
star
4

onset_detection

Python implementation of the most common spectral based onset detection algorithms.
Python
65
star
5

onset_db

Onset data set which can be used to tune/evaluate onset detection algorithms.
57
star
6

SuperFlux

Python reference implementation of the SuperFlux onset detection algorithm
Python
52
star
7

score_following_game

Learning to Listen, Read, and Follow: Score Following as a Reinforcement Learning Game
Python
50
star
8

madmom_tutorials

Tutorials for the madmom package.
Jupyter Notebook
50
star
9

beat_this

Accurate and general beat tracker
Python
49
star
10

deep_lda

Implementation of Deep Linear Discriminant Analysis (DeepLDA)
Python
48
star
11

EfficientLEAF

Official implementation of EfficientLEAF, a learnable audio frontend.
Python
38
star
12

audioLIME

audioLIME: Listenable Explanations Using Source Separation
Python
33
star
13

cca_layer

Implementation of Canonical Correlation Analysis Layer for Cross-Modality Retrieval.
Python
31
star
14

dcase_task2

Training General-Purpose Audio Tagging Networks with Noisy Labels and Iterative Self-Verification
Python
29
star
15

audio_sheet_retrieval

Learning Audio–Sheet Music Correspondences for Cross-Modal Retrieval and Piece Identification
Jupyter Notebook
25
star
16

BallroomAnnotations

This repo includes beat and bar annotations for the ballroom dataset.
24
star
17

audio_conditioned_unet

Audio-Conditioned U-Net for Position Estimation in Full Sheet Images
Python
24
star
18

madmom_models

Trained data models for madmom: https://github.com/CPJKU/madmom
Python
21
star
19

basismixer

The Basis Mixer is an implementation of the Basis Function Modeling framework for musical expression
Python
19
star
20

cpjku_dcase22

Python
18
star
21

partitura_tutorial

A quick introduction to symbolic music processing with partitura
Jupyter Notebook
13
star
22

recommendation_systems_fairness

This repository accompaines the paper "Investigating Gender Fairness of Recommendation Algorithms in the Music Domain"
Jupyter Notebook
12
star
23

cyolo_score_following

Multi-modal Conditional Bounding Box Regression for Music Score Following
Python
12
star
24

composer_concept

Supervised and unsupervised Concept-based explanation of pretrained music classifiers
Python
12
star
25

kagglebirds2020

7th place solution for the Cornell Birdcall Identification Kaggle Challenge
Python
11
star
26

schimmel

Simple Cython Hidden Markov Model Extension Library
Python
11
star
27

LEMONS

Listenable Explanations for Music recOmmeNder Systems
Python
10
star
28

accompanion

An expressive accompaniment system for piano performances
Python
10
star
29

da

Pytorch domain adaptation package
Python
10
star
30

ScaLearn

ScaLearn: Simple and Highly Parameter-Efficient Task Transfer by Learning to Scale
Python
8
star
31

paow

generation experiments
Jupyter Notebook
8
star
32

cpjku_dcase24

Python
7
star
33

adv-multvae

This repository accompanies the paper "Unlearning Protected User Attributes in Recommendations with Adversarial Training"
Python
7
star
34

piano_svsep

Code for the paper Cluster and Separate: A GNN Approach to Voice and Staff Prediction for Score Engraving
Python
6
star
35

DeepGenIR

Code for "A Modern Perspective on Query Likelihood with Deep Generative Retrieval Models"
Python
6
star
36

basismixer-notebooks

A collection of jupyter notebooks demonstrating the basis mixer package
Python
6
star
37

pers_bias

Jupyter Notebook
4
star
38

ModularizedDebiasing

Jupyter Notebook
4
star
39

veracity

Python
4
star
40

performance_embeddings_fire23

Jupyter Notebook
3
star
41

accompanion_ijcai2023

Supplementary material for "The ACCompanion: Combining Reactivity, Robustness, and Musical Expressivity in an Automatic Piano Accompanist" presented at IJCAI-23
Python
3
star
42

dcase2024_task1_baseline

Python
3
star
43

FairnessRetrievalResults

Code and resources of the paper "Societal Biases in Retrieved Contents: Measurement Frameworkand Adversarial Mitigation for BERT Rankers"
Python
3
star
44

accompanion_pieces

Pieces, scores and performances for playing with the accompanion.
2
star
45

plausible_xai

Python
2
star
46

expressivity

Visualizing Musical Expression
JavaScript
2
star
47

performance_similarity_dlfm23

Jupyter Notebook
1
star
48

user-interaction-gender-bias-IR

Code & experiments on the inherent gender bias of the users of search engines
1
star
49

con_espressione_game_ismir2020

Experiments for first results of the Con Espressione Game analysis, accepted for ISMIR 2020
Jupyter Notebook
1
star
50

beat_this_annotations

Beat annotations for the beat tracker Beat This!
Python
1
star