Created
May 3, 2012 16:31
-
-
Save neatonk/2587027 to your computer and use it in GitHub Desktop.
Using Overtone's at macro with lazy-seq's
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Lazy-seq's generated within the body of Overtone's #'at macro, don't behave as expected. | |
;; Use dorun or doseq to force evaluation. | |
;; See: https://groups.google.com/forum/?fromgroups#!topic/overtone/U7k7iKfyT5I | |
;; Define a simple inst... | |
(definst piano [n 60] | |
(let [env (env-gen (perc) :action FREE)] | |
(* env (sin-osc (midicps n))))) | |
;; Using #'for causes #'play-chord to produce a lazy-seq. | |
(defn play-chord [inst c] (for [n c] (inst n))) | |
(osc-debug) ;print osc messages to the repl. | |
;; This won't work as expected... | |
(at (+ 4000 (now)) | |
(play-chord piano (chord :A3 :major))) | |
;; osc-debug output... | |
;; #'at produces a timestamped osc bundle, but there is nothing in it. | |
;; #'play-chord produces a lazy-seq that is returned by at and realized at the repl. | |
;; osc-send-bundle: {:timestamp 1336062227242, :items []} | |
;; osc-send-msg: {:path /s_new, :type-tag siiisf, :args (piano 28 1 25 n 57.0)} | |
;; osc-send-msg: {:path /s_new, :type-tag siiisf, :args (piano 29 1 25 n 61.0)} | |
;; osc-send-msg: {:path /s_new, :type-tag siiisf, :args (piano 30 1 25 n 64.0)} | |
;; This works as expected... | |
(at (+ 4000 (now)) | |
(dorun (play-chord piano (chord :A3 :major)))) | |
;; osc-debug output... | |
;; #'at produces a timestamped osc bundle containing the osc messages produced when | |
;; the result of play chord is realized using dorun. | |
;; osc-send-bundle: | |
;; {:timestamp 1336062092605, | |
;; :items [{:path /s_new, :type-tag siiisf, :args (piano 28 1 25 n 57.0)} | |
;; {:path /s_new, :type-tag siiisf, :args (piano 29 1 25 n 61.0)} | |
;; {:path /s_new, :type-tag siiisf, :args (piano 30 1 25 n 64.0)}]} | |
;; Use #'doseq instead of #'for... | |
(defn play-chord [inst c] (doseq [n c] (inst n))) | |
;; Again, this works as expected... | |
(at (+ 4000 (now)) | |
(play-chord piano (chord :A3 :major))) | |
;; osc-send-bundle: | |
;; {:timestamp 1336062402490, | |
;; :items [{:path /s_new, :type-tag siiisf, :args (piano 28 1 25 n 57.0)} | |
;; {:path /s_new, :type-tag siiisf, :args (piano 29 1 25 n 61.0)} | |
;; {:path /s_new, :type-tag siiisf, :args (piano 30 1 25 n 64.0)}]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment