Next: , Previous: SAL Examples, Up: SAL Examples


8.1 Some Basic SAL Examples

The following SAL code shows a process definition and a sprout command. The output is sent to FOMUS if the output filename in *filename* contains an extension that FOMUS recognizes. Common Music automatically sets the filename setting before processing the score.

process myproc (n, r)
  repeat n
  fms:note(dur: r, pitch: between(48, 73))
  wait r
end

sprout(myproc(16, 1/2), *filename*)

sal001.png

Figure 8.1: Process

The next example produces the same result without sprouting processes. A new score must be created using new-score, after which all information is entered using function calls. run is called at the end to process the score.

function myproc (n, r)
  loop repeat n
    for tim from 0 by r
    fms:note(part: "mypart", time: tim, dur: r, pitch: between(48, 73))
  end
end

fms:new-score(*filename*) ; define a new score object

fms:part(id: "mypart", inst: "piano") ; create a part

myproc(16, 1/2) ; send the notes

fms:run() ; run FOMUS

sal026.png

Figure 8.2: Direct

8.1.1 Data Types

Integer, rational and floating point types are preserved when they are sent to FOMUS. It's generally better to use integers and rationals whenever possible.

fms:new-score(*filename*) ; define a new score object

fms:note(time: 0, dur: 1/2, pitch: 60)
fms:note(time: 0.5, dur: 0.5, pitch: 62.0)
fms:note(time: 1, dur: 1/3, pitch: 64)
fms:note(time: 1.333, dur: 1/3, pitch: 66.0)
fms:note(time: 5/3, dur: 0.333, pitch: 68)

fms:run() ; run FOMUS

sal029.png

Figure 8.3: Numbers

Time stamps in SAL/Common Music processes are floating point numbers.

Symbols and keywords can be used whenever fomus requires a string value. The symbol characters are always converted to lower case.

define process myproc ()
  for p from 0
  while (elapsed() < 3)
  fms:note(part: :prt1, dur: 1/2, pitch: p + 65)
  fms:note(part: "prt2", dur: 1/2, pitch: 48 - p)
  wait 1/2
end

sprout(myproc(), *filename*,
       parts: {{:id "prt1" :inst "guitar"}
               {:id prt2 :inst TUBA}})

sal028.png

Figure 8.4: Symbols/Strings

Any FOMUS setting documented as requiring a “yes/no” value is a boolean value and may be entered using ‘#t’ or ‘#f’.

process myproc ()
  for p from 0 by 1/2
  while (elapsed() < 3)
  fms:note(part: :prt1, dur: 1/2, pitch: 65 + p)
  wait 1/2
end

sprout(myproc(), *filename*,
       sets: {:quartertones #t :double-accs #f}, ; boolean values
       parts: {{:id "prt1" :inst "guitar"}})

sal030.png

Figure 8.5: Boolean Values

Lists or nested lists in FOMUS are simply entered with SAL lists. Settings that are described as “mappings” from strings to values are also entered with lists.

define process myproc ()
  for p from 0
  while elapsed() < 3
  fms:note(part: :prt1, dur: 1/2, pitch: 65 + p,
        voice: {1 2}) ; list of voices
  wait 1/2
end

sprout(myproc(), *filename*,
       sets: {:timesigs {{2 8} {4 8} {8 8}}  ; nested list of possible time signatures
              :keysig-defs ; mapping from keysig symbols to lists
              {asmin {fs cs gs ds as es bs}
               afmaj {bf ef af df}
               afmin {bf ef af df gf cf ff}
               amaj {fs cs gs}
               amin {}
               bfmaj {bf ef}
               bfmin {bf ef af df gf}
               bmaj {fs cs gs ds as}
               bmin {fs cs}
               csmaj {fs cs gs ds as es bs}
               csmin {fs cs gs ds}
               cfmaj {bf ef af df gf cf ff}
               cmaj {}
               cmin {bf ef af}
               dsmin {fs cs gs ds as es}
               dfmaj {bf ef af df gf}
               dmaj {fs cs}
               dmin {bf}
               efmaj {bf ef af}
               efmin {bf ef af df gf cf}
               emaj {fs cs gs ds}
               emin {fs}
               fsmaj {fs cs gs ds as es}
               fsmin {fs cs gs}
               fmaj {bf}
               fmin {bf ef af df}
               gsmin {fs cs gs ds as}
               gfmaj {bf ef af df gf cf}
               gmaj {fs}}
              :keysig "dmaj"},
       parts: {{:id "prt1" :inst "guitar"}}
     )

sal031.png

Figure 8.6: Lists