|
| 1 | +using MusicXML |
| 2 | + |
| 3 | +## Part List |
| 4 | +### Piano |
| 5 | +midiinstrument_piano = MidiInstrument(channel= 1, program =1, volume = 100, pan =0, id = "P1-I1") |
| 6 | +scorepart_piano = ScorePart(name = "Piano", midiinstrument = midiinstrument_piano, id = "P1") |
| 7 | + |
| 8 | +### Acoustic Guitar |
| 9 | +midiinstrument_guitar = MidiInstrument(channel= 1, program =26, volume = 100, pan =0, id = "P2-I1") |
| 10 | +scorepart_guitar = ScorePart(name = "Acoustic Guitar", midiinstrument = midiinstrument_guitar, id = "P2") |
| 11 | + |
| 12 | +### |
| 13 | +partlist = PartList(scoreparts = [scorepart_piano, scorepart_guitar]) |
| 14 | + |
| 15 | +## Part |
| 16 | +### Piano |
| 17 | + |
| 18 | +attributes1_piano = Attributes( |
| 19 | + time = Time(beats = 4, beattype = 4), # 4/4 |
| 20 | + divisions = 4, # we want to use 16th notes at minimum |
| 21 | + clef = [Clef(number = 1, sign = "G", line = 2), Clef(number = 2, sign = "F", line = 4)], # Piano clefs |
| 22 | + staves = 2, # Piano staves |
| 23 | + key = Key(fifths = 0, mode = "major"), # no accidentals, major key |
| 24 | +) |
| 25 | + |
| 26 | +measure1_notes_piano = [ |
| 27 | +NoteX(pitch = Pitch(step = "C", alter = 0, octave = 4), duration = 4), |
| 28 | +NoteX(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 4), |
| 29 | +NoteX(pitch = Pitch(step = "E", alter = 0, octave = 4), duration = 4), |
| 30 | +NoteX(pitch = Pitch(step = "F", alter = +1, octave = 4), duration = 4), |
| 31 | +] |
| 32 | + |
| 33 | +measure2_notes_piano = [ |
| 34 | +NoteX(pitch = Pitch(step = "G", alter = 0, octave = 5), duration = 1), |
| 35 | +NoteX(pitch = Pitch(step = "G", alter = +1, octave = 5), duration = 1), |
| 36 | +NoteX(pitch = Pitch(step = "B", alter = 0, octave = 5), duration = 1), |
| 37 | +NoteX(pitch = Pitch(step = "A", alter = +1, octave = 5), duration = 1), |
| 38 | +NoteX(rest = Rest(), duration = 4), # Rest |
| 39 | +NoteX(pitch = Pitch(step = "A", alter = 0, octave = 5), duration = 4), |
| 40 | +NoteX(pitch = Pitch(step = "B", alter = 0, octave = 5), duration = 4), |
| 41 | +] |
| 42 | + |
| 43 | +measures_piano = [ |
| 44 | +Measure(attributes = attributes1_piano, notes = measure1_notes_piano) # measure 1 has attributes |
| 45 | +Measure(notes = measure2_notes_piano) |
| 46 | +] |
| 47 | + |
| 48 | + |
| 49 | +part_piano = Part(measures = measures_piano, id = "P1") |
| 50 | + |
| 51 | + |
| 52 | +### Guitar |
| 53 | + |
| 54 | +attributes1_guitar = Attributes( |
| 55 | + time = Time(beats = 4, beattype = 4), # 4/4 |
| 56 | + divisions = 4, # we want to use 16th notes at minimum |
| 57 | + clef = [Clef(number = 1, sign = "G", line = 2), Clef(number = 2, sign = "TAB", line = 6)], # Guitar Clefs |
| 58 | + staves = 2, # Guitar staves |
| 59 | + key = Key(fifths = 0, mode = "major"), # no accidentals, major key |
| 60 | +) |
| 61 | + |
| 62 | +measure1_notes_guitar = [ |
| 63 | +# G Major chord for a bar |
| 64 | +NoteX(pitch = Pitch(step = "G", alter = 0, octave = 2), duration = 16, chord = Chord()), |
| 65 | +NoteX(pitch = Pitch(step = "B", alter = 0, octave = 2), duration = 16, chord = Chord()), |
| 66 | +NoteX(pitch = Pitch(step = "D", alter = 0, octave = 3), duration = 16, chord = Chord()), |
| 67 | +NoteX(pitch = Pitch(step = "G", alter = 0, octave = 3), duration = 16, chord = Chord()), |
| 68 | +NoteX(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 16, chord = Chord()), |
| 69 | +NoteX(pitch = Pitch(step = "G", alter = 0, octave = 4), duration = 16, chord = Chord()), |
| 70 | +] |
| 71 | + |
| 72 | +measure2_notes_guitar = [ |
| 73 | +# G Major chord for half a bar |
| 74 | +NoteX(pitch = Pitch(step = "G", alter = 0, octave = 2), duration = 8, chord = Chord()), |
| 75 | +NoteX(pitch = Pitch(step = "B", alter = 0, octave = 2), duration = 8, chord = Chord()), |
| 76 | +NoteX(pitch = Pitch(step = "D", alter = 0, octave = 3), duration = 8, chord = Chord()), |
| 77 | +NoteX(pitch = Pitch(step = "G", alter = 0, octave = 3), duration = 8, chord = Chord()), |
| 78 | +NoteX(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 8, chord = Chord()), |
| 79 | +NoteX(pitch = Pitch(step = "G", alter = 0, octave = 4), duration = 8, chord = Chord()), |
| 80 | + |
| 81 | +# G Major chord for half a bar |
| 82 | +NoteX(pitch = Pitch(step = "G", alter = 0, octave = 2), duration = 8, chord = Chord()), |
| 83 | +NoteX(pitch = Pitch(step = "B", alter = 0, octave = 2), duration = 8, chord = Chord()), |
| 84 | +NoteX(pitch = Pitch(step = "D", alter = 0, octave = 3), duration = 8, chord = Chord()), |
| 85 | +NoteX(pitch = Pitch(step = "G", alter = 0, octave = 3), duration = 8, chord = Chord()), |
| 86 | +NoteX(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 8, chord = Chord()), |
| 87 | +NoteX(pitch = Pitch(step = "G", alter = 0, octave = 4), duration = 8, chord = Chord()), |
| 88 | +] |
| 89 | + |
| 90 | +measures_guitar = [ |
| 91 | +Measure(attributes = attributes1_guitar, notes = measure1_notes_guitar) # measure 1 has attributes |
| 92 | +Measure(notes = measure2_notes_guitar) |
| 93 | +] |
| 94 | + |
| 95 | + |
| 96 | +part_guitar = Part(measures = measures_guitar, id = "P2") |
| 97 | + |
| 98 | +## |
| 99 | +score = ScorePartwise( |
| 100 | +partlist = partlist, |
| 101 | +parts = [part_piano, part_guitar], |
| 102 | +) |
| 103 | + |
| 104 | + |
| 105 | +writemusicxml("myscore.musicxml", score) |
0 commit comments