Guest User

Untitled

a guest
May 22nd, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn update-spectrum [mesh]
  2.   (s/>->> [:p] [:spectrum-data]
  3.        #(if (and (:updated %2) (minim/playing? %1))
  4.           (let
  5.             [data (:data %2); (minim/get-realtime-data % 800) ;
  6.              l-data (:left data)
  7.              r-data (:right data)
  8.              ; [ VARIANT-1 ]
  9.              vertices (mapv (fn [x]
  10.                              ; (println "r = " x " len =" (count l-data))
  11.                              [(spec-x x (nth l-data x)) (spec-y x (nth r-data x)) 0]) (range 360)
  12.                            ;[(spec-x x x) (spec-y x (nth r-data x)) (/ (- x) 5)]) (range 1000)
  13.                            )
  14.              ; [ VARIANT-2 ]
  15. ;             f (fn [x]  [(spec-x x (nth l-data x)) (spec-y x (nth r-data x)) 0])
  16. ;             vertices (reduce (fn [c d] (into c [(spec-x d (nth l-data d)) (spec-y d (nth r-data d)) 0])) [] (range 360))
  17.             ; _ (println vertices)
  18.              ; [ VARIANT-3 ]
  19. ;            max-x 360
  20. ;            vertices (doall (loop [acc [] x 0]
  21. ;                       (if (< max-x x) acc
  22. ;                         (let
  23. ;                           [v [(spec-x x (nth l-data x)) (spec-y x (nth r-data x)) 0]]
  24. ;                           (recur (concat acc v) (+ x 1))))))
  25.         ;;   position-buffer (vb-position vertices)
  26.  
  27.              ]
  28.         ;;    (vertex-buffer! mesh position-buffer)
  29.           (update-vertex-buffer! mesh vb-type-position vertices)
  30.             (s/ag!! :spectrum-data (fn [_] {:updated false}))
  31.             (start-spectrum-data-gatherer %1)))))
  32.  
  33.  
  34. (defn update-vertex-buffer! [mesh|geom vb-type lazy-data]
  35.   (let [data (apply concat lazy-data)
  36.         ;_ (println "data =" lazy-data)
  37.         vb (vertex-buffer?? mesh|geom vb-type)
  38.         nio-buffer (.getData vb)]
  39.     (if (> (count data) (.capacity nio-buffer))
  40.       ; if the existing buffer length is shorter than data length, re-create the buffer
  41.       (let
  42.         [mesh (resolve-mesh mesh|geom)
  43.          new-buffer (create-float-buffer data)]
  44.         (vertex-buffer! mesh vb-type 3 new-buffer))
  45.       ; if the existing buffer length is enough for data, re-use the buffer
  46.       (do
  47.         (.rewind nio-buffer)
  48.         (.updateData vb (create-float-buffer data)))))
Advertisement
Add Comment
Please, Sign In to add comment