Skip to content

Instantly share code, notes, and snippets.

@pelagisk
Created November 8, 2015 22:03
Show Gist options
  • Select an option

  • Save pelagisk/14580d5ffcea3cc95e8b to your computer and use it in GitHub Desktop.

Select an option

Save pelagisk/14580d5ffcea3cc95e8b to your computer and use it in GitHub Desktop.
(ns additive
(:use [overtone.live]))
;; Is it possible to schedule events "dynamically": to let
;; the score determine what is played next and _when_? This could be
;; an interesting way of doing additive rhythmical pieces:
;; The input would be some kind of pattern describing what to play
;; Also, we would provide a coll of transformations applied
;; sequentially (we could of course think of more complicated things
;; than just applying the chain: letting the structure of the coll
;; define a markov process etc.) This would be a simple way to enable
;; thinking more clearly about additive rhytm. If we could instead
;; read from an atom, changing it dynamically could lead to
;; interesting live performances.
(defn play-evol
[event player transformations]
(if (first transformations)
(let [[t f] event]
(at t (apply player [f]))
(play-evol
(apply (first transformations) [event])
player
(rest transformations)))))
(defn translation
[t t0] (+ t t0))
(defn additive-rhythm
[unit pattern]
(map #(partial translation (* unit %1)) pattern))
(defn linear-transforms
[matrices]
(map #(partial matrix-mult %1) matrices))
(defn zip-transforms
[t-transforms form-transforms]
(for [i (range (count t-transforms))]
#(identity [((nth t-transforms i) (first %1))
((nth form-transforms i) (second %1))])))
(definst beep [freq 440]
(let [src (sin-osc freq)
env (env-gen (perc 0.01 1.0) :action FREE)]
(* src env)))
(definst blop [freq 440]
(let [src (pulse freq)
env (env-gen (perc 0.01 1.0) :action FREE)]
(* src env)))
(definst pling [freq 440]
(let [src (lf-tri freq)
env (env-gen (perc 0.01 1.0) :action FREE)]
(* src env)))
(defn absval [n] (max n (- n)))
(defn linear-player-1 [vector]
(let [[[elt1] [elt2] [elt3]] vector]
(apply beep [(midi->hz (absval elt1))])
(apply blop [(midi->hz (absval elt2))])
(apply pling [(midi->hz (absval elt3))])))
(defn euler-x [t]
[[1 0 0]
[0 (Math/cos t) (- (Math/sin t))]
[0 (Math/sin t) (Math/cos t)]])
(defn euler-y [t]
[[(Math/cos t) 0 (Math/sin t)]
[0 1 0]
[(- (Math/sin t)) 0 (Math/cos t)]])
(defn euler-z [t]
[[(Math/cos t) (- (Math/sin t)) 0]
[(Math/sin t) (Math/cos t) 0]
[0 0 1]])
(def pi 3.14)
(def unit-x [[1] [0] [0]])
(def some-vec [[67] [72] [70]])
(def t-transforms-1 (additive-rhythm 400 [1 2 1 1]))
(def f-transforms-1 (linear-transforms (map euler-y [3.1 1.1 0.2 4.1])))
(def f-transforms-2 (repeat 4 identity))
(play-evol [(now) some-vec]
linear-player-1
(zip-transforms t-transforms-1 f-transforms-1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment