Last night, trying to get my single-string synth running with Leipzig, I realized I forgot to :action FREE the synth, so after a while there are too many synths and the server becomes overloaded.
So, I'm trying to conditionally add this free-ing to the macro that creates the synth & running into my own defmacro-fu limitations. If someone can look this over and help me, I'd really appreciate it...
Instead of trying to show the whole defmacro, I think I've created a smaller snippet that shows the issue.
(defmacro mmx [n t]
`(defsynth ~n []
(let [mxxx# (map #(let [t1# (first %)
t2# ~(if t '(first ~%) '(second ~%))]
(~'* t1# t2#))
[ [100 200] [300 400] ])]
(out 0 (sin-osc mxxx#)))))this is just a made-up synth, I'm not even sure it will make a sound in the end.
The interesting bit here is the my attempt to set t2# to either "(first %)" or "(second %)" based on the macro input t. I can't seem to escape things right to get that "%" to make it through the macro expansion process. Here is the output of (macroexpand-1 '(mmx foo false)):
(defsynth
foo
[]
(let [mxxx__18010__auto__ (map
#(let
[t1__18012__auto__
(first %)
t2__18013__auto__
(second ~p1__18009#)] ;; desire this to be "(second %)]"
(*
t1__18012__auto__
t2__18013__auto__))
[[100 200] [300 400]])]
(out 0 (sin-osc mxxx__18010__auto__))))I've tried a variety of escapes and nothing seems to help...does anyone understand what I'm doing wrong here?
Thanks in advance!
--Roger
p.s. On the off chance someone wants to look at the actual code in progress, here is a gist with the code in question highlighted.
https://gist.github.com/4506057#file-stringed-clj-L78-L83