Untitled

 avatar
unknown
plain_text
a month ago
2.0 kB
1
Indexable
from music21 import stream, note, meter, chord, tempo, metadata

# Create a score and add metadata
score = stream.Score()
score.metadata = metadata.Metadata(title="Faith's Journey", composer="User & Assistant")

# Define tempo and time signature
part = stream.Part()
part.append(tempo.MetronomeMark(number=80))  # Slow tempo
part.append(meter.TimeSignature('4/4'))

# Define the melody notes and lyrics
melody_notes = [
    # Bar 1-2
    (["C4", "E4", "G4", "A4"], "In the stillness of the night,"),
    (["G4", "F4", "E4", "D4"], None),
    # Bar 3-4
    (["D4", "E4", "F4", "G4"], "A spark of hope begins to rise."),
    (["E4", "D4", "C4", "C4"], None),
    # Bar 5-6
    (["G4", "A4", "C5", "D5"], "Guided by the voice within,"),
    (["C5", "B4", "A4", "G4"], None),
    # Bar 7-8
    (["F4", "G4", "A4", "G4"], "I’ll find my way through every tide."),
    (["E4", "D4", "C4", "D4"], None),
    # Bar 9-10
    (["E4", "G4", "F4", "E4"], "Faith is stronger than my fear,"),
    (["D4", "C4", "C4", "G4"], None),
    # Bar 11-12
    (["A4", "G4", "F4", "E4"], "And love will carry me from here."),
    (["C4", "D4", "C4", "G4"], None),
    # Bar 13-14
    (["F4", "G4", "A4", "F4"], "Through the storm and endless night,"),
    (["E4", "D4", "C4", "D4"], None),
    # Bar 15-16
    (["E4", "G4", "F4", "E4"], "I’ll rise with strength, I’ll win the fight."),
    (["C4", "D4", "C4", "C4"], None),
]

# Add melody notes and lyrics to the part
for bar_notes, lyric in melody_notes:
    bar = stream.Measure()
    for pitch in bar_notes:
        n = note.Note(pitch, quarterLength=1)
        if lyric:
            n.lyric = lyric
            lyric = None  # Add the lyric only to the first note of the bar
        bar.append(n)
    part.append(bar)

# Add the part to the score
score.append(part)

# Save as MusicXML
file_path = "/mnt/data/Faiths_Journey_Sheet_Music.xml"
score.write("musicxml", file_path)
file_path
Leave a Comment