Skip to content

Instantly share code, notes, and snippets.

@matschaffer
Created December 12, 2012 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matschaffer/4263826 to your computer and use it in GitHub Desktop.
Save matschaffer/4263826 to your computer and use it in GitHub Desktop.
(ns otexplore.core
(:use overtone.live))
(def rain (sample (freesound-path 2521)))
(rain)
(demo (sin-osc 440))
(demo (saw [220 220.5 221]))
(stop)
(def server (osc-server 44100 "osc-clj"))
()
(do
(definst basic-sin [freq 440]
(* (env-gen (perc 0.08 1) :action FREE) (sin-osc freq)))
(defn control-basic [val]
(let [val (scale-range val 0 1 50 1000)]
(ctl basic-sin :freq val)))
(defn play-note [inst note]
(inst (midi->hz note)))
(defn pad-on [action]
(fn [msg]
(if (== 1 (first (:args msg)))
(action))))
(def note-diff (Math/pow 2.0 (/ 1.0 12.0)))
(defn change-note [note steps]
(* note (Math/pow note-diff steps)))
(def hit-count (ref 0))
(def base-note (change-note 440 -16))
(def bass-sequence [[0] [3 7] [3 7]
[2] [5 9] []
[3] [7 10] [7 10]
[2] [5 9] []])
(def high-sequence [[0 36 43] [3 7 36 43] [3 7 36 43]
[2 38 45] [5 9 38 45] [ 38 45]
[3 39 46] [7 10 39 46] [7 10 39 46]
[2 38 45] [5 9 38 45] [ 38 45]])
(defn play-bass []
(let [cc (mod @hit-count 12)
notes (nth bass-sequence cc)]
(do (dosync (ref-set hit-count (inc @hit-count)))
(doall (map #(basic-sin (change-note base-note %)) notes)))))
(defn play-high []
(let [cc (mod @hit-count 12)
notes (nth high-sequence cc)]
(do (dosync (ref-set hit-count (inc @hit-count)))
(doall (map #(basic-sin (change-note base-note %)) notes)))))
(do
(osc-handle server "/2/push1" (pad-on #(play-note basic-sin 62)))
(osc-handle server "/2/push2" (pad-on #(play-note basic-sin 65)))
(osc-handle server "/2/push3" (pad-on #(play-note basic-sin 74)))
(osc-handle server "/2/push4" (pad-on #(play-note basic-sin 76)))
(osc-handle server "/2/push8" (pad-on #(play-note basic-sin 77)))
(osc-handle server "/2/push7" (pad-on #(play-note basic-sin 72)))
(osc-handle server "/2/push6" (pad-on #(play-note basic-sin 69)))
(osc-handle server "/2/push5" (pad-on #(play-note basic-sin 67)))
(osc-handle server "/2/push10" (pad-on #(play-note basic-sin 64)))
(osc-handle server "/2/push13" (pad-on #(do (play-bass))))
(osc-handle server "/2/push16" (pad-on #(dosync (ref-set hit-count 0))))))
;; (basic-sin)
;; (stop)
;; (zero-conf-on)
;; (zero-conf-off)
;; (osc-listen server (fn [msg] (println msg)) :debug)
;; (osc-rm-listener server :debug))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment