f19e3f0633
- 01-basic-chord.py: chord progressions (C major) - 02-90s-dance-track.py: 5-track 90s dance (arp, bass, pads, drums, piano) - 03-arpeggiator.py: reusable arpeggio generator with dir/type options - 04-single-note.py: minimal single-note example - Rewrite compose_neon_dreams.py: cleaner track functions, proper velocity=0 note_off, tick helper - Add README.md with setup and API reference Uses MIDIUtil library (beats-based API) instead of mido (clocks-based API)
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
01-basic-chord.py - MIDIUtil basic example
|
|
Creates a simple chord progression in C major using MIDIUtil.
|
|
"""
|
|
from midiutil import MIDIFile
|
|
|
|
# === Setup ===
|
|
degrees = [
|
|
[60, 64, 67], # C3 (C4, E4, G4)
|
|
[62, 65, 69], # D3 (D4, F4, A4)
|
|
[64, 67, 71], # E3 (E4, G4, B4)
|
|
[65, 69, 72], # F3 (F4, A4, C5)
|
|
] # Chords: C, Dm, Em, F
|
|
|
|
track = 0 # Track index
|
|
channel = 0 # MIDI channel 1
|
|
time = 0 # Start at beat 0
|
|
duration = 1 # Each chord lasts 1 beat (quarter note)
|
|
bpm = 120
|
|
volume = 100 # MIDI velocity 0-127
|
|
|
|
# === Create MIDI File ===
|
|
my_midi = MIDIFile(1) # 1 user track + auto tempo track = format 1
|
|
my_midi.addTempo(track, 0, bpm)
|
|
my_midi.addTrackName(track, 0, "Basic Chord Progression")
|
|
|
|
# === Add Notes ===
|
|
for chord in degrees:
|
|
for pitch in chord:
|
|
my_midi.addNote(track, channel, pitch, time, duration, volume)
|
|
time += duration # Advance one beat per chord
|
|
|
|
# === Write to Disk ===
|
|
with open("basic-chord.mid", "wb") as output_file:
|
|
my_midi.writeFile(output_file)
|
|
|
|
print("Written: basic-chord.mid")
|