-
Notifications
You must be signed in to change notification settings - Fork 0
/
violin.py
307 lines (250 loc) · 9.37 KB
/
violin.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#
# abbreviations
#
# rhythm 1bar2dup3cet4mow
# strings 1234
# shape NPGWCADK None, Porcupine, Gun, Westside, Chicken, Alien, Dog, ducK
# frets 0..24
# fingers 01234
# bowing 0-8
# attack DGS Detache, leGato, Staccato
# dynamics V eVen
#
import math, re
from workout import *
FAST_TEMPO = 120
SHAPES = "PGWCADK"
# divide a score into phrases
def piece(num, title, mp3, tempo, phrases, index="-", rhythm="1234", strings="2", bowing="35",
shapes="W", bases="2", fingers="0", attack="D", dynamics="M"):
# normalise tab lines
index = normalise_tab(index)
rhythm = normalise_tab(rhythm)
strings = normalise_tab(strings)
bowing = normalise_tab(bowing)
shapes = normalise_tab(shapes)
bases = normalise_tab(bases)
fingers = normalise_tab(fingers)
attack = normalise_tab(attack)
dynamics = normalise_tab(dynamics)
# expand abbreviated parameters
def repeat_to_fit(string, length): return (string * math.ceil(length / len(string)))[0:length]
n = len(index)
if n > 1:
if len(strings) < n: strings = repeat_to_fit(strings, n)
if len(bowing) < n + 1 : bowing = repeat_to_fit(bowing, n + 1)
if len(shapes) < n : shapes = repeat_to_fit(shapes, n)
if len(bases) < n : bases = repeat_to_fit(bases, n)
if len(fingers) < n: fingers = repeat_to_fit(fingers, n)
if len(attack) < n: attack = repeat_to_fit(attack, n)
if len(dynamics) < n: dynamics = repeat_to_fit(dynamics, n)
rhythm += "1"
# process phrases in reverse order
lyrics = []
right = len(index)
for i, tupl in reversed(list(enumerate(phrases))):
# split the lyrics, adding the first note of the next phrase if they are sequential
phrase_lyrics = re.split("[- ]", tupl[0])
left = right - len(phrase_lyrics)
lyrics = phrase_lyrics + lyrics
if len(tupl) < 3 and i != len(phrases) - 1:
phrase_lyrics.append(re.split("[- ]", phrases[i + 1][0])[0])
right += 1
# calculate ommitted mp3 splits
if len(tupl) == 3:
start = tupl[1]
stop = tupl[2]
elif len(tupl) == 2:
start = tupl[1]
stop = phrases[i + 1][1]
else:
start = 0
stop = 0
phrase(title, tempo, mp3, start, stop, phrase_lyrics,
index[left:right], rhythm[left:right + 1], strings[left:right],
shapes[left:right], bases[left:right], fingers[left:right], bowing[left:right + 1],
attack[left:right], dynamics[left:right])
right -= len(phrase_lyrics)
# piece bracket
make_bracket(title, tempo, {}, 1)
make_metronome(1)
make_metronome(tempo)
make_whole(mp3)
def phrase(title, tempo, mp3, start, stop, lyrics,
index, rhythm, strings="", shapes="", bases="", fingers="", bowing="", attack="", dynamics=""):
params = locals()
del params["mp3"]
del params["start"]
del params["stop"]
# process words in reverse order
for i in reversed(range(len(index))):
if i > 0:
h = i - 1
j = i + 1
word(title, tempo, lyrics[h:j], rhythm[h:j+1], strings[h:j], shapes[h:j], bases[h:j],
fingers[h:j], bowing[h:j+1], attack[h:j], dynamics[h:j])
# phrase drills
if re.search("[1-4]", fingers):
open_strings(tempo, lyrics, index, rhythm, strings, bowing, attack, dynamics)
make_bracket(title, tempo, params, 5)
make_chunk(mp3, start, stop, 1, "B")
make_chunk(mp3, start, stop, 0.5, "C")
def word(title, tempo, lyrics, rhythm, strings, shapes, bases, fingers, bowing, attack, dynamics):
# process notes in reverse order
note(title, tempo, lyrics[1], rhythm[1:3], strings[1], shapes[1], bases[1], fingers[1],
bowing[1:3], attack[1], dynamics[1])
note(title, tempo, lyrics[0], rhythm[0:2], strings[0], shapes[0], bases[0], fingers[0],
bowing[0:2], attack[0], dynamics[0])
# word drills
if strings[0] == strings[1]:
bow_changes(tempo, lyrics, rhythm, strings[0], bowing, attack, dynamics)
else:
string_crossings(tempo, lyrics, rhythm, strings, bowing, attack, dynamics)
if shapes[0] != shapes[1]:
jankin_switches(shapes[0], shapes[1])
if strings[0] != strings[1]:
hand_jumps_rapid(tempo, strings[0:2], shapes[0:2], bases[0:2])
make_bracket(title, tempo, locals(), 5)
def note(title, tempo, lyrics, rhythm, string, shape, base, finger, bowing, attack, dynamic):
if attack != ".":
bow_attack(tempo, lyrics, rhythm, string, bowing, attack, dynamic)
hand_placement(string, shape, base)
pitch_hitting(string, fret(shape, base, finger), finger)
make_drill(locals(), 5)
##################
## BEGIN DRILLS ##
##################
def open_strings(tempo, lyrics, index, rhythm, strings, bowing, attack, dynamics):
for i in range(len(index)):
if i > 0:
h = i - 1
j = i + 1
if strings[i] == strings[h]:
bow_changes(tempo, lyrics[h:j], rhythm[h:j+1], strings[h], bowing[h:j+1], attack[h:j], dynamics[h:j])
else:
string_crossings(tempo, lyrics[h:j], rhythm[h:j+1], strings[h:j], bowing[h:j+1], attack[h:j], dynamics[h:j])
rhythm_clapping(tempo, lyrics, rhythm)
make_drill(locals(), 5)
def rhythm_clapping(tempo, lyrics, rhythm):
make_drill(locals(), 5)
def string_crossings(tempo, lyrics, rhythm, strings, bowing, attack, dynamics):
make_drill(locals(), 5)
def string_switching(tempo, frm, to, bowpos):
if frm > to: frm, to = to, frm
bow_hold()
make_drill(locals(), 15)
def bow_changes(tempo, lyrics, rhythm, string, bowing, attack, dynamic):
if attack[0] != "." and attack[1] != ".":
bow_attack(tempo, lyrics[0], rhythm[0:2], string, bowing[0:2], attack[0], dynamic[0]),
bow_attack(tempo, lyrics[1], rhythm[1:3], string, bowing[1:3], attack[1], dynamic[1]),
rhythm_clapping(tempo, lyrics, rhythm)
make_drill(locals(), 5)
def pitch_hitting(string, fret, finger):
if int(fret) != 0 and int(finger) != 0:
finger_hammers(string, fret, finger)
if make_drill(locals(), 5):
make_drone(note_at(string, fret))
def finger_hammers(string, fret, finger):
air_hammers(finger)
make_drill(locals(), 15)
def air_hammers(finger):
make_drill( locals(), 30)
def bow_attack(tempo, lyrics, rhythm, string, bowing, attack, dynamic):
if attack != ".":
string_yanking(tempo, string, bowing[0], "D" if bowing[0] < bowing[1] else "U")
rhythm_clapping(tempo, lyrics, rhythm)
make_drill(locals(), 5)
def string_yanking(tempo, string, bowpos, direction):
bow_benders(string, bowpos)
make_drill(locals(), 15)
def bow_benders(string, bowpos):
bow_placement(string, bowpos)
make_drill(locals(), 10)
def bow_placement(string, bowpos):
violin_hold()
bow_hold()
make_drill(locals(), 5)
def violin_hold():
stretches()
no_hands_swivels()
def stretches():
make_drill(locals(), 1)
def no_hands_swivels():
make_drill(locals(), 10)
def bow_hold():
jellyfish()
vertical_bow_raises()
horizontal_bow_raises()
itsy_bitsy_spider()
bow_hand_resets()
def bow_hand_resets():
make_drill(locals(), 5)
def itsy_bitsy_spider():
make_drill(locals(), 5)
def horizontal_bow_raises():
make_drill(locals(), 10)
def vertical_bow_raises():
make_drill(locals(), 10)
def jellyfish():
make_drill(locals(), 5)
def hand_jumps_rapid(tempo, strings, shapes, bases):
if shapes[0] != "N" and shapes[1] != "N":
hand_jumps_exact(strings, shapes, bases)
make_drill(locals(), 5)
def hand_jumps_exact(strings, shapes, bases):
if shapes[0] != "N" and shapes[1] != "N":
hand_jumps_silent(strings, shapes, bases)
make_drill(locals(), 5)
def hand_jumps_silent(strings, shapes, bases):
if shapes[0] != "N" and shapes[1] != "N":
finger_wriggles_curved(shapes[0], shapes[1])
jankin_switches(shapes[0], shapes[1])
hand_placement(strings[1], shapes[1], bases[1])
hand_placement(strings[0], shapes[0], bases[0])
make_drill(locals(), 15)
def hand_placement(string, shape, base):
if shape in SHAPES:
jankin(shape)
pitch_hitting(string, base, 1)
if make_drill(locals(), 60):
make_drone(note_at(string, base))
def jankin(shape):
if shape in SHAPES:
finger_stretches()
make_drill(locals(), 15)
def finger_stretches():
make_drill(locals())
def jankin_switches(from_shape, to_shape):
if to_shape > from_shape: from_shape, to_shape = to_shape, from_shape
if from_shape != "N" and to_shape != "N" and from_shape != to_shape:
jankin(from_shape)
jankin(to_shape)
make_drill(locals(), 15)
def finger_wriggles_curved(from_shape, to_shape):
if to_shape > from_shape: from_shape, to_shape = to_shape, from_shape
if from_shape != "N" and to_shape != "N" and from_shape != to_shape:
finger_wriggles_straight(from_shape, to_shape)
make_drill(locals(), 30)
def finger_wriggles_straight(from_shape, to_shape):
if to_shape > from_shape: from_shape, to_shape = to_shape, from_shape
if from_shape != "N" and to_shape != "N" and from_shape != to_shape:
make_drill(locals(), 30)
def pinky_reaches():
elbow_raises()
make_drill(locals(), 30)
def elbow_raises():
make_drill(locals(), 30)
def son_file():
make_metronome(60)
make_drill(locals(), 4)
def fret(shape, base, finger):
if shape == "P": frets = [0, 2, 4, 6]
elif shape == "G": frets = [0, 1, 3, 5]
elif shape == "W": frets = [0, 2, 3, 5]
elif shape == "C": frets = [0, 2, 4, 5]
elif shape == "A": frets = [0, 1, 3, 4]
elif shape == "D": frets = [0, 1, 2, 4]
elif shape == "K": frets = [0, 2, 3, 4]
return frets[int(finger) - 1] + int(base)
def note_at(string, fret):
return decimal_to_note(note_to_decimal("5Y") - (int(string) * 7) + int(fret))