Save & Load
Pypianoroll supports efficient I/O for pypianoroll.Multitrack
objects. The piano rolls will be first converted to sparse matrices (specifically, instances of scipy.sparse.csc_matrix
) and then stored in a NPZ file.
Functions
- pypianoroll.save(path: Union[str, pathlib.Path], multitrack: Multitrack, compressed: bool = True)[source]
Save a Multitrack object to a NPZ file.
- Parameters
path (str or Path) – Path to the NPZ file to save.
multitrack (
pypianoroll.Multitrack
) – Multitrack to save.compressed (bool, default: True) – Whether to save to a compressed NPZ file.
Notes
To reduce the file size, the piano rolls are first converted to instances of
scipy.sparse.csc_matrix
. The component arrays are then collected and saved to a npz file.See also
pypianoroll.load()
Load a NPZ file into a Multitrack object.
pypianoroll.write()
Write a Multitrack object to a MIDI file.
Note
The saved .npz file is basically a zip archive which contains the following files:
component arrays of the piano rolls in compressed sparse column format:
pianoroll_[index]_csc_data.npy
pianoroll_[index]_csc_indices.npy
pianoroll_[index]_csc_indptr.npy
tempo.npy
: the tempo arraydownbeat.npy
: the down beat arrayinfo.json
: a JSON file that contains meta data and track information
- pypianoroll.load(path: Union[str, pathlib.Path]) pypianoroll.multitrack.Multitrack [source]
Load a NPZ file into a Multitrack object.
Supports only files previously saved by
pypianoroll.save()
.- Parameters
path (str or Path) – Path to the file to load.
See also
pypianoroll.save()
Save a Multitrack object to a NPZ file.
pypianoroll.read()
Read a MIDI file into a Multitrack object.