< Back to IRCAM Forum

bpf-instances in lisp

Hello,
I’m trying to create a randomized bpf through a lisp function. I’m able to make instances of bpf (list for second input of bpf-lib), but I only get default bpfs, even though i try to input the random x and y points.
I had no problems creating chord-seq’s or voice’s with parameters this way. Did I make a mistake, or is there something I’m missing about bpf? I’m still using OM 6.9.
Best,
Ruben

;______________________________________________________________________________________
(defun random-bpfs-lisp (y-minmax-list points-minmax-list number-of-bpfs)
(setf y-min (first y-minmax-list))
(setf y-max (second y-minmax-list))
(setf samples-min (first points-minmax-list))
(setf samples-max (second points-minmax-list))
; To get different randoms, you must place om-random inside a loop. Using repeat-n with random gives ‘once’-mode.
(setf bpfs-random-number-of-points (loop for index from 1 to number-of-bpfs
collect(om-random samples-min samples-max ) ))
;make-a-bpf
(setf make-a-bpf(loop for number-of-points in bpfs-random-number-of-points
;collect bpfs-random-number-of-points
;random-x2y-points-n -use loop to get a different number each time
do(setf these-y-points (loop for point from 1 to number-of-points
collect (om-random y-min y-max)))
do (setf interval-for-x-points (om/ 1000(length these-y-points)))
;The x-points
do (setf these-x-points (om-round(arithm-ser 0 1000 interval-for-x-points)10) )
;Limit y to min and max
do (setf tested-y-points (loop for this-y in these-y-points
collect (if (and(om>= this-y y-min)(om<= this-y y-max))
this-y
(if (om> this-y y-max) y-max y-min)
)))
;show as lists
; collect (list tested-y-points these-x-points)
collect(make-instance 'bpf
:x-points (flat these-x-points)
:y-points (flat tested-y-points)
:decimals '10
)
))
)
;______________________________________________________________________________________

Hi Ruben.

To make an instance of a bpf in code, and fill it with points, you want to fill the instance’s 'point-list slot with “om-points”.

Here’s a simple example:

(defun random-bpf (n)  
  (mki 'bpf  
       :point-list (loop  
		      for i from 0 to n  
		      collect (om-make-point i (random 10.0)))))

Btw, using (setf … expressions to setup or modify local variables in a scope is error-prone. Have a look at the 'let macro for setting up local variables. Ie:

(defun myfunc (minmax)  
  (let ((lmin (first minmax))  
	(lmax (second minmax)))  
    (om-random lmin lmax)))

Thank you! I can see x-points and y-points can still be used to access points from a bpf. I tried to create a bpf with 10 decimals (:decimals 10 ), but 5 seem to be the maximum if I want to avoid numbers like 8.41E-4 8.43E-4 8.46E-4 8.49E-4. In the patch version I used 8 at the fourth input of bpf without this problem. Is this automatically corrected when using bpf graphically?
Ruben

I’m getting random bpf’s out now, but it seems I can’t control the range of the x and y. The inputs go from 0 to 1000 on both x and y, while the output bpf has y 0 to .01 and x stops and different points before .009. Are there some scaling possibilities with om-make-point?

`(defun random-bpfs-lisp (y-minmax-list points-minmax-list number-of-bpfs)
(setf y-min (first y-minmax-list))
(setf y-max (second y-minmax-list))
(setf samples-min (first points-minmax-list))
(setf samples-max (second points-minmax-list))
; To get different randoms, you must place om-random inside a loop. Using repeat-n with random gives ‘once’-mode.
(setf bpfs-random-number-of-points (loop for index from 1 to number-of-bpfs
collect(om-random samples-min samples-max ) ))
;make-a-bpf
(setf make-a-bpf(loop for number-of-points in bpfs-random-number-of-points
;collect bpfs-random-number-of-points
;random-x2y-points-n -use loop to get a different number each time
do(setf these-y-points (loop for point from 1 to number-of-points
collect (om-random y-min y-max)))
do (setf interval-for-x-points (om/ 1000(length these-y-points)))
;The x-points
do (setf these-x-points (om-round(arithm-ser 0 1000 interval-for-x-points)10) )
;Limit y to min and max
do (setf tested-y-points (loop for this-y in these-y-points
collect (if (and(om>= this-y y-min)(om<= this-y y-max))
this-y
(if (om> this-y y-max) y-max y-min)
)))
;show as lists
; collect (list tested-y-points these-x-points)
collect(make-instance 'bpf

                      :decimals 5   
                      :point-list (loop for x in these-x-points  
                                        for y in tested-y-points  
                                    collect (om-make-point x y)  
                                   )  
                       )           

))
)

The printing of numbers as 8.41E-4 instead of 0.000841 is just convenient when the number of digits get large. They are the same floating point number.

About the confused x- and y-points, I think in your case you should use #'simple-bpf-from-list to build your bpf. Fex:

(defun random-bpf (n)  
  (simple-bpf-from-list (loop for i from 0 to 1000 collect i)  
			(loop for i from 0 to 1000 collect (random 1000.0))  
			'bpf 10))

hi all
I confirm simple-bpf-from-list isthe way to go in this case
jean