[CM] Rearranging a sequence
Michael Klingbeil
michael@klingbeil.com
Tue, 10 Apr 2007 20:18:15 -0400
In spite of Rick's warnings, I do destructive modifications on
sequences all the time.
All you need to do is make sure that the subobjects are time sorted
after you make your modifications.
/\\\
---\\\---------
----\\\--------
----/\\\------- Common Music 2.9.1
---/--\\\------
--/----\\\-----
/ \\\/
CL-USER>
; No value
CM> (defparameter myseq
(new seq :subobjects (loop for i to 100
collect (new midi :time i :keynum i))))
MYSEQ
CM> (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)
; No value
CM> (loop for m in (subobjects myseq)
do (sv m :time (between 0 100)))
NIL
CM> (list-objects myseq :end 10)
0. #i(midi time 93 keynum 0 duration 0.5 amplitude 64 channel 0)
1. #i(midi time 92 keynum 1 duration 0.5 amplitude 64 channel 0)
2. #i(midi time 77 keynum 2 duration 0.5 amplitude 64 channel 0)
3. #i(midi time 18 keynum 3 duration 0.5 amplitude 64 channel 0)
4. #i(midi time 76 keynum 4 duration 0.5 amplitude 64 channel 0)
5. #i(midi time 20 keynum 5 duration 0.5 amplitude 64 channel 0)
6. #i(midi time 44 keynum 6 duration 0.5 amplitude 64 channel 0)
7. #i(midi time 93 keynum 7 duration 0.5 amplitude 64 channel 0)
8. #i(midi time 73 keynum 8 duration 0.5 amplitude 64 channel 0)
9. #i(midi time 30 keynum 9 duration 0.5 amplitude 64 channel 0)
; No value
CM> (setf (container-subobjects myseq)
(sort (subobjects myseq) #'< :key #'(lambda (m) (sv
m :time))))
CM> (list-objects myseq :end 10)
0. #i(midi time 0 keynum 16 duration 0.5 amplitude 64 channel 0)
1. #i(midi time 2 keynum 57 duration 0.5 amplitude 64 channel 0)
2. #i(midi time 3 keynum 12 duration 0.5 amplitude 64 channel 0)
3. #i(midi time 5 keynum 35 duration 0.5 amplitude 64 channel 0)
4. #i(midi time 7 keynum 30 duration 0.5 amplitude 64 channel 0)
5. #i(midi time 8 keynum 32 duration 0.5 amplitude 64 channel 0)
6. #i(midi time 9 keynum 11 duration 0.5 amplitude 64 channel 0)
7. #i(midi time 10 keynum 93 duration 0.5 amplitude 64 channel 0)
8. #i(midi time 11 keynum 69 duration 0.5 amplitude 64 channel 0)
9. #i(midi time 12 keynum 51 duration 0.5 amplitude 64 channel 0)
; No value
CM>
At 7:57 PM -0400 4/10/07, Landspeedrecord wrote:
>Thanks Rick! Using fold-objects in conjunction with cons would have
>taken me weeks to figure out so I appreciate your help.
>
>However, what I want to do is exactly what you are saying I shouldn't.
>The only thing I want to shuflle/reorder is the midi time. All the
>other midi information (keynum, duration, amp, chan) is supposed to
>stay together so that the notes remain the same but just come out in a
>different temporal order. Why do I want to do this? Because I am
>trying to manipulate midi files that correspond to .rex files (chopped
>up rhythms produced by propellerheads recycle). If I can rearrange the
>midi file I can come up with endless variations of the looped audio
>file.
>
>I am confused. I thought the midi "time" value was just another
>slot/keyword value of the MIDI class (i.e. the same as keynum or
>duration). I figured that it was only until the seq was put into the
>scheduler that the midi time became "cemented" in. Do I have it all
>wrong?
>
>On 4/9/07, Rick Taube <taube@uiuc.edu> wrote:
>>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.
>>
>
>_______________________________________________
>Cmdist mailing list
>Cmdist@ccrma.stanford.edu
>http://ccrma-mail.stanford.edu/mailman/listinfo/cmdist