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)
32 lines
915 B
Python
32 lines
915 B
Python
#!/usr/bin/env python3
|
|
"""
|
|
04-single-note.py - Single note example (from MIDIUtil docs, adapted)
|
|
Creates a minimal single-track MIDI file with one note.
|
|
Reference: examples/single-note-example.py from MIDIUtil repo
|
|
"""
|
|
from midiutil import MIDIFile
|
|
|
|
# Create the MIDIFile Object
|
|
my_midi = MIDIFile(1)
|
|
|
|
# Add track name and tempo
|
|
track = 0
|
|
time = 0
|
|
my_midi.addTrackName(track, time, "Sample Track")
|
|
my_midi.addTempo(track, time, 120)
|
|
|
|
# Add a single note
|
|
channel = 0 # MIDI channel 1
|
|
pitch = 60 # MIDI note number (60 = middle C / C4)
|
|
duration = 1 # Duration in beats (1 = quarter note)
|
|
volume = 100 # MIDI velocity 0-127
|
|
|
|
my_midi.addNote(track, channel, pitch, time, duration, volume)
|
|
|
|
# Write to disk
|
|
with open("single-note.mid", 'wb') as binfile:
|
|
my_midi.writeFile(binfile)
|
|
|
|
print("Written: single-note.mid")
|
|
print(f" Note: C4(60) on channel {channel}, {duration} beat(s) at 120 BPM")
|