-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHaskoreExamples.lhs
More file actions
212 lines (154 loc) · 6.21 KB
/
HaskoreExamples.lhs
File metadata and controls
212 lines (154 loc) · 6.21 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
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
\section{Examples of Haskore in Action}
\label{examples}
{\small\begin{verbatim}
> module HaskoreExamples (module HaskoreExamples, module Haskore, module IO,
> module ChildSong6, module SelfSim)
> where
>
> import Haskore
> import IO
> import ChildSong6
> import SelfSim
> import Ssf
Simple examples of Haskore in action. Note that this module also
imports modules ChildSong6, SelfSim, and Ssf.
-----------------------------------------------------------------------------
From the tutorial, try things such as pr12, cMajArp, cMajChd, etc. and
try applying inversions, retrogrades, etc. on the same examples. Also
try "childSong6" imported from module ChildSong. For example:
> t0 = test (Instr "piano" childSong6)
-----------------------------------------------------------------------------
C Major scale for use in examples below:
> cMajScale = Tempo 2
> (line [c 4 en [], d 4 en [], e 4 en [], f 4 en [],
> g 4 en [], a 4 en [], b 4 en [], c 5 en []])
>
> cms' = line [c 4 en [], d 4 en [], e 4 en [], f 4 en [],
> g 4 en [], a 4 en [], b 4 en [], c 5 en []]
>
> cms = cMajScale
Test of various articulations and dynamics:
> t1 = test (Instr "percussion"
> (Phrase [Art (Staccato 0.1)] cms :+:
> cms :+:
> Phrase [Art (Legato 1.1)] cms ))
>
> temp = Instr "piano" (Phrase [Dyn (Crescendo 4.0)] (c 4 en []))
>
> mu2 = Instr "vibes"
> (Phrase [Dyn (Diminuendo 0.75)] cms :+:
> Phrase [Dyn (Crescendo 4.0), Dyn (Loudness 25)] cms)
> t2 = test mu2
>
> t3 = test (Instr "flute"
> (Phrase [Dyn (Accelerando 0.3)] cms :+:
> Phrase [Dyn (Ritardando 0.6)] cms ))
-----------------------------------------------------------------------------
A function to recursively apply transformations f (to elements in a
sequence) and g (to accumulated phrases):
> rep :: (Music -> Music) -> (Music -> Music) -> Int -> Music -> Music
> rep f g 0 m = Rest 0
> rep f g n m = m :=: g (rep f g (n-1) (f m))
An example using "rep" three times, recursively, to create a "cascade"
of sounds.
> run = rep (Trans 5) (delay tn) 8 (c 4 tn [])
> cascade = rep (Trans 4) (delay en) 8 run
> cascades = rep id (delay sn) 2 cascade
> t4' x = test (Instr "piano" x)
> t4 = test (Instr "piano"
> (cascades :+: revM cascades))
What happens if we simply reverse the f and g arguments?
> run' = rep (delay tn) (Trans 5) 4 (c 4 tn [])
> cascade' = rep (delay en) (Trans 4) 6 run'
> cascades' = rep (delay sn) id 2 cascade'
> t5 = test (Instr "piano" cascades')
-----------------------------------------------------------------------------
Example from the SelfSim module.
> t10s = test (rep (delay durss) (Trans 4) 2 ss)
-----------------------------------------------------------------------------
Example from the ChildSong6 module.
> cs6 = test childSong6
-----------------------------------------------------------------------------
Example from the Ssf (Stars and Stripes Forever) module.
> ssf0 = test ssf
-----------------------------------------------------------------------------
Midi percussion test. Plays all "notes" in a range. (Requires adding
an instrument for percussion to the UserPatchMap.)
> drums a b = Instr "drums"
> (line (map (\p-> Note (pitch p) sn []) [a..b]))
> t11 a b = test (drums a b)
-----------------------------------------------------------------------------
Test of cut and shorten.
> t12 = test (cut 4 childSong6)
> t12a = test (cms /=: childSong6)
-----------------------------------------------------------------------------
Tests of the trill functions.
> t13note = (Note (C,5) qn [])
> t13 = test (trill 1 sn t13note)
> t13a = test (trill' 2 dqn t13note)
> t13b = test (trilln 1 5 t13note)
> t13c = test (trilln' 3 7 t13note)
> t13d = test (roll tn t13note)
> t13e = test (Tempo (2/3) (Trans 2 (Instr "piano" (trilln' 2 7 t13note))))
-----------------------------------------------------------------------------
Tests of drum.
> t14 = test (Instr "Drums" (perc AcousticSnare qn []))
> -- a "funk groove"
> t14b = let p1 = perc LowTom qn []
> p2 = perc AcousticSnare en []
> in test (Tempo 3 (Instr "Drums" (cut 8 (repeatM
> ((p1 :+: qnr :+: p2 :+: qnr :+: p2 :+:
> p1 :+: p1 :+: qnr :+: p2 :+: enr)
> :=: roll en (perc ClosedHiHat 2 []))))))
> -- a "jazz groove"
> t14c = let p1 = perc CrashCymbal2 qn []
> p2 = perc AcousticSnare en []
> p3 = perc LowTom qn []
> in test (Tempo 3 (Instr "Drums" (cut 4 (repeatM
> ((p1 :+: Tempo (3%2) (p2 :+: enr :+: p2))
> :=: (p3 :+: qnr)) ))))
> t14d = let p1 = perc LowTom en []
> p2 = perc AcousticSnare hn []
> in test (Instr "Drums"
> ( roll tn p1
> :+: p1
> :+: p1
> :+: Rest en
> :+: roll tn p1
> :+: p1
> :+: p1
> :+: Rest qn
> :+: roll tn p2
> :+: p1
> :+: p1 ))
-----------------------------------------------------------------------------
Tests of the MIDI interface.
Music into a MIDI file.
> tab m = do
> outputMidiFile "test.mid" $ makeMidi (m, defCon, defUpm)
Music to a MidiFile datatype and back to Music.
> tad m = readMidi (testMidi m)
A MIDI file to a MidiFile datatype and back to a MIDI file.
> tcb file = do
> x <- loadMidiFile file
> outputMidiFile "test.mid" x
MIDI file to MidiFile datatype.
> tc file = do
> x <- loadMidiFile file
> print x
MIDI file to Music, a UserPatchMap, and a Context.
> tcd file = do
> x <- loadMidiFile file
> print $ fst3 $ readMidi x
> print $ snd3 $ readMidi x
> print $ thd3 $ readMidi x
A MIDI file to Music and back to a MIDI file.
> tcdab file = do
> x <- loadMidiFile file
> outputMidiFile "test.mid" $ makeMidi $ readMidi x
> getTracks (MidiFile _ _ trks) = trks
>
> fst3 (a,b,c) = a
> snd3 (a,b,c) = b
> thd3 (a,b,c) = c
\end{verbatim} }