CCRMA

Common Music Patterns


Common Music Patterns

Introduction to Common Music Patterns. See the Common Music Manual for version 2.4.0. Look at the Common Music dictionary for detailed definition of all the Common Music functions and macros.

Pattern Classes

During the class we took a look at the simplest classes or types of patterns. Each class of patterns has a different behavior in how elements are selected:

cycle
circular selection of elements in the pattern
line
go from first to last, repeat last
palindrome
first to last and back
heap
random selection without replacement
random
random selection with replacement

Patterns are objects created with the "new" macro. The following line stores a cyclic pattern (cyclic patterns are the default type of pattern) that contains five elements in the global variable "pat":

  (setf pat (new cycle :of '(1 2 3 4 5)))

We can access elements through the "next" function, which can either return one element at a time or a whole period of selected elements:

  (next pat)
  1
  (next pat)
  2

or if we want a whole "period" returned in a list we add an optional argument with the value ":chunk":

  (next pat :chunk)
  (1 2 3 4 5)

by default the period of a pattern is equal to the number of elements it contains. We can create a specific kind of pattern by naming its type when creating it:

  (setf pat (new cycle :of '(1 2 3 4 5)))
  (setf pat (new random :of '(1 2 3 4 5)))

Patterns can be nested to arbitrary depths, the following pattern contains a random sub-pattern as element four:

  (setf pat (new cycle :of (list 1 2 3 (new random :of '(10 20 30)) 5)))
  (next pat :chunk)
  (1 2 3 10 30 20 5)

Note that the included pattern completes its own period before returning control to the enclosing pattern. This behavior can be changed by altering the default period of the pattern using the for keyword:

  (setf pat (new cycle :of (list 1 2 3 (new random :of '(10 20 30) :for 1) 5)))
  (next pat :chunk)
  (1 2 3 10 5)
  (next pat :chunk)
  (1 2 3 30 5)

The period itself could be a pattern!:

  (setf pat (new cycle :of (list 1 2 3 (new random :of '(10 20 30) :for (new heap :of '(1 2))) 5)))
  (next pat :chunk)
  (1 2 3 20 10 5)
  (next pat :chunk)
  (1 2 3 10 5)

If you want to supply a prebuilt list of elements to the new macro just use the of keyword followed by a list of elements:

  (setf elements '(1 2 3 4))
  (setf pat (new heap :of elements :for 3))

Here is a link to the examples I played in class. I have added comments and some url's to the file so that the progression of examples make more sense


©1998, 2001-2003 Fernando Lopez-Lezcano. All Rights Reserved.
nando@ccrma.stanford.edu