Jump to content

Featured Replies

Posted

Hi, I'am looking for a method to pick more and more elements from a list (that are more or less equally distributed):

 

(1/4 -1/4 1/4 -3/8 1/4 -1/4 1/4 -3/8)
(1   0    1   0    1   0    1   0   )
1.pass--> (-1/4 -1/4 -1/4 -3/8 1/4 -1/4 -1/4 -3/8)
          
          (0    0    0    0    1   0    0    0   )
2.pass--> (-1/4 -1/4 1/4 -3/8 -1/4 -1/4 1/4 -3/8)
           
          (0    0    1   0    0   0     1   0   )
3.pass--> (1/4 -1/4 -1/4 -3/8 1/4 -1/4 1/4 -3/8)
          
          (1   0    0    0    1   0    1   0   )
4.--> see orginal list

thanks for any hints

best

ole

sorry, but i don't understand what you are looking for...

 

you want to pick all elements > 0?

or change rests into lengths and lengths into rests? like a kind of a filter?

 

 

  • Author

Thank you for the quick reply!

My material is this pattern:

(1/4 -1/4 1/4 -3/8 1/4 -1/4 1/4 -3/8)

now I want to create  all variations of this pattern ranging from one beat:

(-1/4 -1/4 -1/4 -3/8 1/4 -1/4 -1/4 -3/8)
          
(0    0    0    0    1   0    0    0   )

to four beats (orginal pattern)

 

(progn

  ;; your list with EVEN-length!!! (necessary for length/rest-structure) -> starting with all values as rests
  (setf seq '(-1/4 -1/4 -1/4 -3/8 -1/4 -1/4 -1/4 -3/8)) 

  ;; produces all combinations of 0/1 with length of (/ (length seq) 2) => the number of your ON/OFF-vals (switching values, not the rests!) 
  (setf all-basic-binary-combinations (loop for i from 0 to (binary-to-decimal (loop repeat (/ (length seq) 2) collect 1))
                                        with val = '()
                                        do (setf val (decimal-to-binary i))
                                        collect (append (loop repeat (- (/ (length seq) 2) (length val))
                                                          collect 0) ;; necessary "to fill" the seq-length
                                                        val)))

  ;; combines the 1/0-list with 0 (for the unchanging rests)
  (setf binary-seq-completed (loop for x in all-basic-binary-combinations
                               collect (loop for y in x
                                         append (list y 0))))

  ;; maps the "binary-seq-completed" on your values
  (loop for k in binary-seq-completed
    collect (loop 
              for l in k
              for value in seq
              when (= l 1)
              collect (abs value)
              else collect value)))

...is perhaps a way to get the output?

...evaluate...

...or press CMD2 -> so you see the rhythm-structure...

 

...in this version the gen-structure is based on the "BINARY-incf", if you want a RND-version, just "RND-ORDER" the list...

packed in a function:

 

 
(defun all-variants (seq)

  (let ((all-basic-binary-combinations)
        (binary-seq-completed))

    ;; produces all combinations of 0/1 with length of (/ (length seq) 2) => your ON/OFF (switching values) 
    (setf all-basic-binary-combinations (loop for i from 0 to (binary-to-decimal (loop repeat (/ (length seq) 2) collect 1))
                                          with val = '()
                                          do (setf val (decimal-to-binary i))
                                          collect (append (loop repeat (- (/ (length seq) 2) (length val))
                                                            collect 0)
                                                          val)))
    
    ;; combines the 1/0-list with 0 (for the unchanging rests)
    (setf binary-seq-completed (loop for x in all-basic-binary-combinations
                                 collect (loop for y in x
                                           append (list y 0))))
    
    ;; maps the "binary-seq-completed" on your values
    (loop for k in binary-seq-completed
      collect (loop 
                for l in k
                for value in seq
                when (= l 1)
                collect (abs value)
                else collect value))))


(all-variants '(-1/4 -1/4 -1/4 -3/8 -1/4 -1/4 -1/4 -3/8))

 

ALL-VARIANTS2

**********************

 

"extended version" -> if you want to have pairs of rest/length or if EVERY value could be changed

 

(defun all-variants2 (seq &key (length/rest 'nil)) 

  (let ((all-basic-binary-combinations)
        (binary-seq-completed))

    ;;;decides if should work with pairs of length/rests
    (if (equal length/rest 't)
      ;; produces all combinations of 0/1 with length of (/ (length seq) 2) => your ON/OFF (switching values) 
      (progn
        (setf all-basic-binary-combinations (loop for i from 0 to (binary-to-decimal (loop repeat (/ (length seq) 2) collect 1))
                                              with val = '()
                                              do (setf val (decimal-to-binary i))
                                              collect (append (loop repeat (- (/ (length seq) 2) (length val))
                                                                collect 0)
                                                              val)))
        
        ;; combines the 1/0-list with 0 (for the unchanging rests)
        (setf binary-seq-completed (loop for x in all-basic-binary-combinations
                                     collect (loop for y in x
                                               append (list y 0)))))

      ;;;EVERY val will be switched 
      (setf binary-seq-completed (loop for i from 0 to (binary-to-decimal (loop repeat (length seq) collect 1))
                                              with val = '()
                                              do (setf val (decimal-to-binary i))
                                              collect (append (loop repeat (- (length seq) (length val))
                                                                collect 0)
                                                              val))))
        
    ;; maps the "binary-seq-completed" on your values
    (loop for k in binary-seq-completed
      collect (loop 
                for l in k
                for value in seq
                when (= l 1)
                collect (abs value)
                else collect value))))


(all-variants2 '(-1/4 -1/4 -1/4 -3/8 -1/4 -1/4) :length/rest 't)
(all-variants2 '(-1/4 -1/4 -1/4 -3/8 -1/4 -1/4) :length/rest 'nil)

 

  • Author

Thank you so much for your bunch of solutions! I'll have to chew a while examine them, than I'll get back..

best

ole

 

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