1 | (use 'overtone.live)
|
2 | (use 'overtone.inst.sampled-piano)
|
3 | (require '[clojure.java.io :as io])
|
4 | (import '[java.net ServerSocket])
|
5 |
|
6 | (defn chr2int [c]
|
7 | (-> (char c)
|
8 | (str)
|
9 | (Integer.)))
|
10 |
|
11 | (defn beep [index]
|
12 | (let [my-scale (if (> index 6) (scale :C3 :major) (scale :C4 :major))
|
13 | note (nth my-scale (if (> index 6) (- index 1) index))]
|
14 | (sampled-piano :note note)))
|
15 |
|
16 |
|
17 | (defn receive
|
18 | [socket]
|
19 | (.readLine (io/reader socket)))
|
20 |
|
21 | (defn serve [port handler]
|
22 | (with-open [server-sock (ServerSocket. port)
|
23 | sock (.accept server-sock)]
|
24 | (let [msg-in (receive sock)]
|
25 | (handler (chr2int (nth (seq msg-in) 0))))))
|
26 |
|
27 |
|
28 | (while (pos? 1) (do (serve 12345 #(beep %))))
|