spobooks bbv9810.0001.001 in

    Appendix B: Using Common Music with Csound

    Use the Common Music function in-syntax to use Csound.

    STELLA [TOP-LEVEL]: (IN-SYNTAX :CSOUND)
    #<SYNTAX: CSOUND>

    In order to implement the Csound score file output, define an object named i1 using the Common Music macro DEFOBJECT. The new object is a subclass of csound-note. A standard class i1 is created that corresponds to the i1 statement in the Csound scorefile. Additional slots for object i1 are dur, freq, and amp. Parameters for the I-statement are instrument number (ins), start time or rhythm (time ), duration (dur ), amplitude (amp ), and frequency (freq ). These parameters correspond to the parameter fields p1, p2, p3, p4, and p5 in the Csound scorefile.

    Example B.1

    (in-package :cm)
    (defobject i1 (csound-note)
    (dur freq amp)
    (:parameters ins time dur amp freq))

    When Common Music evaluates the code in Example B.1, it responds:

    #<Package "COMMON-MUSIC">

    #<STANDARD-CLASS I1>

    Now that Common Music knows the current syntax is Csound and the parameter fields for an i1 object, we program a generator to output i1 statements:

    Example B.2
    (generator csound-test i1 (length 20 dur .1 rhythm .1)
    (setf freq (between 220 440))
    (setf amp (between 20000 32000)))

    When Common Music evaluates the code in Example B.2, it responds:

    #<GENERATOR: Csound-Test>

    Open a stream to a file so Common Music can output the results of the generator csound-test. The Common Music OPEN command opens a stream to the file named csound.sco. The Common Music MIX command calculates the slot values and writes the result to csound.sco. We do not play the file since we will use csound.sco as input to the Csound compiler.

    Stella [Top-Level]: open csound.sco
    Stream: #<Csound-Score-File: "csound.sco">
    Stella [Top-Level]: mix csound-test
    Start time offset:(<cr>=None)
    Play file csound.sco? (<cr>=Yes) no

    ; Common Music output of 3-May-100 14:21:17

    s
    i1 0.0 0.1 27292 313
    i1 0.1 0.1 23518 417
    i1 0.2 0.1 28220 336
    i1 0.3 0.1 26393 424
    i1 0.4 0.1 29430 373
    i1 0.5 0.1 22509 249
    i1 0.6 0.1 26593 283
    i1 0.699 0.1 28623 238
    i1 0.799 0.1 21379 380
    i1 0.899 0.1 27927 308
    i1 0.999 0.1 26589 380
    i1 1.099 0.1 24515 335
    i1 1.2 0.1 26218 258
    i1 1.3 0.1 25070 391
    i1 1.4 0.1 26345 274
    i1 1.5 0.1 28330 267
    i1 1.6 0.1 25479 268
    i1 1.7 0.1 23905 349
    i1 1.8 0.1 28771 244
    i1 1.9 0.1 28062 335
    e

    You may add additional parameter fields by adding slots to the parameter list and specifying the order in which the values should be output to the parameter list. Example B.3 extends Example B.2 by adding a parameter field for pan.

    Example B.3
    (in-package :cm)
    (defobject i1 (csound-note)
    (dur freq amp pan)
    (:parameters ins time dur amp freq pan))