-
Notifications
You must be signed in to change notification settings - Fork 0
/
LiveCodeMe.hhs
141 lines (141 loc) · 4.52 KB
/
LiveCodeMe.hhs
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
{
"version": "0.2.1.0",
"cells": [
{
"cell_type": "text",
"source": "How to play sound in Haskell?\n\nConnect to a MIDI output device (e.g. Fluidsynth).\n"
},
{
"cell_type": "code",
"source": "s <- openMidi\naddFinalizerSession $ closeMidi >>= print\nshow s"
},
{
"cell_type": "text",
"source": "Create an ensemble and players.\n"
},
{
"cell_type": "code",
"source": "ensemble <- newEnsemble s\ndrums <- newPlayer 10\nbass <- newPlayer 1\npad <- newPlayer 2\nkeys <- newPlayer 3\nlead <- newPlayer 4\nsetTempoBpm ensemble 110\ntogether ensemble [drums, bass, pad, keys, lead]\naddFinalizerSession $ dissolve ensemble"
},
{
"cell_type": "code",
"source": "setTempoBpm ensemble 110"
},
{
"cell_type": "text",
"source": "Drums\n"
},
{
"cell_type": "code",
"source": "play drums $ hasten 4 $\n (with bd <$> hasten 2 (beat \"X,,xX,,x\"))\n <|> (with sn <$> beat \",x,x\")\n <|> (with chh <$> (hasten 4 $ beat $ times (2*4) \"Xx\"))\n[bd, sn, chh, ohh]"
},
{
"cell_type": "code",
"source": "let pat1 = hasten 16 $ beat \"x,x, ,,X, ,,x, x,,x\"\nlet pat2 = hasten 8 $ beat \",,x, ,,x,\"\nlet pat3 = hasten 8 $ beat \",X,x ,X,x\"\nplay drums $\n (with bd <$> pat1)\n <|> (with sn <$> pat2)\n <|> (with hh <$> pat3)"
},
{
"cell_type": "code",
"source": "play drums $ silence"
},
{
"cell_type": "text",
"source": "Bass\n"
},
{
"cell_type": "code",
"source": "play bass $\n with <$> (fromList $ pitches \"a2 f2 c2 g2\") <*>\n (hasten 8 $ beat $ times 4 \"Xxx.Xx.x\")"
},
{
"cell_type": "code",
"source": "play bass $\n (fromList $ pitches \"a2 F2 c2 G2\") <*\n (hasten 16 $ beat $ times (4*8) $ \"x_ x_ x. xx\")"
},
{
"cell_type": "code",
"source": "play bass $ silence"
},
{
"cell_type": "text",
"source": "Pad\n"
},
{
"cell_type": "code",
"source": "play pad $ polyphony $ slow 2 $ fromList $ chords \"am G\""
},
{
"cell_type": "code",
"source": "play pad $ polyphony $ fromList $ voicelead $ chords \"am F C G\""
},
{
"cell_type": "code",
"source": "play pad $ silence"
},
{
"cell_type": "text",
"source": "Rhythm instrument\n"
},
{
"cell_type": "code",
"source": "let mychords = polyphony $ fromList $ chords \"am F C G\"\nlet rhythm = mconcat $ replicate 4 campfire\nlet pattern1 = mychords <* rhythm\nplay keys $ pattern1"
},
{
"cell_type": "code",
"source": "let pattern1 = (fromList $ chords \"am F C G\") `bind` (<$ campfire)\nplay keys $ polyphony $ pattern1"
},
{
"cell_type": "code",
"source": "play keys $ polyphony $ fromList $ chords \"am F C G\""
},
{
"cell_type": "code",
"source": "let arpeggio xs = hasten 16 $ fromList $ times 8 $ xs ++ tail (reverse xs)\nplay keys $ staccato $ (fromList $ chords \"am F C G\") `bind` arpeggio"
},
{
"cell_type": "text",
"source": "Melody\n"
},
{
"cell_type": "code",
"source": "let q1 = map (+2*octave) $ pitches \"c5 g e d c5 g a\"\nlet q2 = map (+1*octave) $ pitches \"c5 d a d a b e\"\nplay keys $ hasten 4 $ fromList q1 <|> fromList q2"
},
{
"cell_type": "code",
"source": "play keys $ silence"
},
{
"cell_type": "text",
"source": "Lead\n"
},
{
"cell_type": "code",
"source": "play lead $ hasten 8 $ fromList $ map (pitch \"a4\" +) $\n reverse minorPenta ++ minorPenta"
},
{
"cell_type": "code",
"source": "let a = [1,2,3,4,5] :: [Int]\nlet b = [6,5,6,7,6] :: [Int]\nlet c = [6,7,8,9,2,1] :: [Int]\nlet melody = map (pitch \"a4\" +) $ map (minorPenta `at`) (a ++ b ++ a ++ c)\nlet rhythm = hasten 16 $ times 2 $ beat \"x_x_ x_xx ,,,, ,,x_ x_x_ x_xx ,,,, ,,,,\"\nplay lead $ flow melody rhythm"
},
{
"cell_type": "code",
"source": "play lead $ silence"
},
{
"cell_type": "text",
"source": "Exit everything.\n"
},
{
"cell_type": "code",
"source": "dissolve ensemble"
},
{
"cell_type": "code",
"source": "show `fmap` closeMidi"
}
],
"extensions": "OverloadedStrings",
"importModules": "import Cnoidal",
"loadFiles": "src/Cnoidal.hs",
"settings": {
"packageTool": "stack",
"packagePath": "../hyper-haskell/haskell/stack.yaml",
"searchPath": "src"
}
}