o_e Posted November 4, 2016 Share Posted November 4, 2016 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 Quote Link to comment Share on other sites More sharing options...
AM Posted November 4, 2016 Share Posted November 4, 2016 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? Quote Link to comment Share on other sites More sharing options...
o_e Posted November 4, 2016 Author Share Posted November 4, 2016 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) Quote Link to comment Share on other sites More sharing options...
AM Posted November 4, 2016 Share Posted November 4, 2016 (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)) Quote Link to comment Share on other sites More sharing options...
AM Posted November 4, 2016 Share Posted November 4, 2016 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) lviklund 1 Quote Link to comment Share on other sites More sharing options...
o_e Posted November 5, 2016 Author Share Posted November 5, 2016 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 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.