A C program that generates randomised backing tracks using concurrent child processes and raw MIDI file construction — no external music libraries required.
The parent process reads user parameters (BPM, genre, key, bars), then spawns 3 child processes concurrently over pipes — one for each instrument. Each child independently generates a MIDI track and pipes it back to the parent, which merges them into a single .mid file and renders it to .ogg via TiMidity++.
┌───────────────────────────┐
│ PARENT PROCESS │
│ │
│ Reads: BPM, Genre, │
│ Key, Bars │
└────────────┬──────────────┘
│
fork() × 3 + pipes
│
┌───────────────────────────┼─────────────────────────┐
│ │ │
▼ ▼ ▼
┌────────────────┐ ┌────────────────┐ ┌────────────────┐
│ CHILD: DRUMS │ │ CHILD: GUITAR │ │ CHILD: PIANO │
│ │ │ │ │ │
│ Kick, snare, │ │ Strummed chord │ │ Melodic runs │
│ hi-hat pattern │ │ progressions │ │ chord voicing │
└───────┬────────┘ └───────┬────────┘ └───────┬────────┘
│ │ │
│ MIDI track bytes (via pipe) │
└───────────────────────────┼─────────────────────────┘
│
▼
┌───────────────────────────┐
│ PARENT PROCESS │
│ │
│ Merges 3 tracks into │
│ SMF Type 1 MIDI file │
│ │
│ Calls TiMidity++ to │
│ render → output.ogg │
└───────────────────────────┘
| # | Genre | Chord Style | Progressions |
|---|---|---|---|
| 0 | Pop | Triads + 7ths | 7 (Classic, Bright, Emotional, Dreamy) |
| 1 | Lo-fi | 7th chords (jazzy) | 10 (Chill, Dreamy, Sad, Neo-Soul) |
| 2 | Rock | Power chords + triads | 8 (Classic, Dark, Garage Punk) |
| 3 | Loony Tunes | Major/minor triads | 1 (fixed cartoon progression) |
Each genre has custom drum patterns, guitar voicings, piano scales, and instrument patches (General MIDI).
- GCC (C99)
- TiMidity++ — for rendering MIDI to audio
sudo apt install timidity # Debian/Ubuntu
brew install timidity # macOS (Homebrew)make
./midi_genThe program is fully interactive. You will be prompted for:
BPM (tempo) [40-240]:
Number of bars [1-64]:
Genre 0=Pop 1=Lo-fi 2=Rock 3=Loony-Tunes
Key root (e.g. C4, G#3, Bb4 — full list shown at prompt)
| File | Description |
|---|---|
output.mid |
Raw MIDI file (SMF Type 1, 4 tracks) |
output.ogg |
Rendered audio — open in any media player |
midi_gen.c — full source (parent + 3 child workers)
Makefile — builds with: make
╔══════════════════════════════════════╗
║ MIDI Banger Generator ║
╚══════════════════════════════════════╝
BPM (tempo) [40-240]: 120
Number of bars [1-64]: 8
Genre 0=Pop 1=Lo-fi 2=Rock 3=Loony-Tunes
Genre [0-3]: 2
Key root: G3
──────────────── LOG ────────────────
[Parent] BPM=120 bars=8 genre=Rock key=55
[Parent] Rock progression: Dark Rock im-bVII-bVI-V
[Drums] Genre selected: Rock
[Guitar] Genre selected: Rock
[Piano] Genre selected: Rock
─────────────────────────────────────
╔══════════════════════════════════════╗
║ Banger Generated! ║
║ ║
║ MIDI -> output.mid ║
║ Audio -> output.ogg ║
╚══════════════════════════════════════╝