Posted July 4Jul 4 Here’s a small function I needed because I’m working with "binary counting patterns". All patterns must always have the same length (a fixed bit length determined by the largest value).(defun dec-to-bin-rhythm (ilist) (let ((span (find-max (mapcar 'length (decimal-to-binary ilist))))) (loop for i in (binary-rhythm span ilist 1 :type 1) collect (loop for x in i when (< x 0) append (gen-repeat (abs x) 0) else collect x)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; to ensure the pattern is always the same length, the bit length for all decimal-to-binary conversions is adjusted to match the largest decimal number ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (dec-to-bin-rhythm '(234234 1 23 110 )) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; binary-counting-rhythm -> counting from x to y ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setf bitseq (dec-to-bin-rhythm (gen-integer 1 145))) ;; 8-bit (omn-to-measure (make-omn :pitch '(c5) :length (gen-length bitseq '1/32) :velocity '(mf)) '(2/8)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; examples with list-plot ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (progn (setf bitseq (dec-to-bin-rhythm (gen-integer 1 79))) (length-list-plot (flatten bitseq) :join-points t :style :fill)) (progn (setf bitseq (dec-to-bin-rhythm (gen-integer 1 230 3))) ;; count with step 3 (length-list-plot (flatten bitseq) :join-points t :style :fill)) (progn (setf bitseq (dec-to-bin-rhythm (primes 50))) (length-list-plot (flatten bitseq) :join-points t :style :fill))A "Binary Counting Filter": You can also think of it (a liitle bit) like Tom Johnson’s work — the filter/binary approach generates all possible combinations etc... (defun binary-count-filter (&key (type 'pos) (n 50) minp maxp minl maxl field (rhy '1/16)) (progn (setf n-chords n) (setf pseq (dec-to-bin-rhythm (gen-integer minp maxp))) (setf lseq (dec-to-bin-rhythm (gen-integer minl maxl)));(cellular-automaton lrule n-chords linit)) (setf positions (loop for i in pseq collect (position-item 1 i))) (setf chords (if (equal type 'neg) (loop for i in positions collect (chordize (remove-duplicates (melodize (position-remove i field))))) (loop for i in positions collect (chordize (position-filter i field))))) (setf lengths (loop for i in (flatten lseq) when (= i 1) collect rhy else collect (* -1 rhy))) (make-omn :pitch chords :length lengths :velocity '(ppp)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; examples counting 1 to 123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; type: pos -> play/chordize the 1-values (binary-count-filter :type 'pos :minp 1 :maxp 123 :field (make-scale 'c4 11 :alt '(1 2 3 7)) :minl 1 :maxl 123 :rhy '1/16) ;; type: neg -> play/chordize the 0-values (binary-count-filter :type 'neg :minp 1 :maxp 123 :field (make-scale 'c4 11 :alt '(1 2 3 7)) :minl 1 :maxl 123 :rhy '1/16) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 2 more examples with counting 23 to 255 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; type: pos -> play/chordize the 1-values (binary-count-filter :type 'pos :minp 23 :maxp 255 :field (make-scale 'c4 11 :alt '(1 2 3 7)) :minl 23 :maxl 255 :rhy '1/32) ;; type: pos -> play/chordize the 0-values (binary-count-filter :type 'neg :minp 23 :maxp 255 :field (make-scale 'c4 11 :alt '(1 2 3 7)) :minl 23 :maxl 255 :rhy '1/32)
Create an account or sign in to comment