liveBook · Manning

Piano roll representation

As explained in Learn Generative AI with PyTorch

A grid-based representation of musical notes over time and pitch, commonly used to encode MIDI-like music for computation.

A piano roll represents music as a grid: time runs horizontally, pitch vertically, and note blocks show when notes begin and how long they last. It supports both visualization and digital processing, especially with MIDI sequencing software and DAWs. section 13.1.3 section 13.0

For computation, each note can become a pitch number and then a one-hot vector. A training example uses shape (4, 2, 16, 84): four tracks, two bars, sixteen time steps per bar, and 84 possible pitches at each step. section 13.0

The representation preserves several musical properties:

  • Vertical position identifies pitch, while horizontal position identifies timing. section 13.1.3
  • Block length represents note duration; quantized note output exposes successive time offsets. section 13.1.3

From MIDI notes to a piano-roll tensor

Using music21, inspect notes with their offsets and MIDI pitches, then map each pitch into the 0–83 range and encode it at its quantized time step. The resulting tensor can later be converted back into a MIDI file for playback. section 13.1

How Learn Generative AI with PyTorch covers it

How deep it goes
Explains grid semantics, quantized notes, pitch mapping, one-hot encoding, and tensor shape, while deferring model internals.
Examples
Uses Bach chorales, music21 note listings, a two-bar piano-roll figure, and a (4, 2, 16, 84) tensor.
What it assumes
Builds from musical notes, pitch numbers, octaves, MIDI files, and basic grid dimensions.
What you can do after
Apply it via music21 to inspect MIDI notes and organize them as a multidimensional training tensor.
How it connects
Connects piano rolls with MIDI, music21, quantization, one-hot encoding, and generative adversarial networks.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Generative AI with PyTorch. The section links point to the parts of the book it draws on.