comparison clojure/com/aurellem/run/final_cut.clj @ 599:4503899241e6

going to render the advanced choreo.
author Robert McIntyre <rlm@mit.edu>
date Sun, 02 Sep 2012 09:18:43 -0500
parents 6ce1d5fd4911
children 31128a10ee28
comparison
equal deleted inserted replaced
598:0b4ff504157d 599:4503899241e6
13 (:import com.aurellem.gb.WaveWriter)) 13 (:import com.aurellem.gb.WaveWriter))
14 14
15 15
16 (def render-dir (File. user-home "proj/vba-clojure/render/test")) 16 (def render-dir (File. user-home "proj/vba-clojure/render/test"))
17 17
18 (defn write-move-image! [move target-file]
19 (let [actual-keys (set move)
20 keys [:a :b :start :select :u :d :l :r]
21 button-on-name ["-size" "5x5" "xc:red"]
22 button-off-name ["-size" "5x5" "xc:white"]]
23 (apply
24 clojure.java.shell/sh
25 (flatten
26 ["convert"
27 "-size" "64x5" "xc:white"
28 (map
29 (fn [index]
30 (let [position ["-geometry"
31 (str "+" (* index 8)
32 "+" "0") "-composite"]]
33 (if (actual-keys (keys index))
34 [button-on-name position]
35 [button-off-name position])))
36 (range (count keys)))
37 (.getCanonicalPath target-file)]))))
38 18
39 (defn render-files! 19 (defn render-files!
40 ([^File target-dir initial-state moves] 20 ([^File target-dir
21 moves-render-fn
22 render-ram-map?
23 initial-state
24 moves
25
26 ]
41 (let [ram-map-dir (File. target-dir "ram-map") 27 (let [ram-map-dir (File. target-dir "ram-map")
42 frames-dir (File. target-dir "frames") 28 frames-dir (File. target-dir "frames")
43 moves-dir (File. target-dir "moves") 29 moves-dir (File. target-dir "moves")
44 audio-file (File. target-dir "audio.wav") 30 audio-file (File. target-dir "audio.wav")
45 _ (.mkdir target-dir) 31 _ (.mkdir target-dir)
73 av-diff (- total-audio-time 59 av-diff (- total-audio-time
74 total-video-time) 60 total-video-time)
75 write-video! 61 write-video!
76 (fn [index] 62 (fn [index]
77 ;; write screenshot 63 ;; write screenshot
78 (write-move-image! 64 (moves-render-fn
79 move 65 move
80 (File. moves-dir (format "%07d.png" index))) 66 (File. moves-dir (format "%07d.png" index)))
81 67
82 (write-png! 68 (write-png!
83 @current-state 69 @current-state
84 (File. frames-dir (format "%07d.png" index))) 70 (File. frames-dir (format "%07d.png" index)))
85 71
86 ;; write ram-image 72 ;; write ram-image
87 (write-ram-image! 73 (if render-ram-map?
88 @current-state 74 (write-ram-image!
89 (File. ram-map-dir (format "%07d.png" index))))] 75 @current-state
76 (File. ram-map-dir (format "%07d.png" index)))))]
90 ;;(println "audio-samples:" (count sound)) 77 ;;(println "audio-samples:" (count sound))
91 78
92 ;; record audio 79 ;; record audio
93 (.process wave-writer sound gb-sound-format) 80 (.process wave-writer sound gb-sound-format)
94 81
124 (render-files! (root) moves))) 111 (render-files! (root) moves)))
125 112
126 (defn file-names [#^File dir] 113 (defn file-names [#^File dir]
127 (mapv #(.getCanonicalPath %) (next (sort (file-seq dir))))) 114 (mapv #(.getCanonicalPath %) (next (sort (file-seq dir)))))
128 115
129 (defn composite-frames-command
130 [move-image screenshot ram-map target]
131 ["convert"
132 "-size" "318x276" "xc:white"
133 move-image "-geometry" "+30+225" "-composite"
134 screenshot "-geometry" "+10+10" "-composite"
135 ram-map "-geometry" "+180+10" "-composite"
136 target])
137
138 (defn generate-composite-frames!
139 [^File rendered-dir]
140 (let [final-frames (File. rendered-dir "final")
141 _ (.mkdir final-frames)
142 move-images (file-names (File. rendered-dir "moves"))
143 screenshots (file-names (File. rendered-dir "frames"))
144 ram-maps (file-names (File. rendered-dir "ram-map"))
145 targets (map #(.getCanonicalPath
146 (File. final-frames (format "%07d.bmp" %)))
147 (range (count screenshots)))]
148 (dorun
149 (map
150 (comp
151 (partial apply clojure.java.shell/sh)
152 flatten
153 (partial apply composite-frames-command)
154 (fn [a b c d] (println d) [a b c d]))
155 move-images screenshots ram-maps targets))))
156 116
157 117
158 ;; (defn final-cut! [^File render-dir] 118 ;; (defn final-cut! [^File render-dir]
159 ;; (let [movie (File. render-dir "final.ogg") 119 ;; (let [movie (File. render-dir "final.ogg")
160 ;; final-audio (File. render-dir "final.wav") 120 ;; final-audio (File. render-dir "final.wav")