[Class]
pval

A specialized pattern that evaluates its data whenever next selects it in a pattern. The name stands for "pattern evaluation".

See generic pattern initializations for documentation on keyword initializations to the pattern.

Examples:

Example 1. Embed a random number selection as the second element of a pattern.

(define pat1 (new cycle :of (list 'a 
                                  (pval (between 1000 5000))
                                  'b)))
(next pat1 12)
 (a 2760 b a 3589 b a 1175 b a 1515 b)

Example 2. Changing a weighted distribution as a function of time.

(define (john-cage offset)
  ;; notes CAGE emerge out of a background of G dorian.
  (let* ((w 0)                      ; weight of CAGE
         (d (pval w))               ; eval in pattern
         (p (new random
              :of `((g3 :weight ,d) ; weight of G
                    (a3 :weight ,d) ; weight of A
                    bf3
                    (c4 :weight ,d) ; weight of C
                    d4
                    (e4 :weight ,d) ; weight of E
                    f4
                    (g4 :weight ,d) ; weight of G
                    (r :max 1 :weight .25)) ; add rests
              :for 1))
         (q (new random 
              :of (list 1/16 1/8
                        (new line :of 1/32 :for 2 )))))
    (process repeat 100
             for n = (next p)
             for r = (rhythm (next q) 65)
             for i from 0
             ;; interpolate new weight for CAGE notes.
             set w = (interp i 0 .5 90 4)
             output (new midi :time (now)
                         :duration r 
                         :keynum (transpose n offset))
             wait r)))

(events (loop for o in '(-12 0 12 24)
              collect (cage o))
        "test.mid"
        (loop for r in '(0 h w w.)
              collect (rhythm r 65)))
 "test.mid"

See also: