]> git.donarmstrong.com Git - lilypond.git/blob - scm/parser-clef.scm
Merge remote-tracking branch 'origin/master' into translation
[lilypond.git] / scm / parser-clef.scm
1 ;;;; This file is part of LilyPond, the GNU music typesetter.
2 ;;;;
3 ;;;; Copyright (C) 2004--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
4 ;;;;
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.
9 ;;;;
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.
14 ;;;;
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/>.
17
18
19 ;; (name . (glyph clef-position octavation))
20 ;;
21 ;; -- the name clefOctavation is misleading. The value 7 is 1 octave,
22 ;; not 7 Octaves.
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))
41
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))
47
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" -4 0))
61     ("mensural-c2" . ("clefs.mensural.c" -2 0))
62     ("mensural-c3" . ("clefs.mensural.c" 0 0))
63     ("mensural-c4" . ("clefs.mensural.c" 2 0))
64     ("mensural-c5" . ("clefs.mensural.c" 4 0))
65     ("blackmensural-c1" . ("clefs.blackmensural.c" -4 0))
66     ("blackmensural-c2" . ("clefs.blackmensural.c" -2 0))
67     ("blackmensural-c3" . ("clefs.blackmensural.c" 0 0))
68     ("blackmensural-c4" . ("clefs.blackmensural.c" 2 0))
69     ("blackmensural-c5" . ("clefs.blackmensural.c" 4 0))
70     ("mensural-f" . ("clefs.mensural.f" 2 0))
71     ("mensural-g" . ("clefs.mensural.g" -2 0))
72     ("neomensural-c1" . ("clefs.neomensural.c" -4 0))
73     ("neomensural-c2" . ("clefs.neomensural.c" -2 0))
74     ("neomensural-c3" . ("clefs.neomensural.c" 0 0))
75     ("neomensural-c4" . ("clefs.neomensural.c" 2 0))
76     ("neomensural-c5" . ("clefs.neomensural.c" 4 0))
77     ("petrucci-c1" . ("clefs.petrucci.c1" -4 0))
78     ("petrucci-c2" . ("clefs.petrucci.c2" -2 0))
79     ("petrucci-c3" . ("clefs.petrucci.c3" 0 0))
80     ("petrucci-c4" . ("clefs.petrucci.c4" 2 0))
81     ("petrucci-c5" . ("clefs.petrucci.c5" 4 0))
82     ("petrucci-f3" . ("clefs.petrucci.f" 0 0))
83     ("petrucci-f4" . ("clefs.petrucci.f" 2 0))
84     ("petrucci-f5" . ("clefs.petrucci.f" 4 0))
85     ("petrucci-f" . ("clefs.petrucci.f" 2 0))
86     ("petrucci-g" . ("clefs.petrucci.g" -2 0))
87     ("kievan-do" . ("clefs.kievan.do" 0 0))))
88
89 ;; "an alist mapping GLYPHNAME to the position of the middle C for
90 ;; that symbol"
91 (define c0-pitch-alist
92   '(("clefs.G" . -4)
93     ("clefs.C" . 0)
94     ("clefs.F" . 4)
95     ("clefs.percussion" . 0)
96     ("clefs.tab" . 0 )
97     ("clefs.vaticana.do" . 0)
98     ("clefs.vaticana.fa" . 4)
99     ("clefs.medicaea.do" . 0)
100     ("clefs.medicaea.fa" . 4)
101     ("clefs.hufnagel.do" . 0)
102     ("clefs.hufnagel.fa" . 4)
103     ("clefs.hufnagel.do.fa" . 0)
104     ("clefs.mensural.c" . 0)
105     ("clefs.mensural.f" . 4)
106     ("clefs.mensural.g" . -4)
107     ("clefs.blackmensural.c" . 0)
108     ("clefs.neomensural.c" . 0)
109     ("clefs.petrucci.c1" . 0)
110     ("clefs.petrucci.c2" . 0)
111     ("clefs.petrucci.c3" . 0)
112     ("clefs.petrucci.c4" . 0)
113     ("clefs.petrucci.c5" . 0)
114     ("clefs.petrucci.f" . 4)
115     ("clefs.petrucci.g" . -4)
116     ("clefs.kievan.do" . 0)))
117
118 (define-public (make-clef-set clef-name)
119   "Generate the clef setting commands for a clef with name @var{clef-name}."
120   (define (make-prop-set props)
121     (let ((m (make-music 'PropertySet)))
122       (map (lambda (x) (set! (ly:music-property m (car x)) (cdr x))) props)
123       m))
124   (let ((e '())
125         (c0 0)
126         (oct 0)
127         (style 'default)
128         (match (string-match "^(.*)([_^])([^0-9a-zA-Z]*)([1-9][0-9]*)([^0-9a-zA-Z]*)$" clef-name)))
129     (if match
130         (begin
131           (set! clef-name (match:substring match 1))
132           (set! oct
133                 (* (if (equal? (match:substring match 2) "^") -1 1)
134                    (- (string->number (match:substring match 4)) 1)))
135           (set! style
136                 (cond ((equal? (match:substring match 3) "(") 'parenthesized)
137                       ((equal? (match:substring match 3) "[") 'bracketed)
138                       (else style)))))
139     (set! e (assoc-get clef-name supported-clefs))
140     (if e
141         (let* ((prop-list `(((symbol . clefGlyph) (value . ,(car e)))
142                             ((symbol . middleCClefPosition)
143                              (value . ,(+ oct
144                                           (cadr e)
145                                           (assoc-get (car e) c0-pitch-alist))))
146                             ((symbol . clefPosition) (value . ,(cadr e)))
147                             ((symbol . clefOctavation) (value . ,(- oct)))))
148                ;; the clefOctavationStyle property is set only when
149                ;; not 'default to calm display-lily-tests.scm
150                (prop-list (if (eq? style 'default)
151                               prop-list
152                               (append
153                                 prop-list
154                                 `(((symbol . clefOctavationStyle)
155                                    (value . ,style))))))
156                (musics (map make-prop-set prop-list))
157                (recalc-mid-C (make-music 'ApplyContext))
158                (seq (make-music 'SequentialMusic
159                                 'elements (append musics (list recalc-mid-C))))
160                (csp (make-music 'ContextSpeccedMusic)))
161           (set! (ly:music-property recalc-mid-C 'procedure) ly:set-middle-C!)
162           (context-spec-music seq 'Staff))
163         (begin
164           (ly:warning (_ "unknown clef type `~a'") clef-name)
165           (ly:warning (_ "supported clefs: ~a")
166                       (string-join
167                        (sort (map car supported-clefs) string<?)))
168           (make-music 'Music)))))
169
170 (define-public (make-cue-clef-set clef-name)
171   "Generate the clef setting commands for a cue clef with name
172 @var{clef-name}."
173   (define (make-prop-set props)
174     (let ((m (make-music 'PropertySet)))
175       (map (lambda (x) (set! (ly:music-property m (car x)) (cdr x))) props)
176       m))
177   (let ((e '())
178         (c0 0)
179         (oct 0)
180         (style 'default)
181         (match (string-match "^(.*)([_^])([^0-9a-zA-Z]*)([1-9][0-9]*)([^0-9a-zA-Z]*)$" clef-name)))
182     (if match
183         (begin
184           (set! clef-name (match:substring match 1))
185           (set! oct
186                 (* (if (equal? (match:substring match 2) "^") -1 1)
187                    (- (string->number (match:substring match 4)) 1)))
188           (set! style
189                 (cond ((equal? (match:substring match 3) "(") 'parenthesized)
190                       ((equal? (match:substring match 3) "[") 'bracketed)
191                       (else style)))))
192     (set! e (assoc-get clef-name supported-clefs))
193     (if e
194         (let* ((prop-list `(((symbol . cueClefGlyph) (value . ,(car e)))
195                             ((symbol . middleCCuePosition)
196                              (value . ,(+ oct
197                                           (cadr e)
198                                           (assoc-get (car e) c0-pitch-alist))))
199                             ((symbol . cueClefPosition) (value . ,(cadr e)))
200                             ((symbol . cueClefOctavation) (value . ,(- oct)))))
201                (prop-list (if (eq? style 'default)
202                               prop-list
203                               (append
204                                 prop-list
205                                 `(((symbol . cueClefOctavationStyle)
206                                    (value . ,style))))))
207                (musics (map make-prop-set prop-list))
208                (recalc-mid-C (make-music 'ApplyContext))
209                (seq (make-music 'SequentialMusic
210                                 'elements (append musics (list recalc-mid-C))))
211                (csp (make-music 'ContextSpeccedMusic)))
212           (set! (ly:music-property recalc-mid-C 'procedure) ly:set-middle-C!)
213           (context-spec-music seq 'Staff))
214         (begin
215           (ly:warning (_ "unknown clef type `~a'") clef-name)
216           (ly:warning (_ "supported clefs: ~a")
217                       (string-join
218                        (sort (map car supported-clefs) string<?)))
219           (make-music 'Music)))))
220
221
222 (define-public (make-cue-clef-unset)
223   "Reset the clef settings for a cue clef."
224   (define (make-prop-unset props)
225     (let ((m (make-music 'PropertyUnset)))
226       (set! (ly:music-property m (car props)) (cdr props))
227       m))
228   (let* ((musics (map make-prop-unset
229                         `((symbol . cueClefGlyph)
230                           (symbol . middleCCuePosition)
231                           (symbol . cueClefPosition)
232                           (symbol . cueClefOctavation)
233                           (symbol . cueClefOctavationStyle))))
234          (recalc-mid-C (make-music 'ApplyContext))
235          (seq (make-music 'SequentialMusic
236                           'elements (append musics (list recalc-mid-C))))
237          (csp (make-music 'ContextSpeccedMusic)))
238     (set! (ly:music-property recalc-mid-C 'procedure) ly:set-middle-C!)
239     (context-spec-music seq 'Staff)))
240
241
242 ;; a function to add new clefs at runtime
243 (define-public (add-new-clef clef-name clef-glyph clef-position octavation c0-position)
244   "Append the entries for a clef symbol to supported clefs and
245 @code{c0-pitch-alist}."
246   (set! supported-clefs
247         (acons clef-name (list clef-glyph clef-position octavation) supported-clefs))
248   (set! c0-pitch-alist
249         (acons clef-glyph c0-position c0-pitch-alist)))