-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChord.ml
73 lines (68 loc) · 1.68 KB
/
Chord.ml
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
type chordel =
RelNote of int | AbsNote of int | Root of int
type chord =
Nil | Cons of (chordel * chord)
let rec findroot music =
match music with
| Nil -> None
| Cons(Root x,_) -> Some x
| Cons(RelNote _,t) -> findroot t
| Cons(AbsNote _,t) -> findroot t
let rec calcnoteslist root music =
match music with
| Nil -> []
| Cons(Root x,t) -> calcnoteslist root t
| Cons(RelNote 0,t) -> calcnoteslist root t
| Cons(RelNote x,t) -> ((x+root) mod 12)::(calcnoteslist root t)
| Cons(AbsNote x,t) -> if (x=root) then (calcnoteslist root t)
else (x::(calcnoteslist root t))
let rec gettexstring l =
let get_val x =
match x with
| 0 -> "c "
| 1 -> "des "
| 2 -> "d "
| 3 -> "ees "
| 4 -> "e "
| 5 -> "f "
| 6 -> "fis "
| 7 -> "g "
| 8 -> "aes "
| 9 -> "a "
| 10 -> "bes "
| 11 -> "b "
| _ -> ""
in
match l with
| [] -> ">2 "
| h::t -> (get_val h)^(gettexstring t)
let calcnotesfromlist pre prebass post postbass root list =
let rec rem_dupls l =
match l with
| [] -> []
| h::t -> if (List.mem h t) then
(rem_dupls t) else h::(rem_dupls t)
in
let getbass r =
match r with
| 0 -> "c"
| 1-> "des"
| 2 -> "d"
| 3 -> "ees"
| 4 -> "e"
| 5 -> "f"
| 6 -> "fis"
| 7 -> "g"
| 8 -> "aes"
| 9 -> "a"
| 10 -> "bes"
| 11 -> "b"
| _ -> ""
in
let gt a b =
if (a=b) then 0 else
(if (a>b) then 1 else -1)
in
let sortlist = List.sort gt (rem_dupls list) in
let stave2 = ("<"^(gettexstring sortlist)) in
((pre^" "^stave2^" "^post),(prebass^" "^(getbass root)^"2 "^postbass))