;;; ;;; ;;; 220b: Assignment 2 ;;; ;;; ;;; Let's start by importing all events from all tracks of a midi file ;;; (http://ccrma.stanford.edu/courses/220b/cm/doc/dict/import-events-fn.html) (defparameter adagi (import-events "/zap/al_adagi.mid")) ;;; so, what is inside adagi? Type adagi in the lisp interpreter: adagi ;;; and it should respond with something like this: CM> adagi (# # # # # # # # # # # #) CM> ;;; so, adagi is a sequence that contains sequences, ;;; this is a multitrack midi file, we probably want to ;;; only read one track (to analyze it later) ;;; we can restrict the read to track #1 (track is zero based) (defparameter adagi (import-events "/zap/al_adagi.mid" :tracks 1)) ;;; adagi will now contain only the second track... CM> adagi # CM> ;;; how do we get to the notes? ;;; those are subobjects in the sequence object, we could extract ;;; them as a list: (subobjects adagi) ;;; see http://ccrma.stanford.edu/courses/220b/cm/doc/dict/subobjects-fn.html ;;; this should print a list of all subobjects, in this case midi notes ;;; we can, of course, iterate over them with loop, ;;; this will again print all events, one per line: (loop for e in (subobjects adagi) do (format t "~s~%" e)) ;;; now, we only need the key number of each event (to feed to markov), ;;; "sv" (slot value) will retrieve a given slot (:keynum in this case) ;;; from an object: (loop for e in (subobjects adagi) do (format t "~s~%" (sv e :keynum))) ;;; see: http://ccrma.stanford.edu/courses/220b/cm/doc/dict/sv-mac.html ;;; but most probably this will fail with an error! ;;; not all midi event types have a keynum slot! ;;; so we should check the object to see if it has a keynum parameter ;;; _before_ trying to access it... (loop for e in (subobjects adagi) do (format t "~s~%" ;; does the object have a keynum parameter? (if (member 'keynum (object-parameters e)) ;; yes, so access it! (sv e :keynum)))) ;;; that should have printed numbers, those are the key numbers of ;;; all the notes contained in the sequence ;;; of course instead of printing we could collect them in a list, ;;; which by coincidence is what markov-analyse needs :-) ;;; you will want to learn about "markov-analyze" here: ;;; http://ccrma.stanford.edu/courses/220b/cm/doc/dict/markov-analyze-fn.html ;;; and of course about the markov pattern class as well: ;;; http://ccrma.stanford.edu/courses/220b/cm/doc/dict/markov-cls.html