Skip to content
HyungSuk Ryu edited this page Mar 7, 2017 · 4 revisions
p.390
;; ClojureScript r1835 src/cljs/cljs/core.cljs line 492
(extend-type nil
  ICounted
  (-count [_] 0))
p.391 (예제 13.1)
(extend-type goog.structs.LinkedMap
  cljs.core/ICounted
  (-count [m] (.getCount m)))
p.393
(defproject joy/music "1.0.0"
     :dependencies [[org.clojure/clojure "1.8.0"]
                      [org.clojure/clojurescript "1.7.228"]])
p.394 (예제 13.3)
(select-keys x [:childern :name :form :op])
p.396 (예제 13.4)
(defproject joy/music "1.0.0"
  :dependencies [[org.clojure/clojure "1.8.0"]
                   [org.clojure/clojurescript "1.7.228"]]
  :plugins [[lein-cljsbuild "1.1.3"]]
p.397 (예제 13.6)
(defn soft-attack
  "Return a gain node that goes from silent at time <delay> up to
   <volume> in 50 milliseconds, then ramps back down to silent after
   <duration>"
  [ctx {:keys [volume delay duration]}]
  (let [node (.createGain ctx)]
    (doto (.-gain node)
      (.linearRampToValueAtTime 0 delay)
      (.linearRampToValueAtTime volume (+ delay 0.05))
      (.linearRampToValueAtTime 0 (+ delay duration)))
    node))

(defn sine-tone
  "Return an oscillator that plays starting at <delay> for <duration> seconds"
  [ctx {:keys [cent delay duration]}]
  (let [node (.createOscillator ctx)]
    (set! (-> node .-frequency .-value) 440)
    (set! (-> node .-detune .-value) (- cent 900))
    (.start node delay)
    (.stop node (+ delay duration))
    node))

(defn woo
  "Play a 'woo' sound; sounds a bit like a glass harp."
  [ctx note]
  (let [linger 1.5
        note (update-in note [:duration] * linger)]
    (-> (sine-tone ctx note)
      (connect-to (soft-attack ctx note)))))
Clone this wiki locally