from midiutil import MIDIFile
- Buat file MIDI sederhana
track = 0 channel = 0 time = 0 tempo = 100 volume = 100
- Not angka ke nada MIDI
note_map = {
'1': 60, # C4 '2': 62, # D4 '3': 64, # E4 '4': 65, # F4 '5': 67, # G4 '6': 69, # A4 '7': 71, # B4 '^1': 72, # C5 '^2': 74, # D5
}
- Melodi chorus (versi sederhana)
chorus_melody = [
('1', 1), ('1', 1), ('2', 1), ('3', 1), ('5', 2), ('1', 1), ('1', 1), ('2', 1), ('3', 1), ('5', 2), ('5', 1), ('6', 1), ('^1', 1), ('^1', 1), ('^2', 2), ('^2', 1), ('^1', 1), ('6', 1), ('5', 1), ('5', 2), ('5', 1), ('6', 1), ('^1', 1), ('^1', 1), ('^2', 2), ('^2', 1), ('^1', 1), ('6', 1), ('5', 1), ('5', 2)
]
- Buat file MIDI
midi = MIDIFile(1) midi.addTempo(track, time, tempo)
current_time = time for note, duration in chorus_melody:
if note in note_map: pitch = note_map[note] midi.addNote(track, channel, pitch, current_time, duration, volume) current_time += duration
- Simpan file
with open("Tanah_Air_Merdeka.mid", "wb") as output_file:
midi.writeFile(output_file)
print("File MIDI berhasil dibuat: Tanah_Air_Merdeka.mid")
Talk pages are where people discuss how to make content on Wikipedia the best that it can be. You can use this page to start a discussion with others about how to improve the "File:MIDI sample.mid" page.