changeset 530:8d3177d19d5f

added full recording function.
author Robert McIntyre <rlm@mit.edu>
date Sun, 24 Jun 2012 16:47:18 -0500
parents 945c7b500433
children c6ad363e36f7
files .hgignore clojure/com/aurellem/run/final_cut.clj clojure/com/aurellem/run/sound.clj
diffstat 3 files changed, 54 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/.hgignore	Sun Jun 24 14:57:15 2012 -0500
     1.2 +++ b/.hgignore	Sun Jun 24 16:47:18 2012 -0500
     1.3 @@ -17,3 +17,4 @@
     1.4  java/.ant-targets-build.xml
     1.5  html/*
     1.6  java/lib/*
     1.7 +render/*
     1.8 \ No newline at end of file
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/clojure/com/aurellem/run/final_cut.clj	Sun Jun 24 16:47:18 2012 -0500
     2.3 @@ -0,0 +1,53 @@
     2.4 +(ns com.aurellem.run.final-cut
     2.5 +  (:use (com.aurellem.gb saves gb-driver util constants
     2.6 +                         items vbm characters money
     2.7 +                         rlm-assembly))
     2.8 +  (:use (com.aurellem.run util sound music title save-corruption
     2.9 +                          bootstrap-0 bootstrap-1
    2.10 +                          ram-display
    2.11 +                          ))
    2.12 +  (:require clojure.string)
    2.13 +  (:import [com.aurellem.gb.gb_driver SaveState])
    2.14 +  (:import java.awt.image.BufferedImage)
    2.15 +  (:import java.io.File)
    2.16 +  (:import com.aurellem.gb.WaveWriter))
    2.17 +
    2.18 +
    2.19 +(def render-dir (File. user-home "proj/vba-clojure/render"))
    2.20 +
    2.21 +(defn render-files!
    2.22 +  ([^File target-dir initial-state moves]
    2.23 +     (let [ram-map-dir (File. target-dir "ram-map")
    2.24 +           frames-dir (File. target-dir "frames")
    2.25 +           audio-file (File. target-dir "audio.wav")
    2.26 +           _ (.mkdirs ram-map-dir)
    2.27 +           _ (.mkdirs frames-dir)
    2.28 +           wave-writer (WaveWriter. audio-file)
    2.29 +           moves (vec moves)]
    2.30 +       (set-state! initial-state)
    2.31 +       (dorun
    2.32 +        (map
    2.33 +         (fn [index]
    2.34 +           (run-moves @current-state (vector (moves index)))
    2.35 +
    2.36 +           ;; record audio
    2.37 +           (.process wave-writer (sound-bytes)
    2.38 +                     gb-sound-format)
    2.39 +
    2.40 +           ;; write screenshot
    2.41 +           (write-png!
    2.42 +            @current-state
    2.43 +            (File. frames-dir (format "%07d.png" index)))
    2.44 +
    2.45 +           ;; write ram-image
    2.46 +           (write-ram-image!
    2.47 +            @current-state
    2.48 +            (File. ram-map-dir (format "%07d.png" index))))
    2.49 +         (range (count moves))))
    2.50 +       (.cleanup wave-writer)))
    2.51 +  ([initial-state moves]
    2.52 +     (render-files! render-dir initial-state moves))
    2.53 +  ([moves]
    2.54 +     (render-files! (root) moves)))
    2.55 +                           
    2.56 +
     3.1 --- a/clojure/com/aurellem/run/sound.clj	Sun Jun 24 14:57:15 2012 -0500
     3.2 +++ b/clojure/com/aurellem/run/sound.clj	Sun Jun 24 16:47:18 2012 -0500
     3.3 @@ -8,7 +8,6 @@
     3.4    (:import [com.aurellem.gb.gb_driver SaveState])
     3.5    (:import java.awt.image.BufferedImage)
     3.6    (:import java.io.File)
     3.7 -
     3.8    (:import com.aurellem.gb.WaveWriter))
     3.9  
    3.10  (defn sound-test []