forked from DCMLab/protovoices-haskell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainExamples.hs
257 lines (238 loc) · 7.61 KB
/
MainExamples.hs
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
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE QualifiedDo #-}
{-# OPTIONS_GHC -Wno-all #-}
module Main where
import ChartParser
import Common
import Display
import PVGrammar
import PVGrammar.Generate
import PVGrammar.Parse
import Musicology.Core
import Musicology.Core.Slicing
-- import Musicology.Internal.Helpers
import Musicology.MusicXML
import Musicology.Pitch.Spelled as MT
import Data.Either (partitionEithers)
import Data.Maybe (catMaybes)
import Data.Ratio (Ratio (..))
import Lens.Micro (over)
import Control.Monad
( forM
, forM_
)
import Data.List qualified as L
import Data.Semiring qualified as R
import Data.Set qualified as S
import Data.Text qualified as T
import Data.Text.IO qualified as T
import Data.Typeable (Proxy (Proxy))
import Data.String (fromString)
-- better do syntax
import Language.Haskell.DoNotation qualified as Do
plotSteps :: FilePath -> [Leftmost s f h] -> IO ()
plotSteps fn deriv = do
let graphs = unfoldDerivation derivationPlayerEmpty deriv
(errors, steps) = partitionEithers graphs
mapM_ putStrLn errors
writeGraphs fn $ reverse steps
putGraph n deriv = case replayDerivation' n derivationPlayerEmpty deriv of
(Left error) -> putStrLn error
(Right g) -> T.putStrLn $ tikzPic $ tikzDerivationGraph showTexT showTexT g
plotDeriv fn deriv = do
case replayDerivation derivationPlayerPV deriv of
(Left err) -> putStrLn err
(Right g) -> viewGraph fn g
example1 = buildDerivation $ Do.do
split ()
splitRight ()
spread ()
freeze ()
split ()
freeze ()
freeze ()
freeze ()
freeze ()
example1Main :: IO ()
example1Main = do
let Right g = replayDerivation derivationPlayerEmpty example1
writeGraph "doc-images/monadic-deriv.tex" g
spreadSplitLeft = buildPartialDerivation @2 $ spread () Do.>> split ()
splitLeftSpread =
buildPartialDerivation @2 $ split () Do.>> freeze () Do.>> spread ()
splitRightSpread = buildPartialDerivation @2 $ Do.do
splitRight ()
spread ()
exampleBoth = buildPartialDerivation @3 $ Do.do
splitRight ()
spread ()
freeze ()
freeze ()
freeze ()
spread ()
examplePartials = buildDerivation $ Do.do
split ()
spread ()
split ()
freeze ()
spread ()
derivBach :: [PVLeftmost (Pitch MT.SIC)]
derivBach = buildDerivation $ Do.do
split $ mkSplit $ do
splitRegular Start Stop (d' nat) RootNote False False
splitRegular Start Stop (d' nat) RootNote False False
splitRegular Start Stop (f' nat) RootNote False False
splitRegular Start Stop (a' nat) RootNote False False
splitRegular Start Stop (a' nat) RootNote False False
spread $ mkSpread $ do
spreadNote (d' nat) ToBoth True
spreadNote (f' nat) ToBoth True
spreadNote (a' nat) (ToRight 1) True
addPassing (d' nat) (f' nat)
splitRight $ mkSplit $ do
splitPassing (d' nat) (f' nat) (e' nat) PassingMid True False
splitRegular (Inner $ d' nat) (Inner $ d' nat) (c' shp) FullNeighbor True True
splitRegular (Inner $ d' nat) (Inner $ d' nat) (d' nat) FullRepeat True True
splitRegular (Inner $ a' nat) (Inner $ a' nat) (a' nat) FullRepeat True True
splitRegular (Inner $ f' nat) (Inner $ f' nat) (g' nat) FullNeighbor True True
splitRight $ mkSplit $ do
splitRegular (Inner $ d' nat) (Inner $ d' nat) (d' nat) FullRepeat True True
splitRegular (Inner $ a' nat) (Inner $ a' nat) (b' flt) FullNeighbor False False
splitRegular
(Inner $ d' nat)
(Inner $ c' shp)
(c' shp)
LeftRepeatOfRight
False
True
splitRegular
(Inner $ d' nat)
(Inner $ e' nat)
(e' nat)
LeftRepeatOfRight
False
False
splitRegular
(Inner $ f' nat)
(Inner $ g' nat)
(g' nat)
LeftRepeatOfRight
False
True
spread $ mkSpread $ do
spreadNote (d' nat) ToBoth True
spreadNote (f' nat) (ToRight 1) False
spreadNote (a' nat) (ToRight 1) False
split $ mkSplit $ addToRight (d' nat) (d' nat) LeftRepeat False
freeze FreezeOp
freeze FreezeOp
spread $ mkSpread $ do
spreadNote (d' nat) (ToRight 1) True
spreadNote (f' nat) (ToRight 1) False
spreadNote (a' nat) (ToLeft 1) False
spread $ mkSpread $ do
spreadNote (d' nat) ToBoth True
spreadNote (a' nat) ToBoth True
freeze FreezeOp
split $ mkSplit $ do
splitRegular (Inner $ a' nat) (Inner $ a' nat) (b' flt) FullNeighbor False False
splitRegular (Inner $ a' nat) (Inner $ a' nat) (g' nat) FullNeighbor False False
splitRegular (Inner $ d' nat) (Inner $ d' nat) (d' nat) FullRepeat True True
spread $ mkSpread $ do
spreadNote (d' nat) ToBoth True
spreadNote (b' flt) (ToLeft 1) False
spreadNote (g' nat) (ToRight 1) False
freeze FreezeOp
freeze FreezeOp
freeze FreezeOp
spread $ mkSpread $ do
spreadNote (d' nat) (ToRight 1) True
spreadNote (f' nat) (ToLeft 1) False
addPassing (f' nat) (d' nat)
freeze FreezeOp
split $ mkSplit $ do
splitPassing (f' nat) (d' nat) (e' nat) PassingMid False False
splitRegular (Inner $ d' nat) (Inner $ d' nat) (d' nat) FullRepeat True True
freeze FreezeOp
freeze FreezeOp
spread $ mkSpread $ do
spreadNote (d' nat) ToBoth True
spreadNote (c' shp) ToBoth True
spreadNote (b' flt) (ToRight 1) False
spreadNote (e' nat) (ToRight 1) False
spreadNote (g' nat) (ToRight 1) False
freeze FreezeOp
spread $ mkSpread $ do
spreadNote (d' nat) ToBoth True
spreadNote (c' shp) ToBoth True
spreadNote (b' flt) ToBoth True
spreadNote (e' nat) (ToRight 1) False
spreadNote (g' nat) (ToRight 1) False
freeze FreezeOp
spread $ mkSpread $ do
spreadNote (d' nat) ToBoth True
spreadNote (c' shp) ToBoth True
spreadNote (b' flt) ToBoth True
spreadNote (e' nat) (ToLeft 1) False
spreadNote (g' nat) (ToRight 1) False
freeze FreezeOp
freeze FreezeOp
splitRight $ mkSplit $ do
splitRegular
(Inner $ g' nat)
(Inner $ f' nat)
(g' nat)
RightRepeatOfLeft
False
False
splitRegular (Inner $ a' nat) (Inner $ a' nat) (a' nat) FullRepeat True True
splitRegular (Inner $ d' nat) (Inner $ d' nat) (d' nat) FullRepeat True True
splitRegular
(Inner $ c' shp)
(Inner $ d' nat)
(d' nat)
LeftRepeatOfRight
False
True
spread $ mkSpread $ do
spreadNote (d' nat) ToBoth True
spreadNote (c' shp) ToBoth True
spreadNote (a' nat) ToBoth True
spreadNote (g' nat) ToBoth False
spreadNote (e' nat) (ToRight 1) False
freeze FreezeOp
spread $ mkSpread $ do
spreadNote (d' nat) ToBoth True
spreadNote (c' shp) ToBoth True
spreadNote (a' nat) ToBoth True
spreadNote (g' nat) (ToLeft 1) False
spreadNote (e' nat) (ToRight 1) False
addPassing (g' nat) (e' nat)
freeze FreezeOp
split $ mkSplit $ do
splitRegular (Inner $ d' nat) (Inner $ d' nat) (d' nat) FullRepeat True True
splitRegular (Inner $ a' nat) (Inner $ a' nat) (a' nat) FullRepeat True True
splitRegular (Inner $ c' shp) (Inner $ c' shp) (c' shp) FullRepeat True True
splitPassing (g' nat) (e' nat) (f' nat) PassingMid False False
freeze FreezeOp
freeze FreezeOp
freeze FreezeOp
spread $ mkSpread $ do
spreadNote (d' nat) (ToLeft 1) False
spreadNote (f' nat) ToBoth False
spreadNote (a' nat) (ToLeft 2) False
spread $ mkSpread $ do
spreadNote (d' nat) (ToLeft 1) False
spreadNote (f' nat) (ToLeft 1) False
spreadNote (a' nat) (ToRight 1) True
addPassing (f' nat) (d' nat)
freeze FreezeOp
split $ mkSplit $ do
splitPassing (f' nat) (d' nat) (e' nat) PassingMid False False
splitRegular (Inner $ a' nat) (Inner $ a' nat) (a' nat) FullRepeat True True
addToRight (a' nat) (a' nat) LeftRepeat True
freeze FreezeOp
freeze FreezeOp
freeze FreezeOp
freeze FreezeOp
main = pure ()