1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2004--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 ;;;; LilyPond is free software: you can redistribute it and/or modify
6 ;;;; it under the terms of the GNU General Public License as published by
7 ;;;; the Free Software Foundation, either version 3 of the License, or
8 ;;;; (at your option) any later version.
10 ;;;; LilyPond is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;;; GNU General Public License for more details.
15 ;;;; You should have received a copy of the GNU General Public License
16 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
19 ;; (name . (glyph clef-position octavation))
21 ;; -- the name clefOctavation is misleading. The value 7 is 1 octave,
23 (define-public supported-clefs
24 '(("treble" . ("clefs.G" -2 0))
25 ("violin" . ("clefs.G" -2 0))
26 ("G" . ("clefs.G" -2 0))
27 ("G2" . ("clefs.G" -2 0))
28 ("french" . ("clefs.G" -4 0))
29 ("soprano" . ("clefs.C" -4 0))
30 ("mezzosoprano" . ("clefs.C" -2 0))
31 ("alto" . ("clefs.C" 0 0))
32 ("C" . ("clefs.C" 0 0))
33 ("tenor" . ("clefs.C" 2 0))
34 ("baritone" . ("clefs.C" 4 0))
35 ("varbaritone" . ("clefs.F" 0 0))
36 ("bass" . ("clefs.F" 2 0))
37 ("F" . ("clefs.F" 2 0))
38 ("subbass" . ("clefs.F" 4 0))
39 ("percussion" . ("clefs.percussion" 0 0))
40 ("tab" . ("clefs.tab" 0 0))
42 ;; should move mensural stuff to separate file?
43 ("vaticana-do1" . ("clefs.vaticana.do" -1 0))
44 ("vaticana-do2" . ("clefs.vaticana.do" 1 0))
45 ("vaticana-do3" . ("clefs.vaticana.do" 3 0))
46 ("vaticana-fa1" . ("clefs.vaticana.fa" -1 0))
48 ("vaticana-fa2" . ("clefs.vaticana.fa" 1 0))
49 ("medicaea-do1" . ("clefs.medicaea.do" -1 0))
50 ("medicaea-do2" . ("clefs.medicaea.do" 1 0))
51 ("medicaea-do3" . ("clefs.medicaea.do" 3 0))
52 ("medicaea-fa1" . ("clefs.medicaea.fa" -1 0))
53 ("medicaea-fa2" . ("clefs.medicaea.fa" 1 0))
54 ("hufnagel-do1" . ("clefs.hufnagel.do" -1 0))
55 ("hufnagel-do2" . ("clefs.hufnagel.do" 1 0))
56 ("hufnagel-do3" . ("clefs.hufnagel.do" 3 0))
57 ("hufnagel-fa1" . ("clefs.hufnagel.fa" -1 0))
58 ("hufnagel-fa2" . ("clefs.hufnagel.fa" 1 0))
59 ("hufnagel-do-fa" . ("clefs.hufnagel.do.fa" 4 0))
60 ("mensural-c1" . ("clefs.mensural.c" -2 0))
61 ("mensural-c2" . ("clefs.mensural.c" 0 0))
62 ("mensural-c3" . ("clefs.mensural.c" 2 0))
63 ("mensural-c4" . ("clefs.mensural.c" 4 0))
64 ("mensural-f" . ("clefs.mensural.f" 2 0))
65 ("mensural-g" . ("clefs.mensural.g" -2 0))
66 ("neomensural-c1" . ("clefs.neomensural.c" -4 0))
67 ("neomensural-c2" . ("clefs.neomensural.c" -2 0))
68 ("neomensural-c3" . ("clefs.neomensural.c" 0 0))
69 ("neomensural-c4" . ("clefs.neomensural.c" 2 0))
70 ("petrucci-c1" . ("clefs.petrucci.c1" -4 0))
71 ("petrucci-c2" . ("clefs.petrucci.c2" -2 0))
72 ("petrucci-c3" . ("clefs.petrucci.c3" 0 0))
73 ("petrucci-c4" . ("clefs.petrucci.c4" 2 0))
74 ("petrucci-c5" . ("clefs.petrucci.c5" 4 0))
75 ("petrucci-f3" . ("clefs.petrucci.f" 0 0))
76 ("petrucci-f4" . ("clefs.petrucci.f" 2 0))
77 ("petrucci-f" . ("clefs.petrucci.f" 2 0))
78 ("petrucci-g" . ("clefs.petrucci.g" -2 0))))
80 ;; "an alist mapping GLYPHNAME to the position of the middle C for
82 (define c0-pitch-alist
86 ("clefs.percussion" . 0)
88 ("clefs.vaticana.do" . 0)
89 ("clefs.vaticana.fa" . 4)
90 ("clefs.medicaea.do" . 0)
91 ("clefs.medicaea.fa" . 4)
92 ("clefs.hufnagel.do" . 0)
93 ("clefs.hufnagel.fa" . 4)
94 ("clefs.hufnagel.do.fa" . 0)
95 ("clefs.mensural.c" . 0)
96 ("clefs.mensural.f" . 4)
97 ("clefs.mensural.g" . -4)
98 ("clefs.neomensural.c" . 0)
99 ("clefs.petrucci.c1" . 0)
100 ("clefs.petrucci.c2" . 0)
101 ("clefs.petrucci.c3" . 0)
102 ("clefs.petrucci.c4" . 0)
103 ("clefs.petrucci.c5" . 0)
104 ("clefs.petrucci.f" . 4)
105 ("clefs.petrucci.g" . -4)))
107 (define-public (make-clef-set clef-name)
108 "Generate the clef setting commands for a clef with name CLEF-NAME."
109 (define (make-prop-set props)
110 (let ((m (make-music 'PropertySet)))
111 (map (lambda (x) (set! (ly:music-property m (car x)) (cdr x))) props)
116 (match (string-match "^(.*)([_^])([1-9][0-9]*)$" clef-name)))
119 (set! clef-name (match:substring match 1))
121 (* (if (equal? (match:substring match 2) "^") -1 1)
122 (- (string->number (match:substring match 3)) 1)))))
123 (set! e (assoc-get clef-name supported-clefs))
125 (let* ((musics (map make-prop-set
126 `(((symbol . clefGlyph) (value . ,(car e)))
127 ((symbol . middleCClefPosition)
130 (assoc-get (car e) c0-pitch-alist))))
131 ((symbol . clefPosition) (value . ,(cadr e)))
132 ((symbol . clefOctavation) (value . ,(- oct))))))
133 (recalc-mid-C (make-music 'ApplyContext))
134 (seq (make-music 'SequentialMusic
135 'elements (append musics (list recalc-mid-C))))
136 (csp (make-music 'ContextSpeccedMusic)))
137 (set! (ly:music-property recalc-mid-C 'procedure) ly:set-middle-C!)
138 (context-spec-music seq 'Staff))
140 (ly:warning (_ "unknown clef type `~a'") clef-name)
141 (ly:warning (_ "supported clefs: ~a")
143 (sort (map car supported-clefs) string<?)))
144 (make-music 'Music)))))
146 (define-public (make-cue-clef-set clef-name)
147 "Generate the clef setting commands for a cue clef with name CLEF-NAME."
148 (define (make-prop-set props)
149 (let ((m (make-music 'PropertySet)))
150 (map (lambda (x) (set! (ly:music-property m (car x)) (cdr x))) props)
155 (match (string-match "^(.*)([_^])([1-9][0-9]*)$" clef-name)))
158 (set! clef-name (match:substring match 1))
160 (* (if (equal? (match:substring match 2) "^") -1 1)
161 (- (string->number (match:substring match 3)) 1)))))
162 (set! e (assoc-get clef-name supported-clefs))
164 (let* ((musics (map make-prop-set
165 `(((symbol . cueClefGlyph) (value . ,(car e)))
166 ((symbol . middleCCuePosition)
169 (assoc-get (car e) c0-pitch-alist))))
170 ((symbol . cueClefPosition) (value . ,(cadr e)))
171 ((symbol . cueClefOctavation) (value . ,(- oct))))))
172 (recalc-mid-C (make-music 'ApplyContext))
173 (seq (make-music 'SequentialMusic
174 'elements (append musics (list recalc-mid-C))))
175 (csp (make-music 'ContextSpeccedMusic)))
176 (set! (ly:music-property recalc-mid-C 'procedure) ly:set-middle-C!)
177 (context-spec-music seq 'Staff))
179 (ly:warning (_ "unknown clef type `~a'") clef-name)
180 (ly:warning (_ "supported clefs: ~a")
182 (sort (map car supported-clefs) string<?)))
183 (make-music 'Music)))))
186 (define-public (make-cue-clef-unset)
187 "Reset the clef settings for a cue clef."
188 (define (make-prop-unset props)
189 (let ((m (make-music 'PropertyUnset)))
190 (set! (ly:music-property m (car props)) (cdr props))
192 (let* ((musics (map make-prop-unset
193 `((symbol . cueClefGlyph)
194 (symbol . middleCCuePosition)
195 (symbol . cueClefPosition)
196 (symbol . cueClefOctavation))))
197 (recalc-mid-C (make-music 'ApplyContext))
198 (seq (make-music 'SequentialMusic
199 'elements (append musics (list recalc-mid-C))))
200 (csp (make-music 'ContextSpeccedMusic)))
201 (set! (ly:music-property recalc-mid-C 'procedure) ly:set-middle-C!)
202 (context-spec-music seq 'Staff)))
205 ;; a function to add new clefs at runtime
206 (define-public (add-new-clef clef-name clef-glyph clef-position octavation c0-position)
207 "Append the entries for a clef symbol to supported clefs and c0-pitch-alist"
208 (set! supported-clefs
209 (acons clef-name (list clef-glyph clef-position octavation) supported-clefs))
211 (acons clef-glyph c0-position c0-pitch-alist)))