Jump to content

Featured Replies

Posted

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!

span is your friend 🙂

 

(setf num '(4 3 2)) 
 (setf pitch '(a4 b4 c4 d4 e4))

(span pitch num)
==>(4 3 2 4 3)

 

  • 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!

  • 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 

 

image.thumb.png.73e59fca162164422aa901588dce0a2d.png

 

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!

 

(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))

 

  • 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!

  • 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)))))
 

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


Copyright © 2014-2025 Opusmodus™ Ltd. All rights reserved.
Product features, specifications, system requirements and availability are subject to change without notice.
Opusmodus, the Opusmodus logo, and other Opusmodus trademarks are either registered trademarks or trademarks of Opusmodus Ltd.
All other trademarks contained herein are the property of their respective owners.

Powered by Invision Community

Important Information

Terms of Use Privacy Policy