SHOW:
|
|
- or go back to the newest paste.
| 1 | (defn update-spectrum [mesh] | |
| 2 | (s/>->> [:p] [:spectrum-data] | |
| 3 | #(if (and (:updated %2) (minim/playing? %1)) | |
| 4 | (let | |
| 5 | [data (:data %2) | |
| 6 | l-data (:left data) | |
| 7 | r-data (:right data) | |
| 8 | - | vertices (persistent! (reduce (fn [c d] (conj! c (spec-x d (nth l-data d)) (spec-y d (nth r-data d)) 0)) (transient []) (range 360))) |
| 8 | + | vertices (persistent! (reduce (fn [c d] (-> c (conj! (spec-x d (nth l-data d))) (conj! (spec-y d (nth r-data d))) (conj! 0))) (transient []) (range 360))) |
| 9 | ] | |
| 10 | (update-vertex-buffer! mesh vb-type-position vertices) | |
| 11 | (s/ag!! :spectrum-data (fn [_] {:updated false}))
| |
| 12 | (start-spectrum-data-gatherer %1))))) | |
| 13 | ||
| 14 | ||
| 15 | (defn update-vertex-buffer! [mesh|geom vb-type lazy-data] | |
| 16 | (let [data (apply concat lazy-data) | |
| 17 | ;_ (println "data =" lazy-data) | |
| 18 | vb (vertex-buffer?? mesh|geom vb-type) | |
| 19 | nio-buffer (.getData vb)] | |
| 20 | (if (> (count data) (.capacity nio-buffer)) | |
| 21 | ; if the existing buffer length is shorter than data length, re-create the buffer | |
| 22 | (let | |
| 23 | [mesh (resolve-mesh mesh|geom) | |
| 24 | new-buffer (create-float-buffer data)] | |
| 25 | (vertex-buffer! mesh vb-type 3 new-buffer)) | |
| 26 | ; if the existing buffer length is enough for data, re-use the buffer | |
| 27 | (do | |
| 28 | (.rewind nio-buffer) | |
| 29 | (.updateData vb (create-float-buffer data))))) |