Mercurial > vba-clojure
diff clojure/com/aurellem/run/final_cut.clj @ 530:8d3177d19d5f
added full recording function.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sun, 24 Jun 2012 16:47:18 -0500 |
parents | |
children | c6ad363e36f7 |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/clojure/com/aurellem/run/final_cut.clj Sun Jun 24 16:47:18 2012 -0500 1.3 @@ -0,0 +1,53 @@ 1.4 +(ns com.aurellem.run.final-cut 1.5 + (:use (com.aurellem.gb saves gb-driver util constants 1.6 + items vbm characters money 1.7 + rlm-assembly)) 1.8 + (:use (com.aurellem.run util sound music title save-corruption 1.9 + bootstrap-0 bootstrap-1 1.10 + ram-display 1.11 + )) 1.12 + (:require clojure.string) 1.13 + (:import [com.aurellem.gb.gb_driver SaveState]) 1.14 + (:import java.awt.image.BufferedImage) 1.15 + (:import java.io.File) 1.16 + (:import com.aurellem.gb.WaveWriter)) 1.17 + 1.18 + 1.19 +(def render-dir (File. user-home "proj/vba-clojure/render")) 1.20 + 1.21 +(defn render-files! 1.22 + ([^File target-dir initial-state moves] 1.23 + (let [ram-map-dir (File. target-dir "ram-map") 1.24 + frames-dir (File. target-dir "frames") 1.25 + audio-file (File. target-dir "audio.wav") 1.26 + _ (.mkdirs ram-map-dir) 1.27 + _ (.mkdirs frames-dir) 1.28 + wave-writer (WaveWriter. audio-file) 1.29 + moves (vec moves)] 1.30 + (set-state! initial-state) 1.31 + (dorun 1.32 + (map 1.33 + (fn [index] 1.34 + (run-moves @current-state (vector (moves index))) 1.35 + 1.36 + ;; record audio 1.37 + (.process wave-writer (sound-bytes) 1.38 + gb-sound-format) 1.39 + 1.40 + ;; write screenshot 1.41 + (write-png! 1.42 + @current-state 1.43 + (File. frames-dir (format "%07d.png" index))) 1.44 + 1.45 + ;; write ram-image 1.46 + (write-ram-image! 1.47 + @current-state 1.48 + (File. ram-map-dir (format "%07d.png" index)))) 1.49 + (range (count moves)))) 1.50 + (.cleanup wave-writer))) 1.51 + ([initial-state moves] 1.52 + (render-files! render-dir initial-state moves)) 1.53 + ([moves] 1.54 + (render-files! (root) moves))) 1.55 + 1.56 +