]> git.donarmstrong.com Git - lilypond.git/blob - scm/parser-clef.scm
Run grand-replace for 2010.
[lilypond.git] / scm / parser-clef.scm
1 ;;;; This file is part of LilyPond, the GNU music typesetter.
2 ;;;;
3 ;;;; Copyright (C) 2004--2010 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" -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))))
79
80 ;; "an alist mapping GLYPHNAME to the position of the middle C for
81 ;; that symbol"
82 (define c0-pitch-alist
83   '(("clefs.G" . -4)
84     ("clefs.C" . 0)
85     ("clefs.F" . 4)
86     ("clefs.percussion" . 0)
87     ("clefs.tab" . 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)))
106
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)
112       m))
113   (let ((e '())
114         (c0 0)
115         (oct 0)
116         (match (string-match "^(.*)([_^])([0-9]+)$" clef-name)))
117     (if match
118         (begin
119           (set! clef-name (match:substring match 1))
120           (set! oct
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))
124     (if e
125         (let* ((musics (map make-prop-set
126                             `(((symbol . clefGlyph) (value . ,(car e)))
127                               ((symbol . middleCClefPosition)
128                                (value . ,(+ oct
129                                             (cadr e)
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))
139         (begin
140           (ly:warning (_ "unknown clef type `~a'") clef-name)
141           (ly:warning (_ "supported clefs: ~a")
142                       (string-join
143                        (sort (map car supported-clefs) string<?)))
144           (make-music 'Music)))))
145
146 ;; a function to add new clefs at runtime
147 (define-public (add-new-clef clef-name clef-glyph clef-position octavation c0-position)
148   "Append the entries for a clef symbol to supported clefs and c0-pitch-alist"
149   (set! supported-clefs
150         (acons clef-name (list clef-glyph clef-position octavation) supported-clefs))
151   (set! c0-pitch-alist
152         (acons clef-glyph c0-position c0-pitch-alist)))