Jump to content

Recommended Posts

Posted

 

here is a small pure LISP-function - even older function - that I need for a project. Kind of a "shift-hysteresis", a randomized change from X to Y to ..., also possible with several value. It is best to try it out with the graph views. have fun!

andré

 

;;; SUB

(defun weighted-t/nil (on-weight)
  (let ((off-weight (- 1 on-weight)))
    (weighted-random (list (list 't on-weight) (list 'nil off-weight)))))

(defun weighted-random (list)
  (loop for item in list
    with rand-num = (random (loop for x in list sum (second x)))
    for add = (second item) then (+ add (second item))
    when (< rand-num add) return (first item)))
                               
;;; MAIN

(defun gen-hysteresis (&key number-of-values 
                                   (value-list '((0 1) (4 0) (0 1) (4 7))) 
                                   (start-weight 0.1) 
                                   (sensitivity 0.02) 
                                   (static 1.0))
  (loop repeat number-of-values
    with weight = start-weight
    with cnt1 = 0
    with cnt-v = 0
    when (equal (weighted-t/nil weight) 'nil)
    collect (first (nth cnt-v value-list)) else collect (second (nth cnt-v value-list)) and do (incf cnt1) 
    when (= cnt1 3) do (setq weight (+ weight sensitivity)
                             cnt1 0)

    when (> weight static)
    do (incf cnt-v)
    and do (setq weight start-weight)
    when (= cnt-v (length value-list)) do (setq cnt-v 0)))

 

test it:

 

(pitch-list-plot (gen-hysteresis :number-of-values 300
                :start-weight 0.1
                :sensitivity 0.05
                :value-list '((gs3 a4))
                :static 2.0)
                 :join-points t :style :fill)


(pitch-list-plot (gen-hysteresis :number-of-values 500
                :start-weight 0.1
                :sensitivity 0.05
                :value-list '((gs3 a4) (e5 ds4) (cs4 gs3))
                :static 1.5)
                 :join-points t :style :fill)



                
(list-plot (gen-hysteresis :number-of-values 500
                :start-weight 0.1
                :sensitivity 0.1
                :value-list '((1 2) (2 6) (4 3) (3 5))
                :static 2.0)
                 :join-points t :style :fill)

Bildschirmfoto2024-10-10um16_25_12.png.86f323f1c9f24182246cdb27ca2ee0e3.pngBildschirmfoto2024-10-10um16_24_15.png.2a116e511243f6d95db9f8086082c345.png

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