Mercurial > vba-clojure
diff clojure/com/aurellem/run/music.clj @ 463:3e74bf517d8f
enabled duty-selection via title information in the midi file.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 04 May 2012 03:45:04 -0500 |
parents | 32375de697e5 |
children | 413c66186baa |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/run/music.clj Fri May 04 03:34:32 2012 -0500 1.2 +++ b/clojure/com/aurellem/run/music.clj Fri May 04 03:45:04 2012 -0500 1.3 @@ -482,31 +482,19 @@ 1.4 (int (* (:duration note-event) 0x100)))) 1.5 notes-with-silence))) 1.6 1.7 - 1.8 (defn midi->mini-midi [#^File midi-file] 1.9 (let [targets (target-tracks midi-file) 1.10 get-track (fn [n] 1.11 (if (not (nil? n)) 1.12 (midi-track->mini-midi midi-file n) 1.13 - []))] 1.14 + [])) 1.15 + duty-info (keys (track-info midi-file))] 1.16 + 1.17 {:voice-1 (get-track (nth targets 0)) 1.18 :voice-2 (get-track (nth targets 1)) 1.19 - :noise (get-track (nth targets 2))})) 1.20 - 1.21 - ;; {:track-1 (flatten (midi-track->mini-midi midi-file 0)) 1.22 - ;; :track-2 (flatten (midi-track->mini-midi midi-file 1))}) 1.23 - 1.24 - 1.25 - 1.26 - 1.27 - 1.28 -(defn wave-duty 1.29 - "get desired wave-duty from the file for the particular channel." 1.30 - [#^File midi-file channel] 1.31 - 1.32 - 1.33 - ) 1.34 - 1.35 + :noise (get-track (nth targets 2)) 1.36 + :duty (zipmap (map :out duty-info) 1.37 + (map :duty duty-info))})) 1.38 1.39 (defn play-midi [#^File midi-file] 1.40 (let [track-1-target 0xA000 1.41 @@ -514,15 +502,19 @@ 1.42 program-target 0xC000 1.43 mini-midi (midi->mini-midi midi-file) 1.44 long-silence (flatten (note-codes 20 0 9001)) 1.45 - wave-duty-1 2 1.46 - wave-duty-2 3 1.47 + 1.48 + voice-1 (flatten (:voice-1 mini-midi)) 1.49 + wave-duty-1 ((:duty mini-midi) 0) 1.50 + 1.51 + voice-2 (flatten (:voice-2 mini-midi)) 1.52 + wave-duty-2 ((:duty mini-midi) 1) 1.53 ] 1.54 1.55 (-> (second (music-base)) 1.56 (set-memory-range track-1-target long-silence) 1.57 (set-memory-range track-2-target long-silence) 1.58 - (set-memory-range track-1-target (flatten (:voice-1 mini-midi))) 1.59 - (set-memory-range track-2-target (flatten (:voice-2 mini-midi))) 1.60 + (set-memory-range track-1-target voice-1) 1.61 + (set-memory-range track-2-target voice-2) 1.62 (set-memory-range 1.63 program-target 1.64 (music-kernel wave-duty-1 wave-duty-2))