spobooks bbv9810.0001.001 in

    5.1 Getting Started

    Perhaps the easiest way to write a program is to type code into a file. Consult your Common LISP documentation to learn how to create, edit, save, compile, and load files.

    Before we begin entering code into a file, we must learn how Common Music assigns values to slots. In section 4.4, we learned how to assign values to global variables using SETF. Common Music also uses SETF to assign values to slots. Example 5.1.1 assigns the MIDI note slot a value of 60 with an amplitude of .5.

    Example 5.1.1

    (setf note 60)
    (setf amplitude .5)

    Example 5.1.2 shows how you can write a program to create a generator and place a note in that generator.

    Example 5.1.2: my-first-generator.lisp

    (generator my-first-generator midi-note (length 1)
    (setf note 60)
    (setf amplitude .5)
    (setf rhythm .25)
    (setf duration .7)
    (setf channel 0))

    Note: examples followed by : and a filename as in Example 5.1.2 are included on the accompanying compact disc.

    What does this code say? We create an instance of a generator called my-first-generator and we fill the generator with midi-note objects. We can initialize the generator's slots in the parentheses following the instantiation of the generator. In this case, we initialize the generator's length slot to have a value of one midi-note. Following the container initialization list, we enter the body of the generator where the additional values are bound to slots using SETF. Notice that SETF is used with slot name-slot value pairs enclosed in parentheses.my-first-generator is closed by a concluding right parenthesis that balances with the left parenthesis that initiated the program.

    What are the various container initialization slots? The container object has optional initialization parameters for start time in seconds. Because of Common Music's object hierarchy, thread, merge, and algorithm inherit start from container. In addition, algorithm has container initializations for length, count, and end.length is the number of note or rest events in the container.count is a Common Music variable that increments its value based on the number of note or rest events in a container.end specifies the ending time in seconds.heap inherits from thread so heap has an optional initialization for start time.generator inherits from thread and algorithm so generator has optional initializations for start, length, count, and end.mute inherits from algorithm so mute also has optional initializations for start, length, count, and end.

    Once the code has been typed into a file, save the file as my-first-generator.lisp. The .lisp extension will help you recognize the file as Common Music source code.

    Next, evaluate the code by selecting all of the text in my-first-generator.lisp, copying it, and then pasting it into Stella. Press return and Stella will evaluate the program and create my-first-generator. Alternatively, you may also evaluate the code by loading the file into Common Music

    You may listen to the generator by entering the Common Music command mix my-first-generator at Stella's Top-Level or change the focus object to my-first-generator and enter the command mix.

    The result of the Common Music evaluation may be saved as a Common Music file using the Common Music command archive command. Notice that in Example 5.1.3, the focus object is my-first-generator. Using a file extension of .cm identifies the file as a Common Music archive.

    Example 5.1.3: my-first-generator.cm
    Stella [My-First-Generator]: archive
    Archive objects: (<cr>=My-First-Generator)
    Archive file: (<cr>=home:test.cm) Macintosh HD:Desktop Folder:my-first-generator.cm
    Archiving Macintosh HD:Desktop Folder:my-first-generator.cm.

    Just as with my-first-generator.lisp, you may load my-first-generator.cm and Common Music will load and evaluate the file.

    What's the difference between the Common Music .lisp source file and the Common Music .cm archived file? Open and view the contents of my-first-generator.cm. You'll see the code that Common Music generated when it evaluated my-first-generator.lisp.

    In addition to saving the .lisp or .cm source, you may wish to save the musical output from my-first-generator.lisp to a MIDI file (.mid). Saving the output of Common Music as a standard MIDI file means you can readily combine the power of Common Music with the functionality of a MIDI sequencer. Type the Common Music command, open <filename>.mid to open a stream to a MIDI file. Once the stream is open, mix the container. The output of the container is directed to <filename>.mid. When you're finished writing the file, use the Common Music command close to close the stream.

    Example 5.1.4
    Stella [My-First-Generator]: open my-first-generator.mid
    Stream: #<Copy-Stream: my-first-generator.mid.copy>
    Stella [My-First-Generator]: mix
    Mix objects: (<cr>=My-First-Generator)
    Start time offset:(<cr>=None)

    Stella [My-First-Generator]: close my-first-generator.mid.copy

    Stella [My-First-Generator]:

    If you're using Common Music on a Macintosh, from the Common Music menu, select Streams , New Streams , and MIDI file . Common Music will bring up a window with a default file name in the title bar of the window. You can enter attributes of the .mid file such as the filename and start time. Use the mix command to route the MIDI output to the named .mid file. To redirect MIDI output to the port, from the Common Music menu, select Streams , and MIDI .

    Table 5.1.1 gives an overview of the file formats discussed in Section 5.1.

    Table 5.1.1

    File Type

    File Suffix

    Description

    Command(s) associated with file creation

    Common Music LISP source

    .lisp

    File contains Common Music and Common LISP program code

    Refer to your Common LISP documentation on how to create, edit, save, compile, and load files.

    Common Music Archive

    .cm

    File contains CLOS program code

    archive

    MIDI File

    .mid

    File contains MIDI data created as a result of opening a stream for MIDI output

    open

    mix