-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindisp.pure
50 lines (35 loc) · 1.21 KB
/
indisp.pure
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
/* Compute the indispensabilities for a given meter, using Barlow's method. */
using factor;
/* Input is a list or vector Q of prime numbers indicating the subdivisions of
the desired meter. The highest level comes first. Thus, e.g., [2,2] would
be used to denote a 4/4 meter (or, more generally, 4/n, depending on the
time base), [2,2,3] denotes 12/n, etc. The output is a list of weights
ranging from 0 to prd Q-1 giving the relative "indispensabilities"
(weights) of the pulses, which can be used to derive velocities or note
probabilities for the given meter. */
indisp Q = map (ind Q) (0..prd Q-1)
with
/* general indispensabilities */
ind Q k = sum
[S!i * pind (Q!i)
((bmod (k-1) (T!0) div T!(i+1) + 1) mod Q!i) |
i = 0..#Q-1]
when S = scanl (*) 1 Q;
T = reverse (scanl (*) 1 (reverse Q))
end;
bmod x y = x mod y if x>=0;
= bmod (x+y) y otherwise;
/* prime indispensabilities */
pind q k = bmod (k-1) q if q<=3;
pind q k = q div 4 if k==q-2;
= ind1 q (k-1) if k==q-1;
= ind1 q k otherwise;
ind1 q k = i+j
when
i = ind (reverse (factor (q-1))) k;
j = i>=q div 4;
end;
/* sums and products */
sum = foldl (+) 0;
prd = foldl (*) 1;
end;