- "Generate the clef setting commands for a clef with name 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 "^(.*)([_^])([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 clef-name supported-clefs))
- (if (pair? e)
- (let* ((musics (map make-prop-set
- `(((symbol . clefGlyph) (value . ,(cadr e)))
- ((symbol . middleCPosition)
- (value . ,(+ oct
- (caddr e)
- (cdr (assoc (cadr e) c0-pitch-alist)))))
- ((symbol . clefPosition) (value . ,(caddr e)))
- ((symbol . clefOctavation) (value . ,(- oct))))))
- (seq (make-music 'SequentialMusic
- 'elements musics))
- (csp (make-music 'ContextSpeccedMusic)))
- (context-spec-music seq 'Staff))
- (begin
- (ly:warning (_ "unknown clef type `~a'") clef-name)
- (ly:warning (_ "see scm/clef.scm for supported clefs"))
- (make-music 'Music)))))
+ "Generate the clef setting commands for a clef with name @var{clef-name}."
+ (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 (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 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."
+ (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)")))