A Short Solo Piano Example - aa-cell
This page outlines the construction of a simple piano piece in Impromptu.  This short example demonstrates a number of techniques commonly used by aa-cell in live coding performance.  
We will start by defining a pitch class set to use for this work (messiaen scale number 6 to begin with).
(define scale (pc:scale 0 'messiaen6))
The structure of this example will be based around the idea of a simple transition network with 4 nodes.  We start by defining node 1 - a simple random walk moving in intervals of a second or third.  Cosine’s provide pulsation and the make-rhythm function provides gestalt groupings of rhythmic material (of triplets quavers and semiquavers).  An additional random variation provides a series of 8 semidemiquavers.  At the completion of the rhythmic pattern - the dlst (duration list) - node1 will move randomly to either node1, node2 or node3.  A simple variation is provided whenever a triplet is encountered by adding an octave and offsetting the cosine pulse (3 instead of the usual 2).
Here is a short audio example of node1 playing by itself.
(define node1
   (lambda (beat pitch dlst)
      (play piano1 pitch (+ 50 (* 20 (cos (* beat pi 2)))) .1)
      (if (= (car dlst) (/ 1 3)) (play piano1 (+ 12 pitch)
                                       (+ 80 (* 30 (cos (* beat pi 3)))) .1))
      (callback (*metro* (+ beat (* .5 (car dlst))))
                (if (and (> (random) .7)
                         (null? (cdr dlst)))
                    (random '(node2 node3))
                (+ beat (car dlst))
                (pc:relative pitch (random (quote (-2 -1 -1 -1 1 1 1 2))) scale)
                (if (null? (cdr dlst))
                    (if (> (random) .8)
                        (make-list 8 .125)
                        (make-rhythm 1 (list (/ 1 3) .25 0.25 0.5)))
                    (cdr dlst)))))
Node2 provides a simple descending motif in leaps to contrast the tight random walk of the first node.  The motif begins from whatever pitch the previous node finished on.  Small changes to the intervals (pc:relative) provides subtle variation to the motif.  Here is a short audio example that includes the first and second nodes only.  Node2 will move randomly to either node3 or node4.
(define node2
   (lambda (beat pitch dlst)
      (play piano1 pitch 80 .2)
      (play .5 piano1 (pc:relative pitch (random '(-3 -4)) scale) 90 .2)  
      (play 1 piano1 (pc:relative pitch (random '(-7 -14)) scale) 100 .2)
      (callback (*metro* (+ beat 1)) (random (cons .9 'node3) (cons .1 'node4))
                (+ beat 1.5)
                (random '(60 72))
                (make-rhythm 1 (quote (0.25 0.5))))))
Node3 plays a single chord - either sustained or staccato - providing contrast to the monophonic lines of nodes1 and 2 as well as providing some breathing space for the music.  Node3 also randomly changes the pitch class set used by all nodes in this example.  Here is a short audio example which includes nodes 1, 2 and 3.  Node3 moves randomly to either node1 or node3.
(define node3
   (lambda (beat pitch dlst)
      (set! scale (pc:scale (random 12) (random '(messiaen6 messiaen2 messiaen4))))
      (let* ((dur (random '(.25 .25 .25 2 4)))
             (pbeat (if (> (random) .3) .15 dur)))
         (for-each (lambda (p)
                      (play-note (*metro* beat) piano1 p pitch (*metro* 'dur pbeat)))
                   (pc:make-chord 40 75 4 scale))
         (callback (*metro* (+ beat .2)) (random '(node1 node1 node3)) (+ beat dur)
                   (random '(60 72 84))
                   (make-rhythm 1 (quote (0.25 0.5)))))))
Node4 provides a strong contrast to the earlier nodes by providing a softer, gentler random exploration of the pitch class set.  Node4 moves to either node4 or node1.  Node4 is less likely to move than either node1,2 or 3, providing a contrasting section for the piece.  The simplicity of this type of node is perfect for live coding performance as it is very fast to implement.
(define node4
   (lambda (beat pitch dlst)
      (let ((cb (random (cons .9 'node4) (cons .1 'node1))))
         (play-note (*metro* beat) piano1 pitch (random 5 30) (*metro* 'dur 6))
         (callback (*metro* (+ beat .2)) cb (+ beat (if (eq? cb 'l1)
                                                        (random '(.25 1 1.5 5 7))))
                   (pc:random 40 80 scale)
                   (make-rhythm 1 (quote (0.25 0.5)))))))
Here is a complete example including all nodes.  
It is important to remember that during a live coding performance these structures are generally built in a more simple form and expanded upon throughout the performance.  For example at the start of a live coding performance node1 would be the only node running and would be far simpler in form.
(define node1
   (lambda (beat pitch dlst)
      (play piano1 pitch (+ 50 (* 20 (cos (* pi beat 2)))) 0.1)
      (callback (*metro* (+ beat (* .5 (car dlst)))) 'node1 (+ beat (car dlst))
                (pc:relative pitch (random '(-2 -1 -1 1 1 2)) scale)
                (if (null? (cdr dlst))
                    (make-rhythm 1 (list (/ 1 3) 0.5 0.25))                
                    (cdr dlst)))))
Possibly the piece would then proceed with the addition of node2 followed by some extensions to node1 etc..
You can find more recordings of performances by aa-cell here.