[CM] MIDI file conversion routine

taube@uiuc.edu taube@uiuc.edu
Sun, 22 Feb 2004 06:49:56 -0600


Assuming you are in Common Lisp something like this will work:

(defun map-slot (seq slot)
  (loop for x in (subobjects seq)
        when (typep x 'midi)
        collect (slot-value x slot)))

(setq myseq (import-events "whatever.midi"))
(setq list1 (map-slot data 'keynum))
(setq list2 (map-slot data 'duration))
(setq list3 (map-slot data 'amplitude))

list3 contains amplitudes 0-1 so to convert to midi velocity values you will have to multiply each number by 127:

(setq list3 (mapcar #'(lambda (x) (* x 127)) list3))




---- Original message ----
>Date: Sat, 21 Feb 2004 23:07:01 -0800 (PST)
>From: "T. Kriewall" <kriewall@u.washington.edu>  
>Subject: [CM] MIDI file conversion routine  
>To: cmdist@ccrma.Stanford.EDU
>
>
>Before I go *too* far with this...
>
>I'm looking for a Lisp routine that loads a MIDI file, in any format, even
>a MIDI file that has been converted to text, and creates from it three
>lists: the note on number of all notes played, their duration, and their
>velocity.  If one is not available, I'd like to write up a brief routine
>that does so.  This will unfortunately involve me asking some rather
>embarrassing low-level questions, although I can go quite a ways with just
>a little help.  Does anybody know of a routine that does this?
>
>Incidentally, if there's a usergroup out there for beginning Lispers,
>please let me know.  I'm at a notably lesser skill level than many on this
>list (but I'm catching up! :)
>
>Thanks,
>
>Tom K
>
>_______________________________________________
>Cmdist mailing list
>Cmdist@ccrma.stanford.edu
>http://ccrma-mail.stanford.edu/mailman/listinfo/cmdist