[CM] Parsing MIDI files with CM

Ralf Mattes rm@seid-online.de
Sun, 03 Jun 2007 17:51:03 +0200


On Sun, 2007-06-03 at 08:11 -0700, David Kamp wrote:
> Hi.
> I am trying desperately to import midi events to lists but all examples in
> CM dictionary and the various ways of doing it mentioned in mails on this
> list (as well as the one quoted below) dont seem to work for me. I am
> working in guile and all i get  is an empty list. Does this work differently
> in guile than in regular lisp? 

Haven't done serious stuff in Guile for quite a while but a quick test
here seems to show that everything works fine ...

guile> (version )
"1.8.1"
guile> (define midi-stream (import-events "/home/ralf/RedCap.mid"))
guile> midi-stream
#<seq "RedCap-track-0">

guile> (map-objects (lambda (n) (format true "Event ~A\n" n))
midi-stream)
Event #i(midi-text-event time 0 type 3 text "RedCap.ume via MM/1 OS-9
UltiMusE-K.")
Event #i(midi-text-event time 0 type 1 text "Simple  circus organ march
from April 2000")
Event #i(midi-text-event time 0 type 1 text "March of the Red-Capped
Penguins")
Event #i(midi-text-event time 0 type 1 text "First two strains finished
10/8/2001")
Event #i(midi-text-event time 0 type 1 text "Dedicated to the LINUX
community.")
Event #i(midi-text-event time 0 type 1 text "Or sing to \"Bomb the
Taliban\" :-)")
Event #i(midi-text-event time 0 type 4 text "Patch085=Voice Lead")
Event #i(midi-text-event time 0 type 4 text "Patch057=Trombone")
Event #i(midi-text-event time 0 type 4 text "Patch082=Calliope")
Event #i(midi-text-event time 0 type 4 text "Patch063=Syn Brass Mello")
Event #i(midi-text-event time 0 type 4 text "Patch073=Flute")
Event #i(midi-text-event time 0 type 4 text "Patch062=Syn Brass Brite")
Event #i(midi-text-event time 0 type 4 text "Patch071=Clarinet")
Event #i(midi-text-event time 0 type 4 text "Patch058=Tuba")
Event #i(midi-key-signature time 0 key 255 mode 0)
Event #i(midi-time-signature time 0 numerator 2 denominator 4 clocks 24
32nds 8)
Event #i(midi-tempo-change time 0 usecs 545454)
Event #i(midi-program-change time 0 channel 0 program 62)
Event #i(midi-program-change time 0 channel 3 program 63)
Event #i(midi-program-change time 0 channel 2 program 57)
Event #i(midi-program-change time 0 channel 4 program 58)
Event #i(midi-program-change time 0 channel 1 program 82)
Event #i(midi-program-change time 1.090908 channel 1 program 82)
Event #i(midi time 1.090908 keynum 81 duration 1.29545325 amplitude
0.779527559055118 channel 0)
Event #i(midi time 1.090908 keynum 72 duration 1.29545325 amplitude
0.779527559055118 channel 0)
Event #i(midi time 1.090908 keynum 65 duration 0.74999925 amplitude
0.779527559055118 channel 2)
Event #i(midi time 1.090908 keynum 53 duration 0.272727 amplitude
0.669291338582677 channel 3)
 ....

> I want to collect keynums durations and amplitudes of a midifile in a list,
> modify them and spit them back out, just like you wrote below.
My first guess: you somehow broke the cristals in your warp-speed-transmogrifier :-)
First rule of question posting to a ML: show us what you've done so far
and tell us WHAT WENT WRONG.


> thanks a lot.
> 
> 
> 
> Rick Taube wrote:
> > 
> > 
> > to collect lists of things, you map the objects rather than a slot and 
> > return what you want:
> > 
> > 	(fold-objects (lambda (x l) (cons (list (sv x :time) (sv x :keynum)) 
> > l)) s1 '() :class 'midi)
> > 
> > 	=> ((18.0 77) (17.875 77) (17.75 77) (17.75 89) (17.625 75) (17.625 
> > 86) ...)

Note: this code will only work for sequences that contain midi note
events - calling slot-value :keynum on a <midi-text-event> will throw
yoiu into guile' debugger.


HTH Ralf Mattes

 
> > 
>