Piano-roll Representation
- muspy.to_pianoroll_representation(music, encode_velocity=True, dtype=None)[source]
Encode notes into piano-roll representation.
- Parameters
music (
muspy.Music
) – Music object to encode.encode_velocity (bool, default: True) – Whether to encode velocities. If True, a binary-valued array will be return. Otherwise, an integer array will be return.
dtype (np.dtype, type or str, optional) – Data type of the return array. Defaults to uint8 if encode_velocity is True, otherwise bool.
- Returns
Encoded array in piano-roll representation.
- Return type
ndarray, shape=(?, 128)
- muspy.from_pianoroll_representation(array, resolution=24, program=0, is_drum=False, encode_velocity=True, default_velocity=64)[source]
Decode piano-roll representation into a Music object.
- Parameters
array (ndarray) – Array in piano-roll representation to decode.
resolution (int, default: muspy.DEFAULT_RESOLUTION (24)) – Time steps per quarter note.
program (int, default: 0 (Acoustic Grand Piano)) – Program number, according to General MIDI specification [1]. Valid values are 0 to 127.
is_drum (bool, default: False) – Whether it is a percussion track.
encode_velocity (bool, default: True) – Whether to encode velocities.
default_velocity (int, default: muspy.DEFAULT_VELOCITY (64)) – Default velocity value to use when decoding. Only used when encode_velocity is True.
- Returns
Decoded Music object.
- Return type
References
[1] https://www.midi.org/specifications/item/gm-level-1-sound-set
- class muspy.PianoRollRepresentationProcessor(encode_velocity=True, default_velocity=64)[source]
Piano-roll representation processor.
The piano-roll represetantion represents music as a time-pitch matrix, where the columns are the time steps and the rows are the pitches. The values indicate the presence of pitches at different time steps. The output shape is T x 128, where T is the number of time steps.
- encode_velocity
Whether to encode velocities. If True, a binary-valued array will be return. Otherwise, an integer array will be return.
- Type
bool, default: True
- default_velocity
Default velocity value to use when decoding if encode_velocity is False.
- Type
int, default: 64