2026-04-17 21:54:54 +00:00
|
|
|
# MIDI Util Examples
|
2026-04-17 17:52:33 +01:00
|
|
|
|
2026-04-17 21:54:54 +00:00
|
|
|
Working examples created from the [MIDIUtil](https://github.com/MarkCWirt/MIDIUtil) source repo patterns.
|
|
|
|
|
All examples use MIDIUtil with beats-based (not ticks-based) time, the cleanest API for MIDI composition.
|
2026-04-17 17:42:16 +00:00
|
|
|
|
2026-04-17 21:54:54 +00:00
|
|
|
## Setup
|
2026-04-17 17:42:16 +00:00
|
|
|
|
2026-04-17 21:54:54 +00:00
|
|
|
```bash
|
|
|
|
|
pip3 install --break-system-packages MIDIUtil
|
|
|
|
|
sudo apt-get install -y fluidsynth fluid-soundfont-gm
|
|
|
|
|
```
|
2026-04-17 17:42:16 +00:00
|
|
|
|
2026-04-17 21:54:54 +00:00
|
|
|
## Examples
|
2026-04-17 17:42:16 +00:00
|
|
|
|
2026-04-17 21:54:54 +00:00
|
|
|
| # | File | Description |
|
|
|
|
|
|---|------|------|
|
|
|
|
|
| 01 | basic-chord.py | Chord progressions in C major |
|
|
|
|
|
| 02 | 90s-dance-track.py | Full multi-track 90s dance composition (arpeggio, bass, pads, drums, piano) |
|
|
|
|
|
| 03 | arpeggiator.py | Automated arpeggiator with ascending/descending patterns |
|
|
|
|
|
| 04 | single-note.py | Minimal single-note example |
|
2026-04-17 17:42:16 +00:00
|
|
|
|
|
|
|
|
## Quick Start
|
|
|
|
|
|
2026-04-17 21:54:54 +00:00
|
|
|
```bash
|
|
|
|
|
cd examples/
|
|
|
|
|
python3 04-single-note.py
|
|
|
|
|
python3 01-basic-chord.py
|
|
|
|
|
python3 03-arpeggiator.py
|
|
|
|
|
python3 02-90s-dance-track.py
|
|
|
|
|
|
|
|
|
|
# Play back with fluidsynth
|
|
|
|
|
fluidsynth -a alsa /usr/share/sounds/sf2/FluidR3_GM.sf2 90s-dance-track.mid
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## API Reference
|
|
|
|
|
|
|
|
|
|
All time values are **in beats** (quarter notes):
|
|
|
|
|
|
|
|
|
|
| Method | Signature |
|
|
|
|
|
|--------|-----------|
|
|
|
|
|
| `addNote` | `(track, channel, pitch, time, duration, volume)` |
|
|
|
|
|
| `addTempo` | `(track, time, bpm)` |
|
|
|
|
|
| `addTrackName` | `(track, time, name)` |
|
|
|
|
|
| `addProgramChange` | `(track, channel, time, program)` |
|
|
|
|
|
| `addControllerEvent` | `(track, channel, time, controller, value)` |
|
|
|
|
|
| `writeFile` | `(fileHandle)` |
|