Jump to content

Featured Replies

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

Create an account or sign in to comment


Copyright © 2014-2025 Opusmodus™ Ltd. All rights reserved.
Product features, specifications, system requirements and availability are subject to change without notice.
Opusmodus, the Opusmodus logo, and other Opusmodus trademarks are either registered trademarks or trademarks of Opusmodus Ltd.
All other trademarks contained herein are the property of their respective owners.

Powered by Invision Community

Important Information

Terms of Use Privacy Policy