Untitled
unknown
plain_text
18 days ago
2.7 kB
1
Indexable
Never
from music21 import stream, instrument, note, chord, meter, tempo # Create a stream to hold the score score = stream.Score() # Add instruments to the parts alto_sax_part = stream.Part() alto_sax_part.insert(0, instrument.AltoSaxophone()) alto_sax_part.insert(0, meter.TimeSignature('4/4')) tenor_sax_part = stream.Part() tenor_sax_part.insert(0, instrument.TenorSaxophone()) tenor_sax_part.insert(0, meter.TimeSignature('4/4')) violin_part = stream.Part() violin_part.insert(0, instrument.Violin()) violin_part.insert(0, meter.TimeSignature('4/4')) viola_part = stream.Part() viola_part.insert(0, instrument.Viola()) viola_part.insert(0, meter.TimeSignature('4/4')) trombone_part = stream.Part() trombone_part.insert(0, instrument.Trombone()) trombone_part.insert(0, meter.TimeSignature('4/4')) horn_part = stream.Part() horn_part.insert(0, instrument.FrenchHorn()) horn_part.insert(0, meter.TimeSignature('4/4')) piano_part = stream.Part() piano_part.insert(0, instrument.Piano()) piano_part.insert(0, meter.TimeSignature('4/4')) percussion_part = stream.Part() percussion_part.insert(0, instrument.Percussion()) percussion_part.insert(0, meter.TimeSignature('4/4')) # Add a tempo mark score.insert(0, tempo.MetronomeMark(number=80)) # Write a short phrase for each instrument (8 measures of simple melodic content) melody = [note.G4, note.A4, note.B4, note.C5, note.D5, note.E5, note.F5, note.G5] # Add notes to alto sax alto_sax_part.append([note.Note(p, quarterLength=1) for p in melody]) # Add notes to tenor sax tenor_sax_part.append([note.Note(p.transpose(-12), quarterLength=1) for p in melody]) # Add notes to violin violin_part.append([note.Note(p, quarterLength=1) for p in melody]) # Add notes to viola (lower octave) viola_part.append([note.Note(p.transpose(-12), quarterLength=1) for p in melody]) # Add notes to trombone trombone_part.append([note.Note(p.transpose(-19), quarterLength=1) for p in melody]) # Add notes to French horn horn_part.append([note.Note(p.transpose(-7), quarterLength=1) for p in melody]) # Add some simple chords for piano piano_chords = [chord.Chord([n, n+4, n+7], quarterLength=1) for n in [60, 62, 64, 65, 67, 69, 71, 72]] piano_part.append(piano_chords) # Add percussion (snare drum) percussion_part.append([note.Rest(quarterLength=2), note.Note('C4', quarterLength=1), note.Rest(quarterLength=1)] * 4) # Add all parts to the score score.append([alto_sax_part, tenor_sax_part, violin_part, viola_part, trombone_part, horn_part, piano_part, percussion_part]) # Show the score as a musicXML file (which can be opened in Finale, Sibelius, Musescore, etc.) score.show('musicxml')
Leave a Comment