Avner Dorman Posted August 11, 2022 Share Posted August 11, 2022 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! Quote Link to comment Share on other sites More sharing options...
o_e Posted August 11, 2022 Share Posted August 11, 2022 span is your friend (setf num '(4 3 2)) (setf pitch '(a4 b4 c4 d4 e4)) (span pitch num) ==>(4 3 2 4 3) Quote Link to comment Share on other sites More sharing options...
Avner Dorman Posted August 11, 2022 Author Share Posted August 11, 2022 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! Quote Link to comment Share on other sites More sharing options...
opmo Posted August 11, 2022 Share Posted August 11, 2022 Imagery function with the output (what you are looking for) otherwise not possible to help. Quote Link to comment Share on other sites More sharing options...
Avner Dorman Posted August 11, 2022 Author Share Posted August 11, 2022 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! Quote Link to comment Share on other sites More sharing options...
o_e Posted August 11, 2022 Share Posted August 11, 2022 (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)) Quote Link to comment Share on other sites More sharing options...
Avner Dorman Posted August 11, 2022 Author Share Posted August 11, 2022 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! Quote Link to comment Share on other sites More sharing options...
Avner Dorman Posted August 11, 2022 Author Share Posted August 11, 2022 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))))) Quote Link to comment Share on other sites More sharing options...
Stephane Boussuge Posted August 12, 2022 Share Posted August 12, 2022 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.