comparison 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
comparison
equal deleted inserted replaced
462:32375de697e5 463:3e74bf517d8f
480 (note-codes (:frequency note-event) 480 (note-codes (:frequency note-event)
481 (:volume note-event) 481 (:volume note-event)
482 (int (* (:duration note-event) 0x100)))) 482 (int (* (:duration note-event) 0x100))))
483 notes-with-silence))) 483 notes-with-silence)))
484 484
485
486 (defn midi->mini-midi [#^File midi-file] 485 (defn midi->mini-midi [#^File midi-file]
487 (let [targets (target-tracks midi-file) 486 (let [targets (target-tracks midi-file)
488 get-track (fn [n] 487 get-track (fn [n]
489 (if (not (nil? n)) 488 (if (not (nil? n))
490 (midi-track->mini-midi midi-file n) 489 (midi-track->mini-midi midi-file n)
491 []))] 490 []))
491 duty-info (keys (track-info midi-file))]
492
492 {:voice-1 (get-track (nth targets 0)) 493 {:voice-1 (get-track (nth targets 0))
493 :voice-2 (get-track (nth targets 1)) 494 :voice-2 (get-track (nth targets 1))
494 :noise (get-track (nth targets 2))})) 495 :noise (get-track (nth targets 2))
495 496 :duty (zipmap (map :out duty-info)
496 ;; {:track-1 (flatten (midi-track->mini-midi midi-file 0)) 497 (map :duty duty-info))}))
497 ;; :track-2 (flatten (midi-track->mini-midi midi-file 1))})
498
499
500
501
502
503 (defn wave-duty
504 "get desired wave-duty from the file for the particular channel."
505 [#^File midi-file channel]
506
507
508 )
509
510 498
511 (defn play-midi [#^File midi-file] 499 (defn play-midi [#^File midi-file]
512 (let [track-1-target 0xA000 500 (let [track-1-target 0xA000
513 track-2-target 0xB000 501 track-2-target 0xB000
514 program-target 0xC000 502 program-target 0xC000
515 mini-midi (midi->mini-midi midi-file) 503 mini-midi (midi->mini-midi midi-file)
516 long-silence (flatten (note-codes 20 0 9001)) 504 long-silence (flatten (note-codes 20 0 9001))
517 wave-duty-1 2 505
518 wave-duty-2 3 506 voice-1 (flatten (:voice-1 mini-midi))
507 wave-duty-1 ((:duty mini-midi) 0)
508
509 voice-2 (flatten (:voice-2 mini-midi))
510 wave-duty-2 ((:duty mini-midi) 1)
519 ] 511 ]
520 512
521 (-> (second (music-base)) 513 (-> (second (music-base))
522 (set-memory-range track-1-target long-silence) 514 (set-memory-range track-1-target long-silence)
523 (set-memory-range track-2-target long-silence) 515 (set-memory-range track-2-target long-silence)
524 (set-memory-range track-1-target (flatten (:voice-1 mini-midi))) 516 (set-memory-range track-1-target voice-1)
525 (set-memory-range track-2-target (flatten (:voice-2 mini-midi))) 517 (set-memory-range track-2-target voice-2)
526 (set-memory-range 518 (set-memory-range
527 program-target 519 program-target
528 (music-kernel wave-duty-1 wave-duty-2)) 520 (music-kernel wave-duty-1 wave-duty-2))
529 (PC! program-target)))) 521 (PC! program-target))))
530 522