Pitch-based Representation
- muspy.to_pitch_representation(music, use_hold_state=False, dtype=<class 'int'>)[source]
Encode a Music object into pitch-based representation.
The pitch-based represetantion represents music as a sequence of pitch, rest and (optional) hold tokens. Only monophonic melodies are compatible with this representation. The output shape is T x 1, where T is the number of time steps. The values indicate whether the current time step is a pitch (0-127), a rest (128) or, optionally, a hold (129).
- Parameters
music (
muspy.Music
) – Music object to encode.use_hold_state (bool, default: False) – Whether to use a special state for holds.
dtype (np.dtype, type or str, default: int) – Data type of the return array.
- Returns
Encoded array in pitch-based representation.
- Return type
ndarray, shape=(?, 1)
- muspy.from_pitch_representation(array, resolution=24, program=0, is_drum=False, use_hold_state=False, default_velocity=64)[source]
Decode pitch-based representation into a Music object.
- Parameters
array (ndarray) – Array in pitch-based 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.
use_hold_state (bool, default: False) – Whether to use a special state for holds.
default_velocity (int, default: muspy.DEFAULT_VELOCITY (64)) – Default velocity value to use when decoding.
- Returns
Decoded Music object.
- Return type
References
[1] https://www.midi.org/specifications/item/gm-level-1-sound-set
- class muspy.PitchRepresentationProcessor(use_hold_state=False, default_velocity=64)[source]
Pitch-based representation processor.
The pitch-based represetantion represents music as a sequence of pitch, rest and (optional) hold tokens. Only monophonic melodies are compatible with this representation. The output shape is T x 1, where T is the number of time steps. The values indicate whether the current time step is a pitch (0-127), a rest (128) or, optionally, a hold (129).
- use_hold_state
Whether to use a special state for holds.
- Type
bool, default: False
- default_velocity
Default velocity value to use when decoding.
- Type
int, default: 64