Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn update-spectrum [mesh]
- (s/>->> [:p] [:spectrum-data]
- #(if (and (:updated %2) (minim/playing? %1))
- (let
- [data (:data %2); (minim/get-realtime-data % 800) ;
- l-data (:left data)
- r-data (:right data)
- ; [ VARIANT-1 ]
- vertices (mapv (fn [x]
- ; (println "r = " x " len =" (count l-data))
- [(spec-x x (nth l-data x)) (spec-y x (nth r-data x)) 0]) (range 360)
- ;[(spec-x x x) (spec-y x (nth r-data x)) (/ (- x) 5)]) (range 1000)
- )
- ; [ VARIANT-2 ]
- ; f (fn [x] [(spec-x x (nth l-data x)) (spec-y x (nth r-data x)) 0])
- ; vertices (reduce (fn [c d] (into c [(spec-x d (nth l-data d)) (spec-y d (nth r-data d)) 0])) [] (range 360))
- ; _ (println vertices)
- ; [ VARIANT-3 ]
- ; max-x 360
- ; vertices (doall (loop [acc [] x 0]
- ; (if (< max-x x) acc
- ; (let
- ; [v [(spec-x x (nth l-data x)) (spec-y x (nth r-data x)) 0]]
- ; (recur (concat acc v) (+ x 1))))))
- ;; position-buffer (vb-position vertices)
- ]
- ;; (vertex-buffer! mesh position-buffer)
- (update-vertex-buffer! mesh vb-type-position vertices)
- (s/ag!! :spectrum-data (fn [_] {:updated false}))
- (start-spectrum-data-gatherer %1)))))
- (defn update-vertex-buffer! [mesh|geom vb-type lazy-data]
- (let [data (apply concat lazy-data)
- ;_ (println "data =" lazy-data)
- vb (vertex-buffer?? mesh|geom vb-type)
- nio-buffer (.getData vb)]
- (if (> (count data) (.capacity nio-buffer))
- ; if the existing buffer length is shorter than data length, re-create the buffer
- (let
- [mesh (resolve-mesh mesh|geom)
- new-buffer (create-float-buffer data)]
- (vertex-buffer! mesh vb-type 3 new-buffer))
- ; if the existing buffer length is enough for data, re-use the buffer
- (do
- (.rewind nio-buffer)
- (.updateData vb (create-float-buffer data)))))
Advertisement
Add Comment
Please, Sign In to add comment