views:

20

answers:

1

I'm using a Lisp MIDI library for a small project I'm working on. Just to get started, I'm trying to write a simple MIDI file that plays middle C. However I can't seem to get this to work and can not find any documentation on how to do this sort of thing. Here is my code:

(defun make-track () 
  (list
   (make-instance 'midi:note-on-message
          :time 0
          :key 60 
          :velocity 100
          :status 0)
   (make-instance 'midi:note-off-message
          :time 128
          :key 60 :velocity 100
          :status 0)))

(defun make-tracks ()
  (list (make-track)))

(defun try-to-write-midi-file ()
  (let* ((my-midi-file (make-instance 'midi:midifile
                     :format 1
                     :tracks (make-tracks)
                     :division 25)))
    (midi:write-midi-file my-midi-file "opus.mid")))

It is creating a MIDI file but one of 0 seconds duration, which does not seem to have a middle C playing in it.

Can anyone tell me what I'm doing wrong here?

+2  A: 

David Lewis, one of the maintainers of the library, explained to me what I was doing wrong. Here is the correct code:

(defun make-track () 
  (list
   ;; The STATUS values you give to your messages gives the sequencer channel 
   ;; information but, rather than taking the channel as you'd expect to see it
   ;; (i.e. an integer between 0-15), it takes it in the form the MIDI itself 
   ;; uses, which for NOTE-ON is (+ 144 channel) and for NOTE-OFF is 
   ;; (+ 128 channel).
   (make-instance 'midi:note-on-message
          :time 0
          :key 60 
          :velocity 100
          :status 144)
   (make-instance 'midi:note-off-message
          :time 128
          :key 60 :velocity 100
          :status 128)))
Paul Reiners