changeset 535:2de44c6184ee

refactored functionality of play-midi into midi-bytes for reuse.
author Robert McIntyre <rlm@mit.edu>
date Mon, 25 Jun 2012 14:15:38 -0500
parents 3f2072b8e457
children c2ee7222a3c4
files clojure/com/aurellem/run/choreo.clj clojure/com/aurellem/run/music.clj todo.org
diffstat 3 files changed, 49 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/run/choreo.clj	Mon Jun 25 12:45:57 2012 -0500
     1.2 +++ b/clojure/com/aurellem/run/choreo.clj	Mon Jun 25 14:15:38 2012 -0500
     1.3 @@ -9,3 +9,27 @@
     1.4    (:import java.io.File))
     1.5  
     1.6  
     1.7 +
     1.8 +;; take over game
     1.9 +;; [X] silence noise
    1.10 +;; [ ] construct writing/playing kernel
    1.11 +;; [ ] play pony song while writing picture-program
    1.12 +;; [ ] run picture program to display pinkie pie mark
    1.13 +
    1.14 +
    1.15 +
    1.16 +(defn-memo silence-noise
    1.17 +  ([] (silence-noise (launch-main-bootstrap-program)))
    1.18 +  ([script]
    1.19 +     (->> script
    1.20 +          (write-RAM 0xFF1A [0 0 0]))))
    1.21 +
    1.22 +
    1.23 +(defn-memo write-pony-music-data
    1.24 +  ([] (write-pony-music-data (silence-noise)))
    1.25 +  ([script]
    1.26 +     (->> script
    1.27 +          (write-RAM 0xA000 
    1.28 +
    1.29 +
    1.30 +
     2.1 --- a/clojure/com/aurellem/run/music.clj	Mon Jun 25 12:45:57 2012 -0500
     2.2 +++ b/clojure/com/aurellem/run/music.clj	Mon Jun 25 14:15:38 2012 -0500
     2.3 @@ -580,16 +580,15 @@
     2.4       :duty    (zipmap (map :out duty-info)
     2.5                        (map #(get % :duty 0) duty-info))}))
     2.6  
     2.7 -(defn play-midi [#^File midi-file]
     2.8 +(defn midi-bytes [^File midi-file]
     2.9    (let [voice-1-target 0xA000
    2.10          voice-2-target 0xB000
    2.11          noise-target   0xA900
    2.12          program-target 0xC000
    2.13          mini-midi (midi->mini-midi midi-file)
    2.14 -        long-silence (flatten (note-codes 20 0 20001))
    2.15 -        long-noise-silence
    2.16 -        (interleave (range 500) (repeat 0x00) (repeat 255))
    2.17 -        
    2.18 +        long-silence (flatten (note-codes 20 0 5000))
    2.19 +        long-noise-silence 
    2.20 +        (interleave (range 100) (repeat 0x00) (repeat 255))
    2.21          voice-1 (flatten (:voice-1 mini-midi))
    2.22          wave-duty-1 ((:duty mini-midi) 0 0)
    2.23  
    2.24 @@ -597,19 +596,29 @@
    2.25          wave-duty-2 ((:duty mini-midi) 1 0)
    2.26  
    2.27          noise (flatten (:noise mini-midi))
    2.28 -        ]
    2.29 +        kernel (music-kernel wave-duty-1 wave-duty-2)]
    2.30      
    2.31 +    {:voice-1 {:address voice-1-target
    2.32 +               :data  (concat voice-1 long-silence)}
    2.33 +     :voice-2 {:address voice-2-target
    2.34 +               :data (concat voice-2 long-silence)}
    2.35 +     :noise   {:address noise-target
    2.36 +               :data (concat noise long-noise-silence)}
    2.37 +     :kernel  {:address program-target
    2.38 +               :data (music-kernel wave-duty-1 wave-duty-2)}}))
    2.39 +
    2.40 +(defn play-midi [^File midi-file]
    2.41 +  (let [bytes (midi-bytes midi-file)]
    2.42      (-> (second (music-base))
    2.43 -        (set-memory-range voice-1-target long-silence)
    2.44 -        (set-memory-range voice-2-target long-silence)
    2.45 -        (set-memory-range noise-target   long-noise-silence)
    2.46 -        (set-memory-range voice-1-target voice-1)
    2.47 -        (set-memory-range voice-2-target voice-2)
    2.48 -        (set-memory-range noise-target   noise)
    2.49          (set-memory-range
    2.50 -         program-target
    2.51 -         (music-kernel wave-duty-1 wave-duty-2))
    2.52 -        (PC! program-target))))
    2.53 +         (:address (:voice-1 bytes)) (:data (:voice-1 bytes)))
    2.54 +        (set-memory-range
    2.55 +         (:address (:voice-2 bytes)) (:data (:voice-2 bytes)))
    2.56 +        (set-memory-range
    2.57 +         (:address (:noise   bytes)) (:data (:noise   bytes)))
    2.58 +        (set-memory-range
    2.59 +         (:address (:kernel  bytes)) (:data (:kernel bytes)))
    2.60 +        (PC! (:address (:kernel bytes))))))
    2.61  
    2.62  (defn test-noise []
    2.63    (let [noise-pattern
     3.1 --- a/todo.org	Mon Jun 25 12:45:57 2012 -0500
     3.2 +++ b/todo.org	Mon Jun 25 14:15:38 2012 -0500
     3.3 @@ -1,4 +1,4 @@
     3.4 -* vba-clojure [3/7]
     3.5 +* vba-clojure [3/8]
     3.6    - [X] create ram display
     3.7    - [ ] derpy hack 
     3.8    - [X] sound recording