[CM] Rearranging a sequence
Rick Taube
taube@uiuc.edu
Mon, 9 Apr 2007 20:55:52 -0500
you shouldnt "rearrange the time values" of the seq's objects -- the
purpose of a seq is maintain a time-ordered list of events!
assuming you want to scramble keynumbers or something like that you
could do this
;; create a seq of midis
(defparameter myseq
(new seq :subobjects (loop for i to 100
collect (new midi :time i :keynum i))))
;; look at the first ten
(list-objects myseq :end 10)
0. #i(midi time 0 keynum 0 duration 0.5 amplitude 64 channel 0)
1. #i(midi time 1 keynum 1 duration 0.5 amplitude 64 channel 0)
2. #i(midi time 2 keynum 2 duration 0.5 amplitude 64 channel 0)
3. #i(midi time 3 keynum 3 duration 0.5 amplitude 64 channel 0)
4. #i(midi time 4 keynum 4 duration 0.5 amplitude 64 channel 0)
5. #i(midi time 5 keynum 5 duration 0.5 amplitude 64 channel 0)
6. #i(midi time 6 keynum 6 duration 0.5 amplitude 64 channel 0)
7. #i(midi time 7 keynum 7 duration 0.5 amplitude 64 channel 0)
8. #i(midi time 8 keynum 8 duration 0.5 amplitude 64 channel 0)
9. #i(midi time 9 keynum 9 duration 0.5 amplitude 64 channel 0)
;; gather the keynumbers
(defparameter seqkeys
(fold-objects #'cons myseq '() :slot 'keynum))
;; now shuffle the keynums and put them back
(let ((mixedup (shuffle seqkeys)))
(loop for m in (subobjects myseq)
for k in mixedup
do (sv m :keynum k))
)
;; look at them again
(list-objects myseq :end 10)
0. #i(midi time 0 keynum 60 duration 0.5 amplitude 64 channel 0)
1. #i(midi time 1 keynum 68 duration 0.5 amplitude 64 channel 0)
2. #i(midi time 2 keynum 15 duration 0.5 amplitude 64 channel 0)
3. #i(midi time 3 keynum 51 duration 0.5 amplitude 64 channel 0)
4. #i(midi time 4 keynum 29 duration 0.5 amplitude 64 channel 0)
5. #i(midi time 5 keynum 52 duration 0.5 amplitude 64 channel 0)
6. #i(midi time 6 keynum 35 duration 0.5 amplitude 64 channel 0)
7. #i(midi time 7 keynum 74 duration 0.5 amplitude 64 channel 0)
8. #i(midi time 8 keynum 25 duration 0.5 amplitude 64 channel 0)
9. #i(midi time 9 keynum 16 duration 0.5 amplitude 64 channel 0)
CM>
On Apr 9, 2007, at 6:52 PM, Landspeedrecord wrote:
> I having been trying to rearrange the time values of a MIDI file, i.e.
> rearrange the ordering of the notes while keeping all the other MIDI
> information intact. I can load the MIDI into a seq object but from
> there I hit a brick wall.