Next: , Previous: Tuplets (Lisp), Up: Lisp Examples


7.10 Instruments

7.10.1 Defining Instruments

FOMUS has many built-in instruments, but you will probably want to modify some of them or define your own. The electric viola instrument defined here uses the built-in ‘viola’ instrument as a template, replacing the values of a few typical settings. name and abbr set the name and abbreviated name of the instrument as it should appear in the score. min-pitch and max-pitch set the minimum and maximum pitch so that FOMUS prints warning messages if the pitches fall out of range. open-strings is a list of pitches representing the open strings of the instrument, used by FOMUS to calculate notation for harmonics.

(defun notes ()
  (fms:note :time 0 :dur 2 :pitch 70))

(fms:with-score
    (:filename *filename*
     :insts '((:id "elvla" :template "viola"
               :name "Electric Viola" :abbr "evla"
               :min-pitch 48 :max-pitch 108
               :open-strings (48 55 62 69)))
     :parts '((:id "mypart" :inst "elvla")))
  (notes))

lsp064.png

Figure 7.47: Instrument Definition

The same instrument is defined inline inside the part in this example.

(defun notes ()
  (fms:note :time 0 :dur 2 :pitch 70))

(fms:with-score
    (:filename *filename*
     :parts '((:id "mypart"
               :inst (:template "viola"
        	      :name "Electric Viola" :abbr "evla"
        	      :min-pitch 48 :max-pitch 108
        	      :open-strings (48 55 62 69)))))
  (notes))

lsp065.png

Figure 7.48: Inline Instrument Definition

The same instrument is defined once again, only this time without using a template (i.e., the template parameter is missing). Since the definition is not based on a built-in instrument, some essential pieces of information missing in the above examples must be provided (the staff and clef definitions, which there are more examples of below).

(defun notes ()
  (fms:note :time 0 :dur 2 :pitch 70))

(fms:with-score
    (:filename *filename*
     :parts '((:id "mypart"
               :inst (:name "Electric Viola" :abbr "evla"
        	      :min-pitch 48 :max-pitch 108
        	      :open-strings (48 55 62 69)
        	      :staves ((:clefs ((:instclef alto :octs-up 0)
        				(:instclef treble :octs-down 0))))))))
  (notes))

lsp066.png

Figure 7.49: Templateless Instrument Definition

7.10.2 Instrument Library

If you find yourself reusing the same instrument definitions, you could insert something resembling the following in your .fomus file located in your home directory (make sure you use ‘+=’ instead of ‘=’ to append the values to FOMUS's default list). See the section below on defining staves in instruments for more on the staves parameter that appears in this example.

     inst-defs += (<id: ukulele name: "Ukulele"
                    staves: <clefs: <instclef: treble>>
                    min-pitch: 60 max-pitch: 81
                    open-strings: (67 60 64 69)>
                   <id: banjo name: "Banjo"
                    staves: <clefs: <instclef: bass>>
                    min-pitch: 67 max-pitch: 74
                    open-strings: (67 50 55 59 62)>)

All of FOMUS's built-in instruments are contained in the file fomus.conf, which is located in /install_prefix/shared/ (install_prefix is most likely /usr/local or /usr).

7.10.3 Defining Staves in Instruments

Below is an instrument definition that contains a grand staff and uses a treble and bass clef. staves is followed by a list of two staff definitions (each staff definition appears as smaller list inside the larger list). The clefs parameter inside each staff definition is followed by a list of clef definitions (again, each clef definition appears as a smaller list), each of which actually represents a clef choice in that staff. The instclef setting is mandatory and determines the clef sign that appears in the score. Each of the two staves in the instrument below, then, are allowed to display either a treble or bass clef. The first clef definition to appear in a list is the default clef, which means that in the example below, the default clef for staff 1 (the top staff) is treble clef and the default for staff 2 (the bottom staff) is bass clef. The ledgers-up and ledgers-down settings specify how many ledger lines should be allowed to appear before FOMUS begins to consider switching staves or clefs. octs-up and octs-down specify whether or not octave change signs are allowed to appear (a value of 1 means an 8va sign is allowed while a value of 2 means 15va is allowed). clef-preference affects the probability that FOMUS will choose that clef over other choices (a value of 2, for example, doubles the chance of it being chosen while a value of 1/2 reduces it by one half).

(defun notes ()
  (fms:note :time 0 :dur 2 :pitch 70)
  (fms:note :time 2 :dur 2 :pitch 71)
  (fms:note :time 4 :dur 2 :pitch 72))

(fms:with-score
    (:filename *filename*
     :insts '((:id harpsichord :name "Harpsichord"
               :staves ((:clefs ((:instclef treble ; top staff
        			  :ledgers-up 3 :ledgers-down 2
        			  :octs-up 2 :octs-down 0)
        			 (:instclef bass
        			  :clef-preference 1/3
        			  :ledgers-up 2 :ledgers-down 3
        			  :octs-up 0 :octs-down 2)))
        		(:clefs ((:instclef bass ; bottom staff
        			  :ledgers-up 2 :ledgers-down 3
        			  :octs-up 0 :octs-down 2)
        			 (:instclef treble
        			  :clef-preference 1/3
        			  :ledgers-up 3 :ledgers-down 2
        			  :octs-up 2 :octs-down 0))))
               :min-pitch 29 :max-pitch 89))
     :parts '((:id prt :inst harpsichord)))
  (notes))

lsp067.png

Figure 7.50: Staves and Clefs

The following example shows how to define an instrument with a grand staff made up of three staves. Three staff objects are created, each one containing two clef objects representing the choices allowed in that staff.

(defparameter *insts*
  '((:id "piano" :template "piano"
     ;; a list of staff objects, each containing a list of clef objects
     ;; the first clef object in the list is the default for that staff
     :staves ((:clefs ((:instclef "treble" ; defines a treble clef
                        :ledgers-down 2 ; approx. 2 ledger lines allowed below staff
                        :octs-down 0) ; no 8vb octave signs allowed
                       (:instclef "bass" ; defines a bass clef
                        :clef-preference 1/2 ; clef is 1/2 as likely to be chosen
                        :ledgers-up 2 ; approx. 2 ledger lines allowed above staff
                        :octs-up 0))) ; no 8va octave signs allowed
              (:clefs ((:instclef "treble" ; clef choices for middle staff...
                        :ledgers-down 2
                        :octs-down 0 :octs-up 0)
                       (:instclef "bass"
                        :ledgers-up 2
                        :octs-down 0 :octs-up 0)))
              (:clefs ((:instclef "bass" ; bass clef is the default for bottom staff
                        :ledgers-up 2
                        :octs-up 0)
                       (:instclef "treble"
                        :clef-preference 1/2
                        :ledgers-down 2
                        :octs-down 0)))))))

(defun notes (n)
  (loop
     repeat n
     for tim from 0
     do (fms:note :part "prt" :time tim :dur 1 :pitch (+ 33 (random 64)))))

(fms:with-score
    (:filename *filename*
     :insts *insts* ; instruments are always defined first in a `with-score' macro
     :parts '((:id "prt" :inst "piano")))
  (notes 20))

lsp023.png

Figure 7.51: Instrument with Three Staves