11 Metastructure for Composition

Example 11-1. Tone descriptions represented as property lists.

(define piano-tone 
  '(pitch 440 duration 1/4 loudness mf))

(define viola-tone
  '(pitch 440 duration 1/4 loudness mf))

Interaction 11-1. Lisp cannot distinguish between the two tones.

cm> (equal? piano-tone viola-tone)
#t
cm>

Example 11-2. Adding type symbols to the front of each sound description.

(define sounds 
  '((piano-tone pitch 440 duration 1/4 loudness mf )
    (viola-tone pitch 440 duration 1/4 loudness mf )
    (metal-crash duration 2 loudness ff)))

Interaction 11-2. Creating midi instances with new.

cm> (new midi)
#i(midi keynum 60 duration 0.5 amplitude 64 channel 0)
cm> (new midi :keynum 90 :time .5 :duration 3)
#i(midi time .5 keynum 3 duration 3 amplitude 64 channel 0)
cm>

Interaction 11-3. Creating a seq object.

cm> (new seq :name 'test :time 10
         :subobjects 
         (loop for i below 4 
               collect (new midi :time i)))
#<seq: "test">
cm> (object-time #&test)
10
cm> (object-name #&test)
"stuff"
cm> (subobjects #&test)
(#i(midi time 0 keynum 60 duration 0.5 amplitude 64 channel 0)
 #i(midi time 1 keynum 60 duration 0.5 amplitude 64 channel 0)
 #i(midi time 2 keynum 60 duration 0.5 amplitude 64 channel 0)
 #i(midi time 3 keynum 60 duration 0.5 amplitude 64 channel 0))
cm>

Chapter Source Code

The source code to all of the examples and interactions in this chapter can be found in the file objects.cm located in the same directory as the HTML file for this chapter. The source file can be edited in a text editor or evaluated inside the Common Music application.