Jump to content

modify-lengths-to-rests


Recommended Posts

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; i needed a function who changes randomly lengths to rests
;;; step by step, and modify (enlarge) its rest-values over x-generations
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defun modify-lengths-to-rests (liste &key (items 1) (step -1) (factor 2) (enlarge-type 'add))
  (let ((liste (loop for j in liste
                   when (< j 0) collect (cond ((equal enlarge-type 'add)
                                               (+ step j))
                                              ((equal enlarge-type 'augmented)
                                               (* factor j)))
                   else collect j)))
    (loop 
      for i in liste
      
      with repl = (rnd-pick (remove 0 liste :test #'>))
      with cnt = 0
      when (and (equal i repl)
                (< cnt items)) 
      collect (* -1 (abs repl)) and do (incf cnt)
      else collect i)))
       

;;;; examples-1 -> ONE generation
;;;; evaluate a few times to see how it works

(modify-lengths-to-rests '(1 1 1 2 2 2 3 3 3 4 4 4 -5 5 5) 
                         :items 1
                         :enlarge-type 'add) ;enlarge only values < 0

(modify-lengths-to-rests '(1 1 1 2 2 2 3 3 3 4 4 4 -5 5 5) 
                         :items 2
                         :enlarge-type 'add) ;enlarge only values < 0

(modify-lengths-to-rests '(1 1 1 2 2 2 3 3 3 4 4 4 -5 5 5) 
                         :items 3
                         :enlarge-type 'add) ;enlarge only values < 0

;;;; examples-2 
;;;; recursiv - with x-generations

(loop repeat 10
  with seq = '(1 2 3 4 4 4 5 6 7)
  collect (setf seq (modify-lengths-to-rests seq 
                                             :items 1
                                             :enlarge-type 'augmented)))

(loop repeat 10
  with seq = '(1 2 3 4 4 4 5 6 7)
  collect (setf seq (modify-lengths-to-rests seq 
                                             :items 1
                                             :enlarge-type 'add)))

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

Terms of Use Privacy Policy