AM Posted October 10, 2024 Posted October 10, 2024 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) Stephane Boussuge, opmo and jesele 2 1 Quote
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.