Posted August 11, 20222 yr Is there a simple way to repeat a list until it is the length of another list? Basically do the same thing that make-omn does but for other parameters. For example if I have a list of numbers '(4 3 2) and pitches '(a4 b4 c4 d4 e4), I would like to repeat the numbers until there are exactly the same number of elements in each list. Thanks!
August 11, 20222 yr span is your friend 🙂 (setf num '(4 3 2)) (setf pitch '(a4 b4 c4 d4 e4)) (span pitch num) ==>(4 3 2 4 3)
August 11, 20222 yr Author Great! Thank you!! So can you help me with this function? I basically want all three elements to be spanned into the longest of the three. How would you suggest I do this? (defun pattern-maker (chords durations repetitions) (loop :for i in chords :for j in durations :for k in repetitions :collect (make-omn :length (gen-repeat k j) :pitch (gen-repeat k i)))) Thanks!
August 11, 20222 yr Imagery function 🙂 with the output (what you are looking for) otherwise not possible to help.
August 11, 20222 yr Author Ok - So as a simple example - (setf chords '(c4e4g4 e4g4c5)) (setf durations '(q e q e s)) (setf repetitions '(7 1 6 2 5 3 4 4)) (length (span chords repetitions)) (defun pattern-maker (chords durations repetitions) (loop :for i in chords :for j in durations :for k in repetitions :collect (make-omn :length (gen-repeat k j) :pitch (gen-repeat k i)))) Would give the following I got this by running: (pattern-maker (span repetitions chords) (span repetitions durations) repetitions) Which is fine - but if "repetitions" was shorter than "chords" I would need to span everything to chords. So I guess I need a condition and define a variable that chooses the largest list of the three and span onto that list. I don't know how to do that 🙂 Many thanks!
August 11, 20222 yr (setf num '(4 3 2 2 3 4 5)) (setf pitch '(a4 b4 c4 d4 e4)) (if (< (length num) (length pitch)) pitch num) =>(4 3 2 2 3 4 5) ;;;;;; (setf num '(4 3 2)) (setf pitch '(a4 b4 c4 d4 e4)) (if (< (length num) (length pitch)) pitch num) =>(a4 b4 c4 d4 e4) hth Edit: I think you need cond to compare the length of three lists with each other: (setf durations '(q e q e s)) (setf chords '(c4e4g4 e4g4c5)) (setf repetitions '(7 1 6 2 5 3 4 4)) (cond ((> (length chords) (and (length durations) (length repetitions))) chords) ((> (length durations) (and (length chords) (length repetitions))) durations) ((> (length repetitions) (and (length chords) (length durations))) repetitions))
August 11, 20222 yr Author Yes - that last condition is exactly what I was looking for! My lisp chops are not that great.... How would you incorporate this condition into the main function 'pattern-maker'? Many thanks!
August 11, 20222 yr Author This seems to work - let me know if there's a more elegant way to do this (defun pattern-maker (chords durations repetitions) (let ((longest (cond ((> (length chords) (and (length durations) (length repetitions))) chords) ((> (length durations) (and (length chords) (length repetitions))) durations) ((> (length repetitions) (and (length chords) (length durations))) repetitions)) )) (loop :for i in (span longest chords) :for j in (span longest durations) :for k in (span longest repetitions) :collect (make-omn :length (gen-repeat k j) :pitch (gen-repeat k i)))))
August 12, 20222 yr Another possible way: (setf chords '(c4e4g4 e4g4c5)) (setf durations '(q e q e s)) (setf repetitions '(7 1 6 2 5 3 4 4)) (setf out (gen-repeat repetitions (make-omn :pitch (mclist chords) :length (gen-trim (length repetitions) (mclist durations)) ))) S.
Create an account or sign in to comment