1 ;;;; clef.scm -- Clef settings
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2004--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
8 ;; (name . (glyph clef-position octavation))
10 ;; -- the name clefOctavation is misleading. The value 7 is 1 octave,
12 (define-public supported-clefs
13 '(("treble" . ("clefs.G" -2 0))
14 ("violin" . ("clefs.G" -2 0))
15 ("G" . ("clefs.G" -2 0))
16 ("G2" . ("clefs.G" -2 0))
17 ("french" . ("clefs.G" -4 0))
18 ("soprano" . ("clefs.C" -4 0))
19 ("mezzosoprano" . ("clefs.C" -2 0))
20 ("alto" . ("clefs.C" 0 0))
21 ("C" . ("clefs.C" 0 0))
22 ("tenor" . ("clefs.C" 2 0))
23 ("baritone" . ("clefs.C" 4 0))
24 ("varbaritone" . ("clefs.F" 0 0))
25 ("bass" . ("clefs.F" 2 0))
26 ("F" . ("clefs.F" 2 0))
27 ("subbass" . ("clefs.F" 4 0))
28 ("percussion" . ("clefs.percussion" 0 0))
29 ("tab" . ("clefs.tab" 0 0))
31 ;; should move mensural stuff to separate file?
32 ("vaticana-do1" . ("clefs.vaticana.do" -1 0))
33 ("vaticana-do2" . ("clefs.vaticana.do" 1 0))
34 ("vaticana-do3" . ("clefs.vaticana.do" 3 0))
35 ("vaticana-fa1" . ("clefs.vaticana.fa" -1 0))
37 ("vaticana-fa2" . ("clefs.vaticana.fa" 1 0))
38 ("medicaea-do1" . ("clefs.medicaea.do" -1 0))
39 ("medicaea-do2" . ("clefs.medicaea.do" 1 0))
40 ("medicaea-do3" . ("clefs.medicaea.do" 3 0))
41 ("medicaea-fa1" . ("clefs.medicaea.fa" -1 0))
42 ("medicaea-fa2" . ("clefs.medicaea.fa" 1 0))
43 ("hufnagel-do1" . ("clefs.hufnagel.do" -1 0))
44 ("hufnagel-do2" . ("clefs.hufnagel.do" 1 0))
45 ("hufnagel-do3" . ("clefs.hufnagel.do" 3 0))
46 ("hufnagel-fa1" . ("clefs.hufnagel.fa" -1 0))
47 ("hufnagel-fa2" . ("clefs.hufnagel.fa" 1 0))
48 ("hufnagel-do-fa" . ("clefs.hufnagel.do.fa" 4 0))
49 ("mensural-c1" . ("clefs.mensural.c" -2 0))
50 ("mensural-c2" . ("clefs.mensural.c" 0 0))
51 ("mensural-c3" . ("clefs.mensural.c" 2 0))
52 ("mensural-c4" . ("clefs.mensural.c" 4 0))
53 ("mensural-f" . ("clefs.mensural.f" 2 0))
54 ("mensural-g" . ("clefs.mensural.g" -2 0))
55 ("neomensural-c1" . ("clefs.neomensural.c" -4 0))
56 ("neomensural-c2" . ("clefs.neomensural.c" -2 0))
57 ("neomensural-c3" . ("clefs.neomensural.c" 0 0))
58 ("neomensural-c4" . ("clefs.neomensural.c" 2 0))
59 ("petrucci-c1" . ("clefs.petrucci.c1" -4 0))
60 ("petrucci-c2" . ("clefs.petrucci.c2" -2 0))
61 ("petrucci-c3" . ("clefs.petrucci.c3" 0 0))
62 ("petrucci-c4" . ("clefs.petrucci.c4" 2 0))
63 ("petrucci-c5" . ("clefs.petrucci.c5" 4 0))
64 ("petrucci-f3" . ("clefs.petrucci.f" 0 0))
65 ("petrucci-f4" . ("clefs.petrucci.f" 2 0))
66 ("petrucci-f" . ("clefs.petrucci.f" 2 0))
67 ("petrucci-g" . ("clefs.petrucci.g" -2 0))))
69 ;; "an alist mapping GLYPHNAME to the position of the middle C for
71 (define c0-pitch-alist
75 ("clefs.percussion" . 0)
77 ("clefs.vaticana.do" . 0)
78 ("clefs.vaticana.fa" . 4)
79 ("clefs.medicaea.do" . 0)
80 ("clefs.medicaea.fa" . 4)
81 ("clefs.hufnagel.do" . 0)
82 ("clefs.hufnagel.fa" . 4)
83 ("clefs.hufnagel.do.fa" . 0)
84 ("clefs.mensural.c" . 0)
85 ("clefs.mensural.f" . 4)
86 ("clefs.mensural.g" . -4)
87 ("clefs.neomensural.c" . 0)
88 ("clefs.petrucci.c1" . 0)
89 ("clefs.petrucci.c2" . 0)
90 ("clefs.petrucci.c3" . 0)
91 ("clefs.petrucci.c4" . 0)
92 ("clefs.petrucci.c5" . 0)
93 ("clefs.petrucci.f" . 4)
94 ("clefs.petrucci.g" . -4)))
96 (define-public (make-clef-set clef-name)
97 "Generate the clef setting commands for a clef with name CLEF-NAME."
98 (define (make-prop-set props)
99 (let ((m (make-music 'PropertySet)))
100 (map (lambda (x) (set! (ly:music-property m (car x)) (cdr x))) props)
105 (match (string-match "^(.*)([_^])([0-9]+)$" clef-name)))
108 (set! clef-name (match:substring match 1))
110 (* (if (equal? (match:substring match 2) "^") -1 1)
111 (- (string->number (match:substring match 3)) 1)))))
112 (set! e (assoc clef-name supported-clefs))
114 (let* ((musics (map make-prop-set
115 `(((symbol . clefGlyph) (value . ,(cadr e)))
116 ((symbol . middleCClefPosition)
119 (cdr (assoc (cadr e) c0-pitch-alist)))))
120 ((symbol . clefPosition) (value . ,(caddr e)))
121 ((symbol . clefOctavation) (value . ,(- oct))))))
122 (recalc-mid-C (make-music 'ApplyContext))
123 (seq (make-music 'SequentialMusic
124 'elements (append musics (list recalc-mid-C))))
125 (csp (make-music 'ContextSpeccedMusic)))
126 (set! (ly:music-property recalc-mid-C 'procedure) ly:set-middle-C!)
127 (context-spec-music seq 'Staff))
129 (ly:warning (_ "unknown clef type `~a'") clef-name)
130 (ly:warning (_ "supported clefs: ~a")
132 (sort (map car supported-clefs) string<?)))
133 (make-music 'Music)))))