# Midnight Circuit — original MIDI composition and synthesized preview

An original, reproducible musical example created for the Kingy.ai Astra music guide. The composition is 64 bars of melodic UK garage at 130 BPM, in 4/4 and D minor. It contains 1,926 note events across drums, bass, chords, lead, and pad.

The WAV files demonstrate the supplied synthesis code. They do not use a commercial text-to-music model, recorded samples, a celebrity voice, or an imitation of a named artist. These are composition previews, not professionally mastered recordings. Automated validation was completed; no listening-panel evaluation or Ableton playback test is claimed.

## Listen and compare

- `midnight-circuit-preview.wav`: full 64-bar arrangement, 1:58.154.
- `comparison-basic-16-bars.wav`: deliberately simple, straight, repetitive control arrangement, 0:29.538.
- `comparison-revised-16-bars.wav`: the corresponding revised bars 9–24, with swing, syncopation, voice leading, pads, and variation, 0:29.538.

The two comparison files use the same sound engine, tempo, duration, and −20 dBFS RMS target. RMS matching is not perceptual loudness matching. The revised version changes several musical choices at once; this demonstrates a revision, not a controlled test of one variable or proof that one version is objectively better. The control was deliberately constructed for comparison; it is not a transcript of a separate model run.

## Files

| File | Purpose |
|---|---|
| `midnight-circuit-full.mid` | Standard MIDI format 1: tempo/marker track plus five instrument tracks |
| `midnight-circuit-drums.mid` | Separate percussion MIDI, channel 10 |
| `midnight-circuit-bass.mid` | Separate monophonic bass MIDI, channel 1 |
| `midnight-circuit-chords.mid` | Separate four-voice chord MIDI, channel 2 |
| `midnight-circuit-lead.mid` | Separate lead MIDI, channel 3 |
| `midnight-circuit-pad.mid` | Separate five-voice pad MIDI, channel 4 |
| `comparison-basic-16-bars.mid` | Straight 16-bar control arrangement |
| `comparison-revised-16-bars.mid` | Revised 16-bar arrangement from bars 9–24 |
| `generate_midnight_circuit.py` | Complete MIDI generator; Python 3 standard library only |
| `render_preview.py` | Optional sample-free synthesizer; requires NumPy |
| `validate_example.py` | Independent MIDI/WAV parser and checks; standard library only |
| `score.json` | Machine-readable note events for editing or visualization |
| `validation.json` | File structure, timing, pitch ranges, and audio validation |
| `render-metrics.json` | Renderer gain and audio measurements |

## Reproduce

Use Python 3.10 or newer. From the extracted bundle's directory:

```bash
python3 generate_midnight_circuit.py --out generated
```

This writes eight MIDI files and a JSON score. It needs no extra Python packages, DAW, network connection, samples, or API key. The seed is fixed at `260907`.

Optional WAV rendering uses NumPy. If NumPy is missing, install it in your preferred Python environment, then run:

```bash
python3 -m pip install numpy
python3 render_preview.py --out generated
python3 validate_example.py generated
```

The included WAVs were rendered using the supplied renderer. MIDI generation is deterministic with the supplied Python code and seed. Floating-point audio results can vary slightly across Python/NumPy/platform versions; audible structure remains the same. The independent validator expects all eight MIDI files and all three rendered WAV files.

## Bring it into Ableton Live or another DAW

1. Set the session to 130 BPM and 4/4.
2. Import the full MIDI file or place the five separate MIDI files on separate MIDI tracks, all starting at bar 1. They include the full timeline, so later notes remain aligned.
3. Assign a drum rack, a mono synth bass, a mellow electric-piano sound, a plucked lead, and a soft pad. MIDI does not contain these sounds. Program changes provide General MIDI hints; a DAW can ignore them.
4. Start with Groove Pool Amount at 0. Swing and small timing/velocity changes are already baked into the note data. Applying another groove can double the displacement.
5. Match the drum rack to the MIDI note numbers below. Octave names vary between DAWs, so use note numbers as the source of truth.
6. Balance the sounds by ear and compare the new DAW arrangement with the supplied synthesis preview. Sound selection, envelopes, effects, and mix choices will change the result.

| MIDI note | Sound |
|---|---|
| 36 | Kick |
| 37 | Side stick/rim |
| 38 | Snare |
| 39 | Hand clap |
| 42 | Closed hi-hat |
| 46 | Open hi-hat |

## Musical design

| Bars | Section | Musical change |
|---|---|---|
| 1–8 | Intro | Pads, then hats and chord stabs; bass and fragments of the hook enter late |
| 9–16 | A | Main two-step groove and full call/answer melody |
| 17–24 | A variation | Extra clap/rim detail, octave answer notes, short lead pickups |
| 25–32 | B | Longer bass values, arpeggiated chords, lower-register melodic contrasts |
| 33–40 | Breakdown | Sparse bass and percussion, exposed pads, long melodic fragments, snare pickup |
| 41–48 | Return | Full groove returns with fills and melodic pickups |
| 49–56 | Climax | Additional chord syncopation, occasional extra kick, octave accents |
| 57–64 | Outro | Layers leave; drums stop after bar 62; bars 63–64 resolve to Dm9 |

The main progression uses two bars each of **Dm9 → B♭maj7 → Fmaj7 → Cadd9**. The upper chord voicings are `[53,57,60,64]`, `[53,57,58,62]`, `[53,57,60,64]`, and `[55,60,62,64]`. Dm9 receives its D root from bass/pad, so its upper notes intentionally match Fmaj7. Common tones and small voice movements connect the chords.

The opening lead call is **D5–F5–E5–A4–C5**, using scientific pitch notation and MIDI notes `[74,77,76,69,72]`. Its timing, answers, register, and chord-tone landings change throughout the arrangement. The groove uses syncopated kicks, backbeat snares, alternating hat accents, and offbeat sixteenths delayed by 0.035 quarter-note beats: a nominal 57:43 sixteenth swing. Small seeded variations are applied after that displacement.

The renderer uses synthesized drum transients and noise, sine-based bass, electric-piano-like chord tones, an FM pluck lead, and detuned sine pads. It adds fixed tempo-related delay repeats, gentle kick-triggered bass/pad ducking, constant-power panning, and static RMS gain. There are no downloaded sounds and no mastering limiter.

## What was verified

An independent standard-library parser read all eight MIDI files. Every note-on has a later note-off; there are no same-channel same-pitch overlaps, and every MIDI track ends at its exact 64- or 16-bar boundary. The full MIDI contains six tracks: one tempo/marker track and five instrument tracks. Resolution is 960 ticks per quarter note.

MIDI stores tempo in whole microseconds. The encoded tempo is 461,538 μs per quarter note, approximately 130.00013 BPM. Consequently, 64 bars last 118.153728 seconds. The 32 kHz WAV rounds this to the nearest sample: 118.15371875 seconds.

All three WAV files are non-silent, stereo, 32 kHz, 16-bit PCM, and have zero clipped samples. The full preview measures −3.941 dBFS peak and −20.000 dBFS RMS. These checks establish file integrity and basic signal properties, not artistic quality, true-peak safety after lossy encoding, or translation to every playback system.

| Track | MIDI pitch range | Note events |
|---|---:|---:|
| Drums | 36–46 | 846 |
| Bass | 34–53 | 173 |
| Chords | 53–64 | 516 |
| Lead | 55–89 | 231 |
| Pad | 46–76 | 160 |

The source is supplied for readers to inspect, run, edit, and develop into their own arrangement. The composition was newly generated for this guide; no exhaustive similarity search or legal clearance is claimed.
