;;;; This file is part of LilyPond, the GNU music typesetter.
;;;;
-;;;; Copyright (C) 2004--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
+;;;; Copyright (C) 2004--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
;;;;
;;;; LilyPond is free software: you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
-;; (name . (glyph clef-position octavation))
+;; (name . (glyph clef-position transposition))
;;
-;; -- the name clefOctavation is misleading. The value 7 is 1 octave,
-;; not 7 Octaves.
+;; -- the name clefTransposition is a bit misleading. Value 7 means
+;; a transposition of an octave, not a seventh.
(define-public supported-clefs
'(("treble" . ("clefs.G" -2 0))
("violin" . ("clefs.G" -2 0))
("G" . ("clefs.G" -2 0))
("G2" . ("clefs.G" -2 0))
+ ("GG" . ("clefs.GG" -2 0))
+ ("tenorG" . ("clefs.tenorG" -2 0))
("french" . ("clefs.G" -4 0))
("soprano" . ("clefs.C" -4 0))
("mezzosoprano" . ("clefs.C" -2 0))
("alto" . ("clefs.C" 0 0))
("C" . ("clefs.C" 0 0))
+ ("varC" . ("clefs.varC" 0 0))
+ ("altovarC" . ("clefs.varC" 0 0))
("tenor" . ("clefs.C" 2 0))
+ ("tenorvarC" . ("clefs.varC" 2 0))
("baritone" . ("clefs.C" 4 0))
+ ("baritonevarC" . ("clefs.varC" 4 0))
("varbaritone" . ("clefs.F" 0 0))
+ ("baritonevarF" . ("clefs.F" 0 0))
("bass" . ("clefs.F" 2 0))
("F" . ("clefs.F" 2 0))
("subbass" . ("clefs.F" 4 0))
("percussion" . ("clefs.percussion" 0 0))
+ ("varpercussion" . ("clefs.varpercussion" 0 0))
("tab" . ("clefs.tab" 0 0))
;; should move mensural stuff to separate file?
("hufnagel-fa1" . ("clefs.hufnagel.fa" -1 0))
("hufnagel-fa2" . ("clefs.hufnagel.fa" 1 0))
("hufnagel-do-fa" . ("clefs.hufnagel.do.fa" 4 0))
- ("mensural-c1" . ("clefs.mensural.c" -2 0))
- ("mensural-c2" . ("clefs.mensural.c" 0 0))
- ("mensural-c3" . ("clefs.mensural.c" 2 0))
- ("mensural-c4" . ("clefs.mensural.c" 4 0))
+ ("mensural-c1" . ("clefs.mensural.c" -4 0))
+ ("mensural-c2" . ("clefs.mensural.c" -2 0))
+ ("mensural-c3" . ("clefs.mensural.c" 0 0))
+ ("mensural-c4" . ("clefs.mensural.c" 2 0))
+ ("mensural-c5" . ("clefs.mensural.c" 4 0))
+ ("blackmensural-c1" . ("clefs.blackmensural.c" -4 0))
+ ("blackmensural-c2" . ("clefs.blackmensural.c" -2 0))
+ ("blackmensural-c3" . ("clefs.blackmensural.c" 0 0))
+ ("blackmensural-c4" . ("clefs.blackmensural.c" 2 0))
+ ("blackmensural-c5" . ("clefs.blackmensural.c" 4 0))
("mensural-f" . ("clefs.mensural.f" 2 0))
("mensural-g" . ("clefs.mensural.g" -2 0))
("neomensural-c1" . ("clefs.neomensural.c" -4 0))
("neomensural-c2" . ("clefs.neomensural.c" -2 0))
("neomensural-c3" . ("clefs.neomensural.c" 0 0))
("neomensural-c4" . ("clefs.neomensural.c" 2 0))
+ ("neomensural-c5" . ("clefs.neomensural.c" 4 0))
("petrucci-c1" . ("clefs.petrucci.c1" -4 0))
("petrucci-c2" . ("clefs.petrucci.c2" -2 0))
("petrucci-c3" . ("clefs.petrucci.c3" 0 0))
;; that symbol"
(define c0-pitch-alist
'(("clefs.G" . -4)
+ ("clefs.GG" . 3)
+ ("clefs.tenorG" . 3)
("clefs.C" . 0)
+ ("clefs.varC" . 0)
("clefs.F" . 4)
("clefs.percussion" . 0)
+ ("clefs.varpercussion" . 0)
("clefs.tab" . 0 )
("clefs.vaticana.do" . 0)
("clefs.vaticana.fa" . 4)
("clefs.mensural.c" . 0)
("clefs.mensural.f" . 4)
("clefs.mensural.g" . -4)
+ ("clefs.blackmensural.c" . 0)
("clefs.neomensural.c" . 0)
("clefs.petrucci.c1" . 0)
("clefs.petrucci.c2" . 0)
(define-public (make-clef-set clef-name)
"Generate the clef setting commands for a clef with name @var{clef-name}."
- (define (make-prop-set props)
- (let ((m (make-music 'PropertySet)))
- (map (lambda (x) (set! (ly:music-property m (car x)) (cdr x))) props)
- m))
- (let ((e '())
- (c0 0)
- (oct 0)
- (match (string-match "^(.*)([_^])([1-9][0-9]*)$" clef-name)))
- (if match
- (begin
- (set! clef-name (match:substring match 1))
- (set! oct
- (* (if (equal? (match:substring match 2) "^") -1 1)
- (- (string->number (match:substring match 3)) 1)))))
- (set! e (assoc-get clef-name supported-clefs))
+ (let* ((match (string-match "^(.*)([_^])([^0-9a-zA-Z]*)([1-9][0-9]*)([^0-9a-zA-Z]*)$" clef-name))
+ (e (assoc-get (if match (match:substring match 1) clef-name) supported-clefs))
+ (oct (if match
+ ((if (equal? (match:substring match 2) "^") - +)
+ (1- (string->number (match:substring match 4))))
+ 0))
+ (style (cond ((not match) 'default)
+ ((equal? (match:substring match 3) "(") 'parenthesized)
+ ((equal? (match:substring match 3) "[") 'bracketed)
+ (else 'default))))
(if e
- (let* ((musics (map make-prop-set
- `(((symbol . clefGlyph) (value . ,(car e)))
- ((symbol . middleCClefPosition)
- (value . ,(+ oct
- (cadr e)
- (assoc-get (car e) c0-pitch-alist))))
- ((symbol . clefPosition) (value . ,(cadr e)))
- ((symbol . clefOctavation) (value . ,(- oct))))))
- (recalc-mid-C (make-music 'ApplyContext))
- (seq (make-music 'SequentialMusic
- 'elements (append musics (list recalc-mid-C))))
- (csp (make-music 'ContextSpeccedMusic)))
- (set! (ly:music-property recalc-mid-C 'procedure) ly:set-middle-C!)
- (context-spec-music seq 'Staff))
- (begin
- (ly:warning (_ "unknown clef type `~a'") clef-name)
- (ly:warning (_ "supported clefs: ~a")
- (string-join
- (sort (map car supported-clefs) string<?)))
- (make-music 'Music)))))
+ (let ((musics (list
+ (make-property-set 'clefGlyph (car e))
+ (make-property-set 'middleCClefPosition
+ (+ oct (cadr e)
+ (assoc-get (car e) c0-pitch-alist)))
+ (make-property-set 'clefPosition (cadr e))
+ (make-property-set 'clefTransposition (- oct))
+ (make-property-set 'clefTranspositionStyle style)
+ (make-apply-context ly:set-middle-C!))))
+ (context-spec-music (make-sequential-music musics) 'Staff))
+ (begin
+ (ly:warning (_ "unknown clef type `~a'") clef-name)
+ (ly:warning (_ "supported clefs: ~a")
+ (string-join
+ (sort (map car supported-clefs) string<?)))
+ (make-music 'Music)))))
(define-public (make-cue-clef-set clef-name)
"Generate the clef setting commands for a cue clef with name
@var{clef-name}."
- (define (make-prop-set props)
- (let ((m (make-music 'PropertySet)))
- (map (lambda (x) (set! (ly:music-property m (car x)) (cdr x))) props)
- m))
- (let ((e '())
- (c0 0)
- (oct 0)
- (match (string-match "^(.*)([_^])([1-9][0-9]*)$" clef-name)))
- (if match
- (begin
- (set! clef-name (match:substring match 1))
- (set! oct
- (* (if (equal? (match:substring match 2) "^") -1 1)
- (- (string->number (match:substring match 3)) 1)))))
- (set! e (assoc-get clef-name supported-clefs))
- (if e
- (let* ((musics (map make-prop-set
- `(((symbol . cueClefGlyph) (value . ,(car e)))
- ((symbol . middleCCuePosition)
- (value . ,(+ oct
- (cadr e)
- (assoc-get (car e) c0-pitch-alist))))
- ((symbol . cueClefPosition) (value . ,(cadr e)))
- ((symbol . cueClefOctavation) (value . ,(- oct))))))
- (recalc-mid-C (make-music 'ApplyContext))
- (seq (make-music 'SequentialMusic
- 'elements (append musics (list recalc-mid-C))))
- (csp (make-music 'ContextSpeccedMusic)))
- (set! (ly:music-property recalc-mid-C 'procedure) ly:set-middle-C!)
- (context-spec-music seq 'Staff))
- (begin
- (ly:warning (_ "unknown clef type `~a'") clef-name)
- (ly:warning (_ "supported clefs: ~a")
- (string-join
- (sort (map car supported-clefs) string<?)))
- (make-music 'Music)))))
-
+ (define cue-clef-map
+ '((clefGlyph . cueClefGlyph)
+ (middleCClefPosition . middleCCuePosition)
+ (clefPosition . cueClefPosition)
+ (clefTransposition . cueClefTransposition)
+ (clefTranspositionStyle . cueClefTranspositionStyle)))
+ (let ((clef (make-clef-set clef-name)))
+ (for-each
+ (lambda (m)
+ (let ((mapped (assq-ref cue-clef-map
+ (ly:music-property m 'symbol))))
+ (if mapped
+ (set! (ly:music-property m 'symbol) mapped))))
+ (extract-named-music clef 'PropertySet))
+ clef))
(define-public (make-cue-clef-unset)
"Reset the clef settings for a cue clef."
- (define (make-prop-unset props)
- (let ((m (make-music 'PropertyUnset)))
- (set! (ly:music-property m (car props)) (cdr props))
- m))
- (let* ((musics (map make-prop-unset
- `((symbol . cueClefGlyph)
- (symbol . middleCCuePosition)
- (symbol . cueClefPosition)
- (symbol . cueClefOctavation))))
- (recalc-mid-C (make-music 'ApplyContext))
- (seq (make-music 'SequentialMusic
- 'elements (append musics (list recalc-mid-C))))
- (csp (make-music 'ContextSpeccedMusic)))
- (set! (ly:music-property recalc-mid-C 'procedure) ly:set-middle-C!)
- (context-spec-music seq 'Staff)))
-
+ (map-some-music
+ (lambda (m)
+ (and (eq? (ly:music-property m 'name) 'PropertySet)
+ (make-music 'PropertyUnset
+ 'symbol (ly:music-property m 'symbol))))
+ (make-cue-clef-set "treble_(8)")))
;; a function to add new clefs at runtime
-(define-public (add-new-clef clef-name clef-glyph clef-position octavation c0-position)
+(define-public (add-new-clef clef-name clef-glyph clef-position transposition c0-position)
"Append the entries for a clef symbol to supported clefs and
@code{c0-pitch-alist}."
(set! supported-clefs
- (acons clef-name (list clef-glyph clef-position octavation) supported-clefs))
+ (acons clef-name (list clef-glyph clef-position transposition) supported-clefs))
(set! c0-pitch-alist
(acons clef-glyph c0-position c0-pitch-alist)))