-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrills.lib
132 lines (120 loc) · 2.91 KB
/
drills.lib
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
# vim: filetype=sh
INSTRUMENT=57
OUTDIR=$HOME/library/workout
mkdir -p $OUTDIR
function mcd { mkdir -p "$1"; cd "$1"; }
#
# create a directory for each drill, adding rotation number, drill number and permutations
#
# $1 drill name
# $2+ drill permutation patterns
#
function drill {
DRILLNUM=$((DRILLNUM+1))
dir="00.$(printf %02d $DRILLNUM).$1"
mkdir "$dir"
# join and normalise the permutations pattern
# brace expansion uses spaces as separators, so we replace them with underscores
pattern="${*:2}"
pattern="${pattern// /_}"
# make one file per permutation
i=0
for permutation in $(eval echo "$pattern"); do
i=$((i+1))
echo -e ${permutation//_/\\n} > "$dir"/$(printf %04d $i)."${permutation//_/ }".txt
done
}
function drillcd {
drill $*
cd "00.$(printf %02d $DRILLNUM).$1"
}
DRILLNUM=0
#
# convert an abc score to an mp3 file
#
# $1 abc score
# $2 output directory
# $3 output filename
# $4 transpose semitones (default 0)
# $5 transpose tempo % (default 100)
#
function make_mp3 {
if [ -f "$2/$3" ]; then
echo "$3 already exists; skipping"
return
fi
mkdir -p "$2"
echo "$1" | abc2midi /dev/stdin -o /dev/stdout \
| timidity - --output-24bit -A800 -K${4:=0} -T${5:=100} -Ow -o - \
| ffmpeg -loglevel error -i - -ac 1 -ab 64k "$2/$3"
}
#
# generate a set of mp3s by transposing the pitch and tempo of the score
#
# $1 set name
# $2 abc score in the key of C with a tempo of 100
# $3 pitches
#
function generate_scales {
STEPS=$((12#${3:0:2} - 12#40))
for PITCH in $3; do
TEMPO=20 # percent
while [ $TEMPO -le 400 ]; do
make_mp3 "$2" $OUTDIR/$1/$PITCH $(printf %03d $TEMPO).$PITCH.${1/\//-}.mp3 $STEPS $TEMPO
TEMPO=$((TEMPO+10))
done
STEPS=$((STEPS+1))
done
}
#
# generate a set of mp3s by transposing the pitch and tempo of the score
#
# $1 drill name
# $2 abc score for the base position (fret=0)
# $* list of frets to transpose to
#
function generate_pattern_scales {
for FRET in ${@:3}; do
TEMPO=30 # percent
while [ $TEMPO -le 240 ]; do
make_mp3 "
X:0
M:4/4
L:1/4
Q:100
K:C
| [I:MIDI program 115]
|cccc| [I:MIDI program $((INSTRUMENT - 1))]
$2" "$1/fret=$FRET" $(printf %03d $TEMPO).mp3 $FRET $TEMPO
TEMPO=$((TEMPO+30))
done
done
}
#
# generate a set of mp3s by transposing the tempo of the score
#
# $1 set name
# $2 abc score with a tempo of 100
#
function generate_tempos {
TEMPO=20 # percent
while [ $TEMPO -le 400 ]; do
make_mp3 "$2" $OUTDIR/$1 \'$(printf %03d $TEMPO).${1/\//-}.mp3 0 $TEMPO
TEMPO=$((TEMPO+10))
done
}
# create a directory for each drill and one file defining each drill variable
function drill~ {
mkdir -p $1;
i=0
for var in ${@:2}; do
i=$((i+1))
touch $1/$i.$var
done
}
# create a set of drills for each scale key
function scale {
for TONIC in 0 1 2 3 4 5 6 7 8 9 X Y; do
drill $1/00.$TONIC/$2 ${@:3}
done
}