Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions examples/test1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from midiutil import MIDIFile

# Create a MIDI file with one track
midi = MIDIFile(1)

# Track, Time, Duration, and Tempo settings
track = 0
time = 0
duration = 1
tempo_intro = 80
Comment on lines +5 to +10

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello

tempo_dev = 120
tempo_concl = 70

midi.addTempo(track, time, tempo_intro)

# Add notes for each section (simplified example)
# Introduction (C Major)
midi.addNote(track, 0, 60, time, duration, 64) # C4
midi.addNote(track, 0, 64, time + 1, duration, 64) # E4
midi.addNote(track, 0, 67, time + 2, duration, 64) # G4

# Change tempo for development
time += 4
midi.addTempo(track, time, tempo_dev)
midi.addNote(track, 0, 67, time, duration, 64) # G4
midi.addNote(track, 0, 71, time + 0.5, duration, 64) # B4
midi.addNote(track, 0, 74, time + 1, duration, 64) # D5

# Change tempo for conclusion
time += 4
midi.addTempo(track, time, tempo_concl)
midi.addNote(track, 0, 60, time, duration, 64) # C4
midi.addNote(track, 0, 64, time + 1, duration, 64) # E4
midi.addNote(track, 0, 67, time + 2, duration, 64) # G4

# Save the MIDI file
with open("beginner_symphony.mid", "wb") as output_file:
midi.writeFile(output_file)