Piano-roll Representation

muspy.to_pianoroll_representation(music: Music, encode_velocity: bool = True) → numpy.ndarray[source]

Encode notes into piano-roll representation.

Parameters:
  • music (muspy.Music object) – Music object to encode.
  • encode_velocity (bool) – Whether to encode velocities. If True, a binary-valued array will be return. Otherwise, an integer array will be return. Defaults to True.
Returns:

Encoded array in piano-roll representation.

Return type:

ndarray, dtype=uint8 or bool, shape=(?, 128)

muspy.from_pianoroll_representation(array: numpy.ndarray, resolution: int = 24, program: int = 0, is_drum: bool = False, encode_velocity: bool = True, default_velocity: int = 64) → muspy.music.Music[source]

Decode pitch-based representation into a Music object.

Parameters:
  • array (ndarray) – Array in piano-roll representation to decode. Will be casted to integer if not of integer type. If encode_velocity is True, will be casted to boolean if not of boolean type.
  • resolution (int) – Time steps per quarter note. Defaults to muspy.DEFAULT_RESOLUTION.
  • program (int, optional) – Program number according to General MIDI specification [1]. Acceptable values are 0 to 127. Defaults to 0 (Acoustic Grand Piano).
  • is_drum (bool, optional) – A boolean indicating if it is a percussion track. Defaults to False.
  • encode_velocity (bool) – Whether to encode velocities. Defaults to True.
  • default_velocity (int) – Default velocity value to use when decoding. Defaults to 64.
Returns:

Decoded Music object.

Return type:

muspy.Music object

References

[1] https://www.midi.org/specifications/item/gm-level-1-sound-set

class muspy.PianoRollRepresentationProcessor(encode_velocity: bool = True, default_velocity: int = 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. Defaults to True.

Type:bool
default_velocity

Default velocity value to use when decoding if encode_velocity is False. Defaults to 64.

Type:int
decode(array: numpy.ndarray) → muspy.music.Music[source]

Decode piano-roll representation into a Music object.

Parameters:array (ndarray) – Array in piano-roll representation to decode. Will be casted to integer if not of integer type. If encode_velocity is True, will be casted to boolean if not of boolean type.
Returns:Decoded Music object.
Return type:muspy.Music object

See also

muspy.from_pianoroll_representation()
Return a Music object converted from piano-roll representation.
encode(music: muspy.music.Music) → numpy.ndarray[source]

Encode a Music object into piano-roll representation.

Parameters:music (muspy.Music object) – Music object to encode.
Returns:Encoded array in piano-roll representation.
Return type:ndarray (np.uint8)

See also

muspy.to_pianoroll_representation()
Convert a Music object into piano-roll representation.