 (defn oscillator [type freq duration]
   (fn [at context]
     (doto (.createOscillator context)
-      (-> .-frequency .-value (set! freq))
+      (-> .-frequency (plug freq at context))
       (-> .-type (set! type))
       (.start at)
       (.stop (+ at duration)))))

(def saw (partial oscillator "sawtooth"))
(def square (partial oscillator "square"))

(defn modulator [freq duration]
  (fn [at context]
    (let [modulatee (saw freq duration)
          carrier (>> (sin-osc 2 duration) (gain freq))]
      ((connect carrier (.-frequency modulatee)) at context)
      modulatee)))

(defn biquad-filter [type freq]
  (fn [at context]
    (doto (.createBiquadFilter context)
      (-> .-frequency .-value (set! freq))
      (-> .-type (set! type)))))

(def lpf (partial biquad-filter "lowpass"))

(ns klangmeister.instruments)

(defn run [ugen at context]
  (ugen at context))

(defn plug [param input at context]
  "Plug an input into an audio parameter,
  accepting both numbers and ugens."
  (if (fn? input)
    (.connect (input at context) param)
    (.setValueAtTime param input at)))

(defn gain [level]
  (fn [at context]
    (doto (.createGain context)
      (-> .-gain (plug level at context)))))

(defn line
  "Build a line out of [dx y] coordinates, starting at [0 0]."
  [& corners]
  (fn [at context]
    (let [node (.createGain context)
