[Class]
copier

A specialized pattern that copies and repeats periods of a subpattern.

copier supports the following slot initializations:

:of pattern
Sets the pattern to be copied or repeated.
:for {number | pattern}
Specifies how may repetitions of the subpattern will constitute one period of elements returned by the copier. The total number of elements in the copier's period will equal this value times the number of elements returned by the subpattern. The default value is 1.
:repeat-for {number | pattern}
Specifies how many times each period in the subpattern will be repeated and forces the period length of the copier to remain the same as the subpattern. This initialization causes the :for initialization to be ignored.

Examples:

Example 1. The copier pattern.

(define x (new copier :of (new cycle :of '(a b c) :for 2)
                      :for 3))

(loop repeat 3 collect (next x #t))
 ((a b a b a b) (c a c a c a) (b c b c b c))

(define x (new copier :of (new cycle :of '(a b c) :for 2)
                      :repeat-for 3))

(loop repeat 9 collect (next x #t))
 ((a b) (a b) (a b) (c a) (c a) (c a) (b c) (b c) (b c))

Example 2. Repetition and randomness.

(define (wander num tmpo)
  ;; play segments of 5 notes chosen randomly between keynums
  ;; 41 and 60 with no direct repetition within each segment.
  ;; play segments 1, 3 or 5 times before selecting the next.
  (let* ((segs (new random :of (loop for i from 41 to 60
                                     collect (list i :max 1))
                           :for 5))
         (bass (new copier :of segs
                    :for (new random :of '(1 3 5))
                    :repeat num))
         (amps (new heap :of '(.6 .4 .4 .4 .4))))
    (process for k = (next bass)
             for a = (next amps)
             until (eod? k)
             output
             (new midi :time (now)
                  :keynum k
                  :duration (if (> a .5) 5 3)
                  :amplitude a)
             wait (rhythm 1/20 tmpo))))

(events (wander 20 48) "test.mid")
 "test.mid"

See also: