# Turn a song into four Game Boy voices

This is how the music of Gambeta (https://gambeta.futbol) was made: more
than thirty songs, no audio files. The result of this procedure is data,
not sound. A small synth plays it.

The part a script can do is small. The part that matters is choosing, by
ear, which part of the source plays what. Do not skip the listening step
and do not decide it for the person: build them a way to hear each choice.

## The target format

Four monophonic voices on a grid of sixteenth notes:

```json
{ "bpm": 90, "steps": 1040,
  "lead": [[0, 79, 2], [2, 81, 4]],
  "harm": [[0, 74, 6]],
  "bass": [[0, 43, 2]],
  "drums": [[0, "B"], [4, "SH"]] }
```

Notes are `[step, midi note, length in steps]`. Drums are `[step, hits]`
with `B` kick, `S` snare, `H` closed hi-hat, `C` cymbal. A synth for this
format, in about a hundred lines of Web Audio, is in
https://zajdband.com/gambeta-music/toys.js: the functions `audio`, `tone`,
`noise` and `play` (square wave for the lead, a 25%
pulse for the harmony, a triangle for the bass, filtered noise for the
drums).

## 1. Get notes from whatever exists

In order of preference:

- **A MIDI, or a karaoke `.kar`** (a MIDI with the lyrics as text events).
  Free MIDI sites vary a lot by genre and country; try several. Reject a
  MIDI that was transcribed from audio: it is unusable, look for another
  source instead of cleaning it.
- **A Guitar Pro tab** (`.gp5`), often available when no good MIDI is, and
  tabs usually carry the vocal line. Parse it (for example with
  `pyguitarpro`) into one MIDI track per instrument. Pitch is the string's
  tuning plus the fret; on percussion tracks it is the note value. Merge
  tied notes into one note and skip dead notes. Tab sites often need an
  account to download: ask the person to download and hand it over.
- **A score in a PDF.** Transcribe the line you need by hand into a compact
  notation (note and duration per token), transpose it to the key of the
  MIDI you are combining it with, and place each phrase where it is sung.
  If the MIDI is a karaoke, its lyric events tell you where.
- **A web sequencer** (sites where people write songs in the browser).
  These export their own formats; onlinesequencer.net serves a protobuf
  you can decode without a library. Expect every voice in one instrument;
  authors usually separate them by volume, so split by volume and register.
  If it was played by hand it drifts: measure the offset of a part that
  plays on a regular grid against that grid, fit a straight line to offset
  over time, and subtract it from every note before quantizing.

## 2. Summarize the tracks

For each track with notes: index, name, instrument (or drums, channel 10),
note count, lowest and highest note, average note, and the bars where it
plays. This summary is what the person and any model reason about.

A starting guess: drums are the percussion tracks, the bass is the lowest
tonal track, the melody the highest one with plenty of notes, the harmony
the next. Present it as a guess. The melody is the vocal line or whatever
doubles it (a flute, strings, a trumpet), which is often not the highest
track.

## 3. Let the person choose by ear

Give them a page, not a command line: every track with a button to hear it
alone, already in the target voice, and a selector for its role (melody,
harmony, bass, drums or nothing). Several tracks may feed one voice. Also:
the section (from which bar, fractions allowed, and how many bars), a "no
cymbals" switch, and a choice of a fixed 16 step drum pattern to replace
the MIDI's drums. Play the result from where it was playing every time a
choice changes.

## 4. Convert

- One step is `ppq / 4` ticks. Round every start and length to steps.
- Melody and harmony: at each step keep the highest note of the tracks in
  that voice; bass: the lowest. Cut each note where the next one starts.
- Drums, General MIDI: 35 and 36 kick; 37 to 40 snare; 42, 44, 46 hi-hat;
  49, 51, 52, 55, 57 cymbal. Ignore the rest.
- Drums played live are off the grid and sound wrong once quantized.
  Replace them with a 16 step pattern in every bar where the MIDI had
  drums. Patterns that worked: cumbia `B...S.B.B...S...`, rock
  `B...S...B.B.S...`, candombe `S.HS.HSB.HSBSHBB`, march
  `B...S...B...S...`.
- Cut to the section last, trimming notes that cross its end.

## 5. Fix what the conversion breaks

- **A melody with holes** (verses where only a few loose notes are left):
  if a riff elsewhere in the song uses the same chords, put the riff there
  and move the loose notes to the harmony. Or drop every stretch where the
  melody is silent for two bars or more.
- **A voice from another source** (step 1): lay it over the converted song
  and remove the base melody notes inside the spans it covers.
- **Tempo**: expect to be asked for faster or slower. Keep it as a number
  in the song, not baked into the notes.

Keep the command or script that produces each song next to it, with the
choices and the reason for each. Songs get redone.

## 6. If a model helps choose

Send it the track summary, the current choices and the bar that is
playing, with the person's request in their words. Ask for structured
output: a sentence or two for the person, all the choices (not only the
changed ones), and a note for anything the tool cannot do. Validate the
indices it returns against the file before applying them.

---

From [Gambeta's music: from anything that looks like a score to a Game Boy](https://zajdband.com/gambeta-music/) by Dan Zajdband, CC BY 4.0
(https://creativecommons.org/licenses/by/4.0/). This is the procedure behind that article, published
separately so you can act on it.
