-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.hs
More file actions
114 lines (87 loc) · 3.18 KB
/
Example.hs
File metadata and controls
114 lines (87 loc) · 3.18 KB
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
module Example
( genPiece
) where
import MusicTrees
import Trees
import Transform
import Chord
import Scale
import Generation
import qualified Random as R
import Euterpea
import System.Random
import Control.Monad.State
import qualified Data.List as L
-- The area where you can specify how the example piece is generated:
genPiece :: StdGen -> Euterpea.Music (Pitch, Volume)
genPiece gen =
let (cps,gen2) = genChordProgs 2 gen
chordsTree = genStartingTree cps
-- ^ the starting tree, filled with chords
(final, gen3) = sequencePlans gen2 ptPlans chordsTree
-- ^ the final tree, with all pts applied to it.
in toMusic final
-- GENERATIVE PLANS: -----------------------------------------------------------
ptPlans = [rhythmPlan, patternPlan]
rhythmPlan = Plan { _ttPool = map rhythm' [ronettes, n, evn 4]
, _ttDepth = \tree -> measureDepth tree + 1
, _skeleton = defaultPT'
}
patternPlan = Plan { _ttPool = map pattern [full, waltz, sadwaltz, falling]
, _ttDepth = \tree -> measureDepth tree
, _skeleton = defaultPT''
}
defaultPT' = Node id [
Node id [
Leaf id id
, Leaf id id
]
]
defaultPT'' = Node id [
Node id [
Leaf id id
, Leaf id id
]
, Node id [
Leaf id id
, Leaf id id
]
]
-- STARTING CHORD TREE: --------------------------------------------------------
structured :: Orientation -> [[Primitive Pitch]] -> MusicOT
structured o chords = Group H $ map (toGroup o) chords
genStartingTree cps = toMT $ insertionsPT cps
insertionsPT cs = Node (atDepth 0 [0..1]) [
Node (atDepth 1 [0..2]) [
Leaf (atDepth 2 [0..1]) (insert $ structured V (cs !! 0))
, Leaf (atDepth 2 [2..3]) (insert $ structured V (cs !! 1))
]
]
insertionsPT' = Node (atDepth 0 [0]) [
Leaf (atDepth 1 [0,1]) (insert $ structured V nico)
]
testBoy = toMT insertionsPT'
chordProgressions = [nico, house, dreams]
genChordProgs x = runState (R.getRandoms x chordProgressions)
--chord progression pool:
mkc p o m ints dur = map (\p -> Note dur p) $ pitches $ getChord (p,o) m ints
nico = [mkc C 3 Major [2,4,6] wn, mkc F 3 Major [2,4,6] wn]
house = [mkc A 3 Minor [2,4,6] wn, mkc E 3 Minor [2,4,6] wn]
dreams = [mkc C 3 Major [2,4,6] wn, mkc A 2 Minor [2,4,6] wn]
strange = [mkc D 3 Major [2,4,6] wn, mkc D 3 Minor [2,4,6] wn]
-- TREE TRANSFORMATIONS: -------------------------------------------------------
-- patterns pool:
patterns = [full, sad, falling, waltz, rising, sadwaltz]
full, sad, falling, waltz, sadwaltz, rising :: Pattern
full = [[0,1,2]]
sad = [[0,1,2,3]]
falling = [[2], [1], [0]]
waltz = [[0], [1,2], [1,2]]
sadwaltz = [[0,3], [1,2,3], [1,2,3]]
rising = L.reverse falling
-- rhythm pool:
rhythms = [n, ronettes, ffff, evn 4]
n = [(qn + en), (qn + en), qn]
ronettes = [(qn + en), en, hn]
ffff = [(qn +en), en, en, en, qn]
mr = [(qn + en), (qn + en), qn,(qn + en), qn, (qn + en)]