Created
March 1, 2025 23:09
-
-
Save buzzdeee/e1ba36eaaf99de9cde73b475d7970e9c to your computer and use it in GitHub Desktop.
Mittelalterliche Musik
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from midiutil import MIDIFile | |
# Erstelle ein neues MIDI-Objekt mit einer Spur | |
mid = MIDIFile(3) # Drei Spuren: Laute, Flöte, Trommel | |
# Spur 0: Laute (Melodie) | |
mid.addTrackName(0, 0, "Laute") | |
mid.addTempo(0, 0, 120) | |
mid.addProgramChange(0, 0, 0, 24) # 24 = Akustische Gitarre (Laute) | |
# Spur 1: Flöte (zweite Melodie) | |
mid.addTrackName(1, 0, "Flöte") | |
mid.addTempo(1, 0, 120) | |
mid.addProgramChange(1, 1, 0, 73) # 73 = Flöte | |
# Spur 2: Trommel (Percussion) | |
mid.addTrackName(2, 0, "Trommel") | |
mid.addTempo(2, 0, 120) | |
mid.addProgramChange(2, 2, 0, 117) # 117 = Percussion (Woodblock als einfache Trommel) | |
# Melodie für Laute (Tonhöhe, Startzeit, Dauer) | |
melody = [ | |
(60, 0, 0.5), (62, 0.5, 0.5), (64, 1, 0.5), (65, 1.5, 0.5), (67, 2, 1), | |
(65, 3, 0.5), (64, 3.5, 0.5), (62, 4, 0.5), (60, 4.5, 1), | |
(62, 6, 0.5), (64, 6.5, 0.5), (65, 7, 0.5), (67, 7.5, 0.5), (69, 8, 1), | |
(67, 9, 0.5), (65, 9.5, 0.5), (64, 10, 0.5), (62, 10.5, 1) | |
] * 4 # Wiederholt für ca. 1 Minute | |
# Zweite Melodie für Flöte | |
flute_melody = [(note+12, start+0.5, duration) for note, start, duration in melody] # Eine Oktave höher und versetzt | |
# Rhythmus für Trommel | |
percussion = [(36, i, 1) for i in range(0, 48, 2)] # Tiefe Trommel auf jeder zweiten Zählzeit | |
# Noten hinzufügen | |
for note, start, duration in melody: | |
mid.addNote(0, 0, note, start, duration, 100) | |
for note, start, duration in flute_melody: | |
mid.addNote(1, 1, note, start, duration, 80) | |
for note, start, duration in percussion: | |
mid.addNote(2, 2, note, start, duration, 90) | |
# Speichere die MIDI-Datei | |
with open("mittelalter_melodie.mid", "wb") as midi_file: | |
mid.writeFile(midi_file) | |
print("MIDI-Datei 'mittelalter_melodie.mid' wurde erfolgreich erstellt!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment