-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimers.py
127 lines (118 loc) · 7.01 KB
/
primers.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
'''
primers.py
Sara Adkins 2022
'''
HEADER1 = ['artist:unknown_artist', 'downtune:0']
HEADER2 = ['start', 'new_measure', 'measure:repeat_open']
DISTORTED = "distorted0"
BASS = "bass"
DRUMS = "drums"
def build_pitched_note(instrument, string, fret):
return "{}:note:s{}:f{}".format(instrument, string, fret)
def build_percussion_note(instrument, midi_num):
return "{}:note:{}".format(instrument, midi_num)
# create primer tokens based on yaml configurations
def build_primer(bpm, key=None, duration=0):
primer = []
for val in HEADER1:
primer.append(val)
primer.append("tempo:{}".format(bpm))
for val in HEADER2:
primer.append(val)
if key == 't':
text_file = open("primer_blank.txt", "r")
lines = text_file.read().split('\n')
for line in lines:
primer.append(line)
primer.append("new_measure")
elif key == 'blank':
pass
elif not key == None:
if key == 'e':
primer.append(build_pitched_note(DISTORTED, 6, 0))
primer.append(build_pitched_note(BASS, 5, 0))
elif key == 'a':
primer.append(build_pitched_note(DISTORTED, 5, 0))
primer.append(build_pitched_note(BASS, 4, 0))
elif key == 'd':
primer.append(build_pitched_note(DISTORTED, 4, 0))
primer.append(build_pitched_note(BASS, 3, 0))
elif key == 'em': #one bar of Em eigth notes
primer.append(build_pitched_note(DISTORTED, 6, 0)) #E
primer.append(build_pitched_note(DISTORTED, 5, 2)) #B
primer.append(build_pitched_note(DISTORTED, 4, 2)) #E
primer.append(build_pitched_note(BASS, 5, 0)) #E
primer.append("wait:{}".format(480))
primer.append(build_pitched_note(DISTORTED, 6, 0)) #E
primer.append(build_pitched_note(DISTORTED, 5, 2)) #B
primer.append(build_pitched_note(DISTORTED, 4, 2)) #E
primer.append(build_pitched_note(BASS, 5, 0)) #E
primer.append("wait:{}".format(480))
primer.append(build_pitched_note(DISTORTED, 6, 0)) #E
primer.append(build_pitched_note(DISTORTED, 5, 2)) #B
primer.append(build_pitched_note(DISTORTED, 4, 2)) #E
primer.append(build_pitched_note(BASS, 5, 0)) #E
primer.append("wait:{}".format(480))
primer.append(build_pitched_note(DISTORTED, 6, 0)) #E
primer.append(build_pitched_note(DISTORTED, 5, 2)) #B
primer.append(build_pitched_note(DISTORTED, 4, 2)) #E
primer.append(build_pitched_note(BASS, 5, 0)) #E
primer.append("wait:{}".format(480))
primer.append(build_pitched_note(DISTORTED, 6, 0)) #E
primer.append(build_pitched_note(DISTORTED, 5, 2)) #B
primer.append(build_pitched_note(DISTORTED, 4, 2)) #E
primer.append(build_pitched_note(BASS, 5, 0)) #E
primer.append("wait:{}".format(480))
primer.append(build_pitched_note(DISTORTED, 6, 0)) #E
primer.append(build_pitched_note(DISTORTED, 5, 2)) #B
primer.append(build_pitched_note(DISTORTED, 4, 2)) #E
primer.append(build_pitched_note(BASS, 5, 0)) #E
primer.append("wait:{}".format(480))
primer.append(build_pitched_note(DISTORTED, 6, 0)) #E
primer.append(build_pitched_note(DISTORTED, 5, 2)) #B
primer.append(build_pitched_note(DISTORTED, 4, 2)) #E
primer.append(build_pitched_note(BASS, 5, 0)) #E
primer.append("wait:{}".format(480))
primer.append(build_pitched_note(DISTORTED, 6, 0)) #E
primer.append(build_pitched_note(DISTORTED, 5, 2)) #B
primer.append(build_pitched_note(DISTORTED, 4, 2)) #E
primer.append(build_pitched_note(BASS, 5, 0)) #E
primer.append("wait:{}".format(480))
primer.append("new_measure")
primer.append(build_pitched_note(DISTORTED, 6, 0))
primer.append(build_pitched_note(BASS, 5, 0))
elif key == 'cg': #whole note C chord G chord x 2
primer.append(build_pitched_note(DISTORTED, 5, 3)) #C
primer.append(build_pitched_note(DISTORTED, 4, 2)) #E
primer.append(build_pitched_note(DISTORTED, 3, 0)) #G
primer.append(build_pitched_note(BASS, 4, 3)) #C
primer.append("wait:{}".format(960 * 4))
primer.append("new_measure")
primer.append(build_pitched_note(DISTORTED, 6, 3)) #G
primer.append(build_pitched_note(DISTORTED, 5, 2)) #B
primer.append(build_pitched_note(DISTORTED, 4, 0)) #D
primer.append(build_pitched_note(BASS, 5, 3)) #G
primer.append("wait:{}".format(960 * 4))
primer.append("new_measure")
primer.append(build_pitched_note(DISTORTED, 5, 3)) #C
primer.append(build_pitched_note(DISTORTED, 4, 2)) #E
primer.append(build_pitched_note(DISTORTED, 3, 0)) #G
primer.append(build_pitched_note(BASS, 4, 3)) #C
primer.append("wait:{}".format(960 * 4))
primer.append("new_measure")
primer.append(build_pitched_note(DISTORTED, 6, 3)) #G
primer.append(build_pitched_note(DISTORTED, 5, 2)) #B
primer.append(build_pitched_note(DISTORTED, 4, 0)) #D
primer.append(build_pitched_note(BASS, 5, 3)) #G
primer.append("wait:{}".format(960 * 4))
primer.append("new_measure")
primer.append(build_pitched_note(DISTORTED, 5, 3))
primer.append(build_pitched_note(BASS, 4, 3))
else:
print("Unrecognized key {}, defaulting to e".format(key))
primer.append(build_pitched_note(DISTORTED, 6, 0))
primer.append(build_pitched_note(BASS, 5, 0))
primer.append(build_percussion_note(DRUMS, 42))
primer.append(build_percussion_note(DRUMS, 36))
primer.append("wait:{}".format(duration))
return primer