[CM] improved patterns

Rick Taube taube@uiuc.edu
Wed, 12 Jul 2006 08:45:48 -0500


cvs has some big improvements to pattern support

1. new (pattern ...) macro allows complex patterns to be defined more 
easily. the macro is a bit like loop -- variables can be declared and 
then referenced in the item specification with other item data 
considered constant. there are two types of variables: standard ones 
declared using 'with' and a special type of variable (called an 
'alias') that substitutes an expression into the data rather than a 
value. here's the difference between with and alias variables:

(pattern with x = (random 10) cycle a x b x c x)
==> a 7 b 7 c 7
(pattern alias x = (random 10) cycle a x b x c x)
==> a 2 b 6 b 9

This is how you can define subpatterns with the pattern macro:

(pattern with x = (pattern heap c e g for 1)
          and y = (pattern heap f a c for 1)
          cycle of notes bf x gf y)

The optional 'of' lets you type item data and do nice things like 
define pattern local modes and tempo:

(pattern heap of rhythms q q q w tempo 90)

2. The (process ...) macro now supports pattern iteration clauses:

(process ...
          for x over <pattern> [by <num|t>]
          ...)

in other words, the 'over' clause automatically increments a variable 
by the next value in a pattern and stops iteration if the pattern ever 
returns end-of-data. So the process

(process for x over (pattern cycle 60 61 62 repeat 4)
          output ...)

will stop after outputting 12 notes. using 'over' and 'pattern' makes 
it much easier to express something complex like weights that change as 
a function of something:

(process for k over (pattern alias w = (interpl (now) '(0 0 1 100))
                              weighting of notes c4 (d :weight w)  ...)
          output ...)

In Sal patterns will be defined using a [] notation:
   run for x over [cycle 1,2,3,4 for 5]
     output ...
   end

3. its now possible to place lambda exprs directly in patterns with the 
expectation that they will be funcalled when encountered. this measn 
the (pval ) macro is no longer needed (and has been depreciated).

4. all patterns now accept an :eop-hook, if supplied it is funcalled 
every time the period of the pattern is reset.

pattern macro doc at:
	http://commonmusic.sourceforge.net/doc/dict/pattern-mac.html