-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviolin.py
294 lines (239 loc) · 8.82 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
#
# abbreviations
#
# rhythm 1bar2dup3cet4mow
# strings 1234
# shape NPGWCADKH None, Porcupine, Gun, Westside, Chicken, Alien, Dog, ducK, Huddle
# fingers 01234
# bowing 0-8
# attack DGS Detache, leGato, Staccato
# dynamics V eVen
#
import math, re
from workout import *
from dataclasses import dataclass
MP3_DIR = os.environ['HOME'] + "/library/workout/violin/04.pieces/"
FAST_TEMPO = 120
SHAPES = "PGWCADKH"
@dataclass
class ViolinNote(Note):
base: int
string: str
shape: str
finger: int
start_bow: str
bow_direction: str
stop_bow: str
def to_string(n):
return f"{n.start_beat}{n.stop_beat} {n.degree} {n.base}{n.string}{n.shape}{n.finger} {n.start_bow}{n.bow_direction}{n.stop_bow}{n.attack}{n.dynamics} {n.label}"
def parse_violin_note(text: str) -> Note:
"""
field order: (start_beat stop_beat) degree (base string shape finger) (start_bow bow_direction stop_bow attack dynamic) label
example: "12 0 02W0 3v5LM twin-"
"""
return ViolinNote(
start_beat = text[0],
stop_beat = text[1],
degree = text[3],
base = text[5],
string = text[6],
shape = text[7],
finger = text[8],
start_bow = text[10],
bow_direction = text[11],
stop_bow = text[12],
attack = text[13],
dynamics = text[14],
label = text[16:])
def parse_violin_notes(text: str) -> list[Note]:
"""
parse a block of notes line by line and return an array of ViolinNotes
"""
return list(map(parse_violin_note, filter(lambda x: len(x) > 0, map(str.strip, text.split("\n")))))
def calculate_note_defaults(note, next):
if note.stop_beat == "=": note.stop_beat = next.start_beat
if note.stop_bow == "=": note.stop_bow = next.start_bow
if next.degree == "=": next.degree = note.degree
if next.attack == "=": next.attack = note.attack
if next.dynamics == "=": next.dynamics = note.dynamics
if next.string == "=": next.string = note.string
if next.start_bow == "=": next.start_bow = note.stop_bow
if next.base == "=": next.base = note.base
if next.shape == "=": next.shape = note.shape
if next.finger == "=": next.finger = note.finger
def process_piece(piece):
make_metronome(1)
# calculate defaults
for section in piece.sections:
for phrase in section.phrases:
for i, note in enumerate(phrase.notes):
if i < len(phrase.notes) - 1: calculate_note_defaults(note, phrase.notes[i + 1])
# process sections
for section in reversed(piece.sections): process_section(piece, section)
def process_section(piece, section):
for phrase in reversed(section.phrases): process_phrase(piece, section, phrase)
make_metronome(piece.tempo)
def process_phrase(piece, section, phrase):
# process notes in reverse order
notes = phrase.notes
make_chunk(MP3_DIR + piece.mp3, phrase.start_secs, phrase.stop_secs)
for i in reversed(range(len(notes))):
make_bracket(piece.tempo, notes[i:])
process_note(piece.tempo, notes[i])
if i < len(notes) - 1: process_transition(piece.tempo, notes[i], notes[i+1])
# phrase drills
tempo = piece.tempo
make_phrase_drill("rhythm_clapping", tempo, notes)
make_phrase_drill("bowing_vis", tempo, notes)
make_phrase_drill("open_strings", tempo, notes)
make_phrase_drill("fingering_vis", tempo, notes)
make_phrase_drill("phrase_vis", tempo, notes)
make_phrase_drill("phrase_clicks", tempo, notes)
def process_transition(tempo, note, next):
rhythm = note.start_beat + note.stop_beat + next.start_beat + next.stop_beat
strings = note.string + next.string
bowing = note.start_bow + note.stop_bow + next.start_bow + next.stop_bow
attack = note.attack + next.attack
dynamics = note.dynamics + next.dynamics
# transition drills
if note.string == next.string:
bow_changes(tempo, rhythm, note.string, bowing, attack, dynamics)
else:
string_crossings(tempo, rhythm, strings, bowing, attack, dynamics)
if note.shape != next.shape:
jankin_switches(note.shape, next.shape)
if note.string != next.string:
hand_jumps_rapid(tempo, strings, note.shape + next.shape, note.base + next.base)
def process_note(tempo, note):
if note.label != "." and note.label != "," and note.attack != ".":
bow_attack(tempo, note.start_beat + note.stop_beat, note.string, note.start_bow + note.stop_bow, note.attack, note.dynamics)
hand_placement(note.string, note.shape, note.base)
pitch_hitting(note.string, fret(note.shape, note.base, note.finger), note.finger)
############
## DRILLS ##
############
def string_crossings(tempo, rhythm, strings, bowing, attack, dynamics):
string_switching(tempo, strings[0], strings[1], bowing[1])
beat_clapping(tempo, rhythm)
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 beat_clapping(tempo, rhythm):
make_drill(locals(), 5)
def bow_changes(tempo, rhythm, string, bowing, attack, dynamics):
if attack[0] != "." and attack[1] != ".":
beat_clapping(tempo, 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, rhythm, string, bowing, attack, dynamics):
if attack != ".":
string_yanking(tempo, string, bowing[0], "D" if bowing[1] > bowing[0] else "U")
beat_clapping(tempo, 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 == "N": return base
if shape == "P": frets = [0, 2, 4, 6] # porcupine
elif shape == "G": frets = [0, 1, 3, 5] # gun
elif shape == "W": frets = [0, 2, 3, 5] # westside
elif shape == "C": frets = [0, 2, 4, 5] # chicken
elif shape == "A": frets = [0, 1, 3, 4] # alien
elif shape == "D": frets = [0, 1, 2, 4] # dog
elif shape == "K": frets = [0, 2, 3, 4] # duck
elif shape == "H": frets = [0, 1, 2, 3] # huddle
return str(frets[int(finger) - 1] + int(base))
def note_at(string, fret):
return decimal_to_note(note_to_decimal("5Y") - (int(string) * 7) + int(fret))