Skip to content

muspy truncates MIDI files' lengths when converted to numpy arrays #84

@RishabhMalviya

Description

@RishabhMalviya

I'm trying to convert a MIDI file into a PyTorch Tensor, but muspy seems to be truncating the file.

This is the file's Music representation (after reading it in with test_music = muspy.read_midi('...'):

metadata:
  schema_version: '0.2'
  title: Aeri Aali - Sthaayi 1.1_2
  source_filename: Aeri Aali - Sthaayi 1.1_2.mid
  source_format: midi
resolution: 96
time_signatures:
- time: 0
  numerator: 4
  denominator: 4
- time: 0
  numerator: 4
  denominator: 4
tracks:
- program: 0
  is_drum: false
  notes:
  - time: 0
    pitch: 72
    duration: 24
    velocity: 93
  - time: 21
    pitch: 73
    duration: 33
    velocity: 49
  ...
  - time: 672
    pitch: 68
    duration: 21
    velocity: 96
  - time: 717
    pitch: 68
    duration: 42
    velocity: 119

The last note ends at timestep 759 (0-indexed). So, when I convert this Music object to a piano roll representation using muspy.to_representation(test_music, kind='piano-roll'), I get an array of length 760:

array([[0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       ...,
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0]], shape=(760, 128), dtype=uint8)

But the original MIDI clip was 768 timesteps long (96 timesteps/beat * 8 beats = 768 timesteps).

How can I get muspy to give me a Tensor that is 768 timesteps long? This is important to my application as the notes need to be placed in the context of the full beat lengths.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions