-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice2.py
More file actions
58 lines (48 loc) · 1.49 KB
/
practice2.py
File metadata and controls
58 lines (48 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
##--------------------------------------------------------------------------
##
## Simple Canon Variation Style
##
##--------------------------------------------------------------------------
from music21 import stream, note, chord, meter, key, tempo
# Create a score
score = stream.Score()
# Set time signature, key, and tempo
part = stream.Part()
part.append(tempo.MetronomeMark(number=90))
part.append(key.Key('D'))
part.append(meter.TimeSignature('4/4'))
# Canon-like bass line (typical to Pachelbel)
bass_line = ['D2', 'A2', 'B2', 'F#2', 'G2', 'D2', 'G2', 'A2']
# Add bass notes as whole notes
for pitch in bass_line:
n = note.Note(pitch)
n.duration.quarterLength = 4
part.append(n)
# Add right-hand broken chords (a very simplified version)
right_hand = stream.Part()
right_hand.id = 'Piano_RH'
right_hand.append(tempo.MetronomeMark(number=90))
right_hand.append(key.Key('D'))
right_hand.append(meter.TimeSignature('4/4'))
chord_progression = [
['D4', 'F#4', 'A4'],
['A3', 'C#4', 'E4'],
['B3', 'D4', 'G4'],
['F#3', 'A3', 'D4'],
['G3', 'B3', 'D4'],
['D3', 'F#3', 'A3'],
['G3', 'B3', 'D4'],
['A3', 'C#4', 'E4']
]
for c in chord_progression:
arpeggio = stream.Voice()
for pitch in c:
n = note.Note(pitch)
n.duration.quarterLength = 1
arpeggio.append(n)
right_hand.append(arpeggio)
# Combine both parts into a score
score.insert(0, part)
score.insert(0, right_hand)
# Show the score (requires MuseScore or musicXML viewer)
score.show()