2 ;;; chord-name.scm -- chord name utility functions
4 ;;; source file of the GNU LilyPond music typesetter
6 ;;; (c) 2000--2003 Jan Nieuwenhuizen <janneke@gnu.org>
8 ;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 (define (natural-chord-alteration p)
11 "Return the natural alteration for step P."
12 (if (= (ly:pitch-steps p) 6)
17 (define-public (alteration->text-accidental-markup alteration)
23 (make-musicglyph-markup
24 (string-append "accidentals-" (number->string alteration))))))
26 (define (accidental->markup alteration)
27 "Return accidental markup for ALTERATION."
29 (make-line-markup (list empty-markup))
30 (conditional-kern-before
31 (alteration->text-accidental-markup alteration)
36 (define-public (note-name->markup pitch)
37 "Return pitch markup for PITCH."
41 (vector-ref #("C" "D" "E" "F" "G" "A" "B") (ly:pitch-notename pitch)))
42 (accidental->markup (ly:pitch-alteration pitch)))))
45 (define-public ((chord-name->german-markup B-instead-of-Bb) pitch)
46 "Return pitch markup for PITCH, using german note names.
47 If B-instead-of-Bb is set to #t real german names are returned.
48 Otherwise semi-german names (with Bb and below keeping the british names)
50 (let* ((name (ly:pitch-notename pitch))
51 (alt (ly:pitch-alteration pitch))
52 (n-a (if (member (cons name alt) '((6 . -1) (6 . -2)))
53 (cons 7 (+ (if B-instead-of-Bb 1 0) alt))
58 (vector-ref #("C" "D" "E" "F" "G" "A" "H" "B") (car n-a)))
59 (make-normal-size-super-markup
60 (accidental->markup (cdr n-a)))))))
63 (define-public (note-name->german-markup pitch)
64 (let* ((name (ly:pitch-notename pitch))
65 (alt (ly:pitch-alteration pitch))
66 (n-a (if (member (cons name alt) '((6 . -1) (6 . -2)))
72 (list-ref '("c" "d" "e" "f" "g" "a" "h" "b") (car n-a))
73 (if (or (equal? (car n-a) 2) (equal? (car n-a) 5))
74 (list-ref '( "ses" "s" "" "is" "isis") (+ 2 (cdr n-a)))
75 (list-ref '("eses" "es" "" "is" "isis") (+ 2 (cdr n-a)))))))))
77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
80 ;; fixme we should standardize on omit-root (or the other one.)
81 ;; perhaps the default should also be reversed --hwn
82 (define-public (sequential-music-to-chord-exceptions seq . rest)
83 "Transform sequential music SEQ of type <<c d e>>-\markup{ foobar }
84 to (cons CDE-PITCHES FOOBAR-MARKUP), or to (cons DE-PITCHES
85 FOOBAR-MARKUP) if OMIT-ROOT is given and non-false.
88 (define (chord-to-exception-entry m)
89 (let* ((elts (ly:get-mus-property m 'elements))
90 (omit-root (and (pair? rest) (car rest)))
91 (pitches (map (lambda (x) (ly:get-mus-property x 'pitch))
93 (lambda (y) (memq 'note-event
94 (ly:get-mus-property y 'types)))
96 (sorted (sort pitches ly:pitch<?))
100 ;;(diff (ly:pitch-diff root (ly:make-pitch -1 0 0)))
101 ;; FIXME. This results in #<Pitch c> ...,
102 ;; but that is what we need because default octave for
103 ;; \chords has changed to c' too?
104 (diff (ly:pitch-diff root (ly:make-pitch 0 0 0)))
105 (normalized (map (lambda (x) (ly:pitch-diff x diff)) sorted))
106 (texts (map (lambda (x) (ly:get-mus-property x 'text))
108 (lambda (y) (memq 'text-script-event
109 (ly:get-mus-property y 'types)))
112 (text (if (null? texts) #f (if omit-root (car texts) texts))))
113 (cons (if omit-root (cdr normalized) normalized) text)))
115 (define (is-req-chord? m)
117 (memq 'event-chord (ly:get-mus-property m 'types))
118 (not (equal? (ly:make-moment 0 1) (ly:get-music-length m)))))
120 (let* ((elts (filter is-req-chord? (ly:get-mus-property seq 'elements)))
121 (alist (map chord-to-exception-entry elts)))
122 (filter (lambda (x) (cdr x)) alist)))
125 (define-public (new-chord-name-brew-molecule grob)
128 (ws (ly:get-grob-property grob 'word-space))
129 (markup (ly:get-grob-property grob 'text))
130 (molecule (interpret-markup grob
131 (cons '((word-space . 0.0))
132 (Font_interface::get_property_alist_chain grob))
137 ;; chord names aren't in staffs, so WS is in global staff space.
139 (ly:molecule-combine-at-edge
141 X RIGHT (ly:make-molecule "" (cons 0 ws) '(-1 . 1) )