-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathentropy
executable file
·42 lines (33 loc) · 1006 Bytes
/
entropy
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
#!/usr/bin/env clojure
;; vim: ft=clojure
(require '[alda.core :refer :all])
(def REST-RATE 0.15)
(def MS-LOWER 30)
(def MS-UPPER 3000)
(def MAX-OCTAVE 8)
(defn random-note
"Returns a random note in a random octave with a random duration in
milliseconds.
May randomly return a rest with a random duration in milliseconds, instead."
[]
(let [ms (ms (rand-nth (range MS-LOWER MS-UPPER)))]
(if (< (rand) REST-RATE)
(pause (duration ms))
(let [o (rand-int (inc MAX-OCTAVE))
n [(keyword (str (rand-nth "abcdefg")))
(rand-nth [:sharp :flat :natural])]]
[(octave o)
(note (apply pitch n) (duration ms))]))))
(play!
(part "midi-electric-piano-1")
(panning 25)
(repeatedly 50 random-note)
(part "midi-timpani")
(panning 50)
(repeatedly 50 random-note)
(part "midi-celesta")
(panning 75)
(repeatedly 50 random-note))
(println "Press Ctrl-C to stop & exit.")
(.addShutdownHook (Runtime/getRuntime)
(Thread. #(stop!)))