1 ;;;; chord-name.scm -- chord name utility functions
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2006 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@xs4all.nl>
8 (define (natural-chord-alteration p)
9 "Return the natural alteration for step P."
10 (if (= (ly:pitch-steps p) 6)
15 ;; TODO: make into markup.
17 (define-public (alteration->text-accidental-markup alteration)
21 (if (= alteration FLAT)
24 (make-musicglyph-markup
25 (assoc-get alteration standard-alteration-glyph-name-alist "")))))
27 (define (accidental->markup alteration)
28 "Return accidental markup for ALTERATION."
30 (make-line-markup (list empty-markup))
31 (conditional-kern-before
32 (alteration->text-accidental-markup alteration)
33 (= alteration FLAT) 0.2)))
35 (define (accidental->markup-italian alteration)
36 "Return accidental markup for ALTERATION, for use after an italian chord root name."
38 (make-hspace-markup 0.2)
41 (make-hspace-markup (if (= alteration FLAT) 0.7 0.5))
42 (make-raise-markup 0.7 (alteration->text-accidental-markup alteration))
43 (make-hspace-markup (if (= alteration SHARP) 0.2 0.1))
46 (define-public (note-name->markup pitch)
47 "Return pitch markup for PITCH."
51 (vector-ref #("C" "D" "E" "F" "G" "A" "B") (ly:pitch-notename pitch)))
52 (accidental->markup (ly:pitch-alteration pitch)))))
54 (define (pitch-alteration-semitones pitch)
55 (inexact->exact (round (* (ly:pitch-alteration pitch) 2))))
57 (define-safe-public ((chord-name->german-markup B-instead-of-Bb) pitch)
58 "Return pitch markup for PITCH, using german note names.
59 If B-instead-of-Bb is set to #t real german names are returned.
60 Otherwise semi-german names (with Bb and below keeping the british names)
62 (let* ((name (ly:pitch-notename pitch))
63 (alt-semitones (pitch-alteration-semitones pitch))
64 (n-a (if (member (cons name alt-semitones) `((6 . -1) (6 . -2)))
65 (cons 7 (+ (if B-instead-of-Bb 1 0) alt-semitones))
66 (cons name alt-semitones))))
70 (vector-ref #("C" "D" "E" "F" "G" "A" "H" "B") (car n-a)))
71 (make-normal-size-super-markup
72 (accidental->markup (/ (cdr n-a) 2)))))))
74 (define-safe-public (note-name->german-markup pitch)
75 (let* ((name (ly:pitch-notename pitch))
76 (alt-semitones (pitch-alteration-semitones pitch))
77 (n-a (if (member (cons name alt-semitones) `((6 . -1) (6 . -2)))
78 (cons 7 (+ 1 alt-semitones))
79 (cons name alt-semitones))))
83 (list-ref '("c" "d" "e" "f" "g" "a" "h" "b") (car n-a))
84 (if (or (equal? (car n-a) 2) (equal? (car n-a) 5))
85 (list-ref '( "ses" "s" "" "is" "isis") (+ 2 (cdr n-a)))
86 (list-ref '("eses" "es" "" "is" "isis") (+ 2 (cdr n-a)))))))))
88 (define-public ((chord-name->italian-markup re-with-eacute) pitch)
89 "Return pitch markup for PITCH, using italian/french note names.
90 If re-with-eacute is set to #t, french 'ré' is returned for D instead of 're'
92 (let* ((name (ly:pitch-notename pitch))
93 (alt (ly:pitch-alteration pitch)))
99 #("Do" "Ré" "Mi" "Fa" "Sol" "La" "Si")
100 #("Do" "Re" "Mi" "Fa" "Sol" "La" "Si"))
102 (accidental->markup-italian alt)
105 ;; fixme we should standardize on omit-root (or the other one.)
106 ;; perhaps the default should also be reversed --hwn
107 (define-safe-public (sequential-music-to-chord-exceptions seq . rest)
108 "Transform sequential music SEQ of type <<c d e>>-\\markup{ foobar }
109 to (cons CDE-PITCHES FOOBAR-MARKUP), or to (cons DE-PITCHES
110 FOOBAR-MARKUP) if OMIT-ROOT is given and non-false.
113 (define (chord-to-exception-entry m)
114 (let* ((elts (ly:music-property m 'elements))
115 (omit-root (and (pair? rest) (car rest)))
116 (pitches (map (lambda (x) (ly:music-property x 'pitch))
118 (lambda (y) (memq 'note-event
119 (ly:music-property y 'types)))
121 (sorted (sort pitches ly:pitch<?))
125 ;;(diff (ly:pitch-diff root (ly:make-pitch -1 0 0)))
126 ;; FIXME. This results in #<Pitch c> ...,
127 ;; but that is what we need because default octave for
128 ;; \chords has changed to c' too?
129 (diff (ly:pitch-diff root (ly:make-pitch 0 0 0)))
130 (normalized (map (lambda (x) (ly:pitch-diff x diff)) sorted))
131 (texts (map (lambda (x) (ly:music-property x 'text))
133 (lambda (y) (memq 'text-script-event
134 (ly:music-property y 'types)))
137 (text (if (null? texts) #f (if omit-root (car texts) texts))))
138 (cons (if omit-root (cdr normalized) normalized) text)))
140 (define (is-event-chord? m)
142 (memq 'event-chord (ly:music-property m 'types))
143 (not (equal? ZERO-MOMENT (ly:music-length m)))))
145 (let* ((elts (filter is-event-chord? (ly:music-property seq 'elements)))
146 (alist (map chord-to-exception-entry elts)))
147 (filter (lambda (x) (cdr x)) alist)))