Upload
neeraj-bhusari
View
216
Download
0
Embed Size (px)
Citation preview
8/14/2019 2008andersonphd.pdf
1/191
Anderson, Alasdair J. (2011)Analysis of musical structures: an approach
utilising monadic parser combinators.PhD thesis.
http://theses.gla.ac.uk/2353/
Copyright and moral rights for this thesis are retained by the author
A copy can be downloaded for personal non-commercial research or
study, without prior permission or charge
This thesis cannot be reproduced or quoted extensively from without firstobtaining permission in writing from the Author
The content must not be changed in any way or sold commercially in any
format or medium without the formal permission of the Author
When referring to this work, full bibliographic details including the
author, title, awarding institution and date of the thesis must be given
Glasgow Theses Service
http://theses.gla.ac.uk/
http://theses.gla.ac.uk/2353/http://theses.gla.ac.uk/2353/8/14/2019 2008andersonphd.pdf
2/191
8/14/2019 2008andersonphd.pdf
3/191
8/14/2019 2008andersonphd.pdf
4/191
8/14/2019 2008andersonphd.pdf
5/191
8/14/2019 2008andersonphd.pdf
6/191
8/14/2019 2008andersonphd.pdf
7/191
8/14/2019 2008andersonphd.pdf
8/191
8/14/2019 2008andersonphd.pdf
9/191
8/14/2019 2008andersonphd.pdf
10/191
8/14/2019 2008andersonphd.pdf
11/191
8/14/2019 2008andersonphd.pdf
12/191
8/14/2019 2008andersonphd.pdf
13/191
8/14/2019 2008andersonphd.pdf
14/191
8/14/2019 2008andersonphd.pdf
15/191
8/14/2019 2008andersonphd.pdf
16/191
8/14/2019 2008andersonphd.pdf
17/191
8/14/2019 2008andersonphd.pdf
18/191
8/14/2019 2008andersonphd.pdf
19/191
8/14/2019 2008andersonphd.pdf
20/191
8/14/2019 2008andersonphd.pdf
21/191
8/14/2019 2008andersonphd.pdf
22/191
8/14/2019 2008andersonphd.pdf
23/191
8/14/2019 2008andersonphd.pdf
24/191
8/14/2019 2008andersonphd.pdf
25/191
8/14/2019 2008andersonphd.pdf
26/191
8/14/2019 2008andersonphd.pdf
27/191
8/14/2019 2008andersonphd.pdf
28/191
8/14/2019 2008andersonphd.pdf
29/191
8/14/2019 2008andersonphd.pdf
30/191
8/14/2019 2008andersonphd.pdf
31/191
8/14/2019 2008andersonphd.pdf
32/191
8/14/2019 2008andersonphd.pdf
33/191
8/14/2019 2008andersonphd.pdf
34/191
8/14/2019 2008andersonphd.pdf
35/191
8/14/2019 2008andersonphd.pdf
36/191
8/14/2019 2008andersonphd.pdf
37/191
8/14/2019 2008andersonphd.pdf
38/191
8/14/2019 2008andersonphd.pdf
39/191
8/14/2019 2008andersonphd.pdf
40/191
2424
8
24
8
24
24
8
8
6
8/14/2019 2008andersonphd.pdf
41/191
8/14/2019 2008andersonphd.pdf
42/191
653
6
35
7
4
34
36
6
6
24
8/14/2019 2008andersonphd.pdf
43/191
8/14/2019 2008andersonphd.pdf
44/191
8/14/2019 2008andersonphd.pdf
45/191
8/14/2019 2008andersonphd.pdf
46/191
4343
7
12
17
8/14/2019 2008andersonphd.pdf
47/191
8/14/2019 2008andersonphd.pdf
48/191
8/14/2019 2008andersonphd.pdf
49/191
8/14/2019 2008andersonphd.pdf
50/191
3
8/14/2019 2008andersonphd.pdf
51/191
43
43
5
8/14/2019 2008andersonphd.pdf
52/191
UpperNeighbour
DoubleNeighbour
LowerNeighbour
8/14/2019 2008andersonphd.pdf
53/191
PassingNotes
8/14/2019 2008andersonphd.pdf
54/191
8/14/2019 2008andersonphd.pdf
55/191
8/14/2019 2008andersonphd.pdf
56/191
8/14/2019 2008andersonphd.pdf
57/191
8/14/2019 2008andersonphd.pdf
58/191
8/14/2019 2008andersonphd.pdf
59/191
8/14/2019 2008andersonphd.pdf
60/191
8/14/2019 2008andersonphd.pdf
61/191
C
D
8/14/2019 2008andersonphd.pdf
62/191
8/14/2019 2008andersonphd.pdf
63/191
8/14/2019 2008andersonphd.pdf
64/191
8/14/2019 2008andersonphd.pdf
65/191
8/14/2019 2008andersonphd.pdf
66/191
8/14/2019 2008andersonphd.pdf
67/191
8/14/2019 2008andersonphd.pdf
68/191
a.f
f(x)
f(x) =x3 + 2x2 7x x.x3 + 2x2 7x
f(3) = 24 (x.x3 + 2x2 7x)3 = 24
a f
8/14/2019 2008andersonphd.pdf
69/191
2
[1] > (defun double(x)( 2x))
[2] > (double(double(double(double1))))16
[3] > (defun repeat(f n o)(if (zerop n)
o
(repeat f (1 n) (funcall f o))))[4] > (repeat#double4 1)16
8/14/2019 2008andersonphd.pdf
70/191
[5] > (repeat#(lambda(v) ( 2v)) 4 1)16
(p1 e1, , pn en)
8/14/2019 2008andersonphd.pdf
71/191
8/14/2019 2008andersonphd.pdf
72/191
8/14/2019 2008andersonphd.pdf
73/191
8/14/2019 2008andersonphd.pdf
74/191
8/14/2019 2008andersonphd.pdf
75/191
8/14/2019 2008andersonphd.pdf
76/191
class Monad m where
(=) :: m a (a m b) m b() :: m a m b m breturn :: a m afail :: String m a
type TP a=String [(a, String)]
pass ::a TP apass a=inp [(a, inp)]
discard ::TP adiscard=inp [ ]
bind ::TP a (a TP b) TP bpbindf =inp concat[f v inp | (v, inp) p inp]
8/14/2019 2008andersonphd.pdf
77/191
item ::TP Charitem=inp caseinp of
[] [](x :xs) [(x, xs)]
satsify :: (Char Bool) TP Charsatisfy p =itembind
x ifp xthenpass xelsediscard
letter ::TP Charletter=satisfy isAlpha
space ::TP Charspace=satisfy isSpace
8/14/2019 2008andersonphd.pdf
78/191
8/14/2019 2008andersonphd.pdf
79/191
alt ::TP a TP a TP apaltq=inp (p inp + +q inp)
choice ::TP a TP a TP apchoiceq=inp case(paltq)inp of
[ ](x : ) [x]
perhaps ::TParser a TParser[a]perhaps p =(some p) choicepass[]
some ::TParser a TParser[a]some p =pbind
x perhaps pbindxs pass(x :xs)
skip ::TParser a TParser b TParser apskipq=pbind
x perhaps qbind pass x
word ::TParser Stringword=some letter
8/14/2019 2008andersonphd.pdf
80/191
8/14/2019 2008andersonphd.pdf
81/191
7 + (6 52 + 3)
7 + (6 52 + 3) =
= 7 + (6 25 + 3)
= 7 + (150 + 3)
= 7 + 153
= 160
8/14/2019 2008andersonphd.pdf
82/191
PRororganic or+ganic
PRorganorganic organ+ic
PRorganicorganic organic
8/14/2019 2008andersonphd.pdf
83/191
8/14/2019 2008andersonphd.pdf
84/191
83
8/14/2019 2008andersonphd.pdf
85/191
8/14/2019 2008andersonphd.pdf
86/191
Gott erhalte melody
Variation 2
3
Variation 3
3
8/14/2019 2008andersonphd.pdf
87/191
8/14/2019 2008andersonphd.pdf
88/191
8/14/2019 2008andersonphd.pdf
89/191
8/14/2019 2008andersonphd.pdf
90/191
type Note=(Int, Int)
type B40 =Notetype B12 =Notetype B7 =Note
8/14/2019 2008andersonphd.pdf
91/191
x
Bx
8/14/2019 2008andersonphd.pdf
92/191
B/C/D Bx/C/D Cx/D/E D/E/F Dx/E/F E/F/G Ex/F/G Fx/G/A
G/A Gx/A/B A/B/C
Ax/B/C
8/14/2019 2008andersonphd.pdf
93/191
x
8/14/2019 2008andersonphd.pdf
94/191
type Crd = [Note]
8/14/2019 2008andersonphd.pdf
95/191
type Seq = [Crd]
C
E
C
D
E
F
Dx
C
E
D
E
8/14/2019 2008andersonphd.pdf
96/191
type Parser a = Seq [(a, Seq)]
noteitem ::Parser B40noteitem=inp caseinp of
[] [](x :xs) [(xel, xs) | xel x]
8/14/2019 2008andersonphd.pdf
97/191
8/14/2019 2008andersonphd.pdf
98/191
cMapAll :: [a] [a] (a a Bool) BoolcMapAll c1c2f =and[ or[ f n1n2 | n2 c2] | n1 c1]
cMapAny :: [a] [a] (a a Bool) BoolcMapAny c1c2f =or[ or[ f n1n2 | n2 c2] | n1 c1]
8/14/2019 2008andersonphd.pdf
99/191
function ::B40 B40 Bool
notescan ::Parser B40notescan=inp caseinp of
[] [](x :xs) [(xel, x :xs) | xel x]
type TxtParser a=String [(a, String)]
itemscan ::TxtParser Charitemscan=inp caseinp of
[] [](x :xs) [(x, x :xs)]
8/14/2019 2008andersonphd.pdf
100/191
{ui : ui Z, un+1 un = 1}
8/14/2019 2008andersonphd.pdf
101/191
un+1 un = 1
8/14/2019 2008andersonphd.pdf
102/191
2n
2n+1
8/14/2019 2008andersonphd.pdf
103/191
un un+1 = 1
8/14/2019 2008andersonphd.pdf
104/191
seqsat ::Parser Seq (Seq Bool) ABParser Seqseqsat p c=pbindx ifc xthenalways xelsenever
somelap ::forall a.(Seq > [([a], Seq)]) > Seq > [([a], Seq)]somelap p =(ppseqmanylap p) usinglap
manylap ::forall a.(Seq > [([a], Seq)]) > Seq > [([a], Seq)]manylap p =(somelap p) choicealways[]
lap ::forall a.([a], [a]) > [a]lap(xh, []) =xhlap(xh, xt) =xh + + (tail xt)
8/14/2019 2008andersonphd.pdf
105/191
chordown ::Parser Seqchorddown=seqsat duplet seqstepdown
descent ::Parser Seqdescent=seqsat(somelap chorddown)length3
8/14/2019 2008andersonphd.pdf
106/191
43
ascent ::Parser Seqascent=seqsat(somelap chordup)length3
8/14/2019 2008andersonphd.pdf
107/191
43
neighbourup =((chorduppseqchorddown) usinglap) choicechorddownneighbourdown=((chorddownpseqchordup) usinglap) choicechordup
8/14/2019 2008andersonphd.pdf
108/191
neighbour ::Parser Seqneighbour=neighbourup choiceneighbourdown
43
8/14/2019 2008andersonphd.pdf
109/191
passingdown=(chorddownpseqchorddown) usinglappassingup =(chorduppseqchordup) usinglap
passing ::Parser Seqpassing=passingupchoicepassingdown
8/14/2019 2008andersonphd.pdf
110/191
8/14/2019 2008andersonphd.pdf
111/191
8/14/2019 2008andersonphd.pdf
112/191
alt ::Parser a Parser a Parser apaltq=inp (p inp ++ q inp)
8/14/2019 2008andersonphd.pdf
113/191
43
43
choice ::Parser a Parser a Parser apchoiceq=inp case(paltq)inp of
[] [](x :xs) [x]
8/14/2019 2008andersonphd.pdf
114/191
pllel :: [Parser a] Parser apllel ap=case(length ap)of
2 (head ap) choice (last ap)otherwise (head ap) choice (pllel(tail ap))
43
8/14/2019 2008andersonphd.pdf
115/191
many ::Parser a Parser[a]many p =(some p) choicealways[]
some ::Parser a Parser[a]some p =pbindx
many pbindxs always(x :xs)
8/14/2019 2008andersonphd.pdf
116/191
8/14/2019 2008andersonphd.pdf
117/191
seqitem ::Parser Seqseqitem=inp caseinp of
[] [](x :xs) [([x], xs)]
43
8/14/2019 2008andersonphd.pdf
118/191
8/14/2019 2008andersonphd.pdf
119/191
8/14/2019 2008andersonphd.pdf
120/191
A
D
D
43
A
8/14/2019 2008andersonphd.pdf
121/191
8/14/2019 2008andersonphd.pdf
122/191
8/14/2019 2008andersonphd.pdf
123/191
8/14/2019 2008andersonphd.pdf
124/191
8/14/2019 2008andersonphd.pdf
125/191
8/14/2019 2008andersonphd.pdf
126/191
8/14/2019 2008andersonphd.pdf
127/191
interesting :: [Parser Seq] Parser Seqinteresting p =seqsat(pnone p)length3
8/14/2019 2008andersonphd.pdf
128/191
pnone :: [Parser Seq] Parser Seqpnone p =inp case((pllel p)inp)of
[] noneagain p inpotherwise always[] inp
noneagain :: [Parser Seq] > Parser Seqnoneagain p =seqitembindy
(pnone p) bindz always(y+ +z)
8/14/2019 2008andersonphd.pdf
129/191
43
8/14/2019 2008andersonphd.pdf
130/191
A
I
I
43
D
I
A
I
D 4
A A
8/14/2019 2008andersonphd.pdf
131/191
pedalpoint ::Parser Seqpedalpoint=seqsat tripletnote pedalBin
pedal ::Parser Seqpedal=seqsat(somelap pedalpoint)length5
8/14/2019 2008andersonphd.pdf
132/191
43
8/14/2019 2008andersonphd.pdf
133/191
8/14/2019 2008andersonphd.pdf
134/191
8/14/2019 2008andersonphd.pdf
135/191
type N5 = (Int, Int, Int, Int, Int)
type Crd =[N5]type HSlice=[N5]type VSlice=[N5]
type Seq =[[N5]]type HSlab =[VSlice]type VSlab =[HSlice]
8/14/2019 2008andersonphd.pdf
136/191
8/14/2019 2008andersonphd.pdf
137/191
op :: (Parser Seq, String) Parser Token Parser Token(p, t) opxs=(ptokt) altxs
combiner :: [(Parser Seq, String)] Parser[Token]
combiner l inp| inp == [] = [([(End, inp)], inp)]| otherwise = case(foldr op never l inp) of
[] combiner l(tail inp)x concat[tokenjoin(t, s, l) | (t, s) x]
tokenjoin :: (Token, Seq, [(Parser Seq, String)]) [([Token, Seq)]tokenjoin(t, s, l) =[(t :t, s) | (t, s) (combiner l s)]
8/14/2019 2008andersonphd.pdf
138/191
8/14/2019 2008andersonphd.pdf
139/191
Al
Al
N
Al
N
N
I
N
Al
Al
I
Al
8/14/2019 2008andersonphd.pdf
140/191
8/14/2019 2008andersonphd.pdf
141/191
8/14/2019 2008andersonphd.pdf
142/191
8/14/2019 2008andersonphd.pdf
143/191
8/14/2019 2008andersonphd.pdf
144/191
Al
Al
Al
Al
2
Al
3
Al
4
Al
Al
5
Ne St
Al
8/14/2019 2008andersonphd.pdf
145/191
6
Al
7
St
Ne
Al
Al
8
Al
St
St
9
St
St
St
10
St
8/14/2019 2008andersonphd.pdf
146/191
Ne
11
Ne
Al
St
12
StSt
St
13
Al
St
14
Ne
Ne
15
Al
8/14/2019 2008andersonphd.pdf
147/191
Al
16
Al
Al
17
Al
Al
Al
18
19
St
Ne
8/14/2019 2008andersonphd.pdf
148/191
St
St
20
St
St
St
St
21
St
St
St
22
St
23
St
8/14/2019 2008andersonphd.pdf
149/191
St
St
St
24
St
St
St
25
St
St
St
26
St
St
St
27
Ne
8/14/2019 2008andersonphd.pdf
150/191
St28
Ne
St
St
29
St
St
30
St31
Al
32
8/14/2019 2008andersonphd.pdf
151/191
33
34
35
36
37
AlSt
8/14/2019 2008andersonphd.pdf
152/191
8/14/2019 2008andersonphd.pdf
153/191
8/14/2019 2008andersonphd.pdf
154/191
Nb
Ig
Alt
Nb
Nb
Ig
2
Alt
Nb
Nb
Ig
3
Alt
Nb
8/14/2019 2008andersonphd.pdf
155/191
Nb Ig
4
AltNb
Alt
St
5
Nb
Nb
Alt
Ig
6
Nb
Nb
Nb
Alt
St
Ig
7
Nb
Nb
8/14/2019 2008andersonphd.pdf
156/191
8/14/2019 2008andersonphd.pdf
157/191
St12
St St
St
13
Alt
St
14
Nb
Nb
Alt
Ig
15
Nb
Nb
Nb
Alt
Nb
16
Ig
Nb
8/14/2019 2008andersonphd.pdf
158/191
AltNb
Nb
Ig
17
Nb
Ig
18
Alt
Nb
St
19
Nb
Ig St
Ig
St
20
St
St
8/14/2019 2008andersonphd.pdf
159/191
St
Ig St
Ig
21
St
St
St
22
St
23
St
Ig
St
Ig
St
St
24
St
8/14/2019 2008andersonphd.pdf
160/191
8/14/2019 2008andersonphd.pdf
161/191
29
StSt
St
30
St
AltSt
31
32
33
8/14/2019 2008andersonphd.pdf
162/191
34
35
36
Alt37
St
38
8/14/2019 2008andersonphd.pdf
163/191
39
Alt
Alt
40
41
Alt
8/14/2019 2008andersonphd.pdf
164/191
8/14/2019 2008andersonphd.pdf
165/191
Nb
Nb
Al
Al
Al
Ig
Ig
Ig
Ig
Ig
5
2
0
Ig
Ig
7
4
3
6
Al
Al
Al
IgAl
1
Nb
Ig
Ig
Ig
IgAl
Ig
Al
Al
Nb
Ig
Al
Ig
Ig
Al
8/14/2019 2008andersonphd.pdf
166/191
Nb
Nb
Al
Nb
Al
Ig
Al
Nb
Nb
Nb
Nb
Nb
Ig
Ig
Ig
Ig
Ig
9
Ig
8
11
Al
13
12
Al
Al
Nb
15
Al
Nb
Al
Nb
Nb
10
14
Ig
Al
Al
Al
Al
8/14/2019 2008andersonphd.pdf
167/191
Al
Nb
Nb
Al
Al
Al
Nb
Nb
Ig
Al
Ig
Al
Al
Al
3
Ig
6
Al
Al
Al
2
0
4
5
Nb
Nb
1
Nb
7
Nb
Ig
Al
8/14/2019 2008andersonphd.pdf
168/191
Nb
Ig
Al
Al
Al
Nb
Nb
Al
Al
Ig
Ig
Ig
10
Al
Nb
Nb
Nb
Al
Al
Al
Al
13
Nb
Al
Nb
Al
14
15
8
11
9
12
8/14/2019 2008andersonphd.pdf
169/191
8/14/2019 2008andersonphd.pdf
170/191
8/14/2019 2008andersonphd.pdf
171/191
8/14/2019 2008andersonphd.pdf
172/191
8/14/2019 2008andersonphd.pdf
173/191
8/14/2019 2008andersonphd.pdf
174/191
8/14/2019 2008andersonphd.pdf
175/191
8/14/2019 2008andersonphd.pdf
176/191
8/14/2019 2008andersonphd.pdf
177/191
8/14/2019 2008andersonphd.pdf
178/191
8/14/2019 2008andersonphd.pdf
179/191
8/14/2019 2008andersonphd.pdf
180/191
8/14/2019 2008andersonphd.pdf
181/191
8/14/2019 2008andersonphd.pdf
182/191
8/14/2019 2008andersonphd.pdf
183/191
8/14/2019 2008andersonphd.pdf
184/191
8/14/2019 2008andersonphd.pdf
185/191
8/14/2019 2008andersonphd.pdf
186/191
8/14/2019 2008andersonphd.pdf
187/191
always :: a Parser a
always a = inp [(a, inp)]
never :: Parser a
never = inp []
duplet ::Parser Seqduplet=chorditembindx
chordscanbindy
always(x : [y])
8/14/2019 2008andersonphd.pdf
188/191
chorditem :: Parser Crd
chorditem = inp caseinp of
[] []
(x :xs) [(x, xs)]
chordscan :: Parser Crd
chordscan = inp caseinp of
[] []
(x :xs) [(x, x :xs)]
notestepup :: B40 B40 Bool
notestepup n1n2 = case((forty2Seven n1) b7Interval (forty2Seven n2))of
1 True
otherwiseFalse
notestepdown :: B40 B40 Bool
notestepdown n1n2 = notestepup n2n1
chordstepdown :: Crd Crd Bool
chordstepdown c1c2 = cMapAny c1c2notestepdown
seqstepdown :: Seq > Bool
seqstepdown[] = True
seqstepdown s@(c: cs)
8/14/2019 2008andersonphd.pdf
189/191
| (chordstepdown c(head cs)) == True=(seqstepup (tail cs))
| otherwise =False
bind :: Parser a (a Parser b) Parser b
pbindf = inp concat[f v inp | (v, inp) p inp]
tripletnote ::Parser Seq
tripletnote=noteitembindx
noteitembindy
notescanbindz
always([x] : [y] : [[z]])
pedalBin seq | (length seq) > 2 = chordpedal(seq!!0) (seq!!2)
| otherwise = False
chordpedal c1c2 =cMapAny c1c2
notepedal notepedal n1n2 =n1 nexactn2
mlex:: [(Parser Seq, String)] Parser[Token]
mlex=many.(foldr op never)
8/14/2019 2008andersonphd.pdf
190/191
many ::Parser a Parser[a]
many p =(some p) choicealways[]
8/14/2019 2008andersonphd.pdf
191/191