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)
20 (if (= alteration FLAT)
23 (make-musicglyph-markup
24 (assoc-get alteration standard-alteration-glyph-name-alist "")))))
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)
32 (= alteration FLAT) 0.2)))
34 (define (accidental->markup-italian alteration)
35 "Return accidental markup for ALTERATION, for use after an italian chord root name."
37 (make-hspace-markup 0.2)
40 (make-hspace-markup (if (= alteration FLAT) 0.7 0.5))
41 (make-raise-markup 0.7 (alteration->text-accidental-markup alteration))
42 (make-hspace-markup (if (= alteration SHARP) 0.2 0.1))
45 (define-public (note-name->markup pitch)
46 "Return pitch markup for PITCH."
50 (vector-ref #("C" "D" "E" "F" "G" "A" "B") (ly:pitch-notename pitch)))
51 (accidental->markup (ly:pitch-alteration pitch)))))
53 (define (pitch-alteration-semitones pitch)
54 (inexact->exact (round (* (ly:pitch-alteration pitch) 2))))
56 (define-safe-public ((chord-name->german-markup B-instead-of-Bb) pitch)
57 "Return pitch markup for PITCH, using german note names.
58 If B-instead-of-Bb is set to #t real german names are returned.
59 Otherwise semi-german names (with Bb and below keeping the british names)
61 (let* ((name (ly:pitch-notename pitch))
62 (alt-semitones (pitch-alteration-semitones pitch))
63 (n-a (if (member (cons name alt-semitones) `((6 . -1) (6 . -2)))
64 (cons 7 (+ (if B-instead-of-Bb 1 0) alt-semitones))
65 (cons name alt-semitones))))
69 (vector-ref #("C" "D" "E" "F" "G" "A" "H" "B") (car n-a)))
70 (make-normal-size-super-markup
71 (accidental->markup (/ (cdr n-a) 2)))))))
73 (define-safe-public (note-name->german-markup pitch)
74 (let* ((name (ly:pitch-notename pitch))
75 (alt-semitones (pitch-alteration-semitones pitch))
76 (n-a (if (member (cons name alt-semitones) `((6 . -1) (6 . -2)))
77 (cons 7 (+ 1 alt-semitones))
78 (cons name alt-semitones))))
82 (list-ref '("c" "d" "e" "f" "g" "a" "h" "b") (car n-a))
83 (if (or (equal? (car n-a) 2) (equal? (car n-a) 5))
84 (list-ref '( "ses" "s" "" "is" "isis") (+ 2 (cdr n-a)))
85 (list-ref '("eses" "es" "" "is" "isis") (+ 2 (cdr n-a)))))))))
87 (define-public ((chord-name->italian-markup re-with-eacute) pitch)
88 "Return pitch markup for PITCH, using italian/french note names.
89 If re-with-eacute is set to #t, french 'ré' is returned for D instead of 're'
91 (let* ((name (ly:pitch-notename pitch))
92 (alt (ly:pitch-alteration pitch)))
98 #("Do" "Ré" "Mi" "Fa" "Sol" "La" "Si")
99 #("Do" "Re" "Mi" "Fa" "Sol" "La" "Si"))
101 (accidental->markup-italian alt)
104 ;; fixme we should standardize on omit-root (or the other one.)
105 ;; perhaps the default should also be reversed --hwn
106 (define-safe-public (sequential-music-to-chord-exceptions seq . rest)
107 "Transform sequential music SEQ of type <<c d e>>-\\markup{ foobar }
108 to (cons CDE-PITCHES FOOBAR-MARKUP), or to (cons DE-PITCHES
109 FOOBAR-MARKUP) if OMIT-ROOT is given and non-false.
112 (define (chord-to-exception-entry m)
113 (let* ((elts (ly:music-property m 'elements))
114 (omit-root (and (pair? rest) (car rest)))
115 (pitches (map (lambda (x) (ly:music-property x 'pitch))
117 (lambda (y) (memq 'note-event
118 (ly:music-property y 'types)))
120 (sorted (sort pitches ly:pitch<?))
124 ;;(diff (ly:pitch-diff root (ly:make-pitch -1 0 0)))
125 ;; FIXME. This results in #<Pitch c> ...,
126 ;; but that is what we need because default octave for
127 ;; \chords has changed to c' too?
128 (diff (ly:pitch-diff root (ly:make-pitch 0 0 0)))
129 (normalized (map (lambda (x) (ly:pitch-diff x diff)) sorted))
130 (texts (map (lambda (x) (ly:music-property x 'text))
132 (lambda (y) (memq 'text-script-event
133 (ly:music-property y 'types)))
136 (text (if (null? texts) #f (if omit-root (car texts) texts))))
137 (cons (if omit-root (cdr normalized) normalized) text)))
139 (define (is-event-chord? m)
141 (memq 'event-chord (ly:music-property m 'types))
142 (not (equal? ZERO-MOMENT (ly:music-length m)))))
144 (let* ((elts (filter is-event-chord? (ly:music-property seq 'elements)))
145 (alist (map chord-to-exception-entry elts)))
146 (filter (lambda (x) (cdr x)) alist)))