1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2000--2010 Jan Nieuwenhuizen <janneke@gnu.org>
4 ;;;; Han-Wen Nienhuys <hanwen@xs4all.nl>
6 ;;;; LilyPond is free software: you can redistribute it and/or modify
7 ;;;; it under the terms of the GNU General Public License as published by
8 ;;;; the Free Software Foundation, either version 3 of the License, or
9 ;;;; (at your option) any later version.
11 ;;;; LilyPond is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;;; GNU General Public License for more details.
16 ;;;; You should have received a copy of the GNU General Public License
17 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
19 (define (natural-chord-alteration p)
20 "Return the natural alteration for step P."
21 (if (= (ly:pitch-steps p) 6)
25 (define (conditional-string-downcase str condition)
31 ;; TODO: make into markup.
33 (define-public (alteration->text-accidental-markup alteration)
37 (if (= alteration FLAT)
40 (make-musicglyph-markup
41 (assoc-get alteration standard-alteration-glyph-name-alist "")))))
43 (define (accidental->markup alteration)
44 "Return accidental markup for ALTERATION."
46 (make-line-markup (list empty-markup))
47 (conditional-kern-before
48 (alteration->text-accidental-markup alteration)
49 (= alteration FLAT) 0.2)))
51 (define (accidental->markup-italian alteration)
52 "Return accidental markup for ALTERATION, for use after an italian chord root name."
54 (make-hspace-markup 0.2)
57 (make-hspace-markup (if (= alteration FLAT) 0.7 0.5))
58 (make-raise-markup 0.7 (alteration->text-accidental-markup alteration))
59 (make-hspace-markup (if (= alteration SHARP) 0.2 0.1))
62 (define-public (note-name->markup pitch lowercase?)
63 "Return pitch markup for PITCH."
67 (conditional-string-downcase
68 (vector-ref #("C" "D" "E" "F" "G" "A" "B") (ly:pitch-notename pitch))
70 (accidental->markup (ly:pitch-alteration pitch)))))
72 (define (pitch-alteration-semitones pitch)
73 (inexact->exact (round (* (ly:pitch-alteration pitch) 2))))
75 (define-safe-public ((chord-name->german-markup B-instead-of-Bb)
77 "Return pitch markup for PITCH, using german note names.
78 If B-instead-of-Bb is set to #t real german names are returned.
79 Otherwise semi-german names (with Bb and below keeping the british names)
81 (let* ((name (ly:pitch-notename pitch))
82 (alt-semitones (pitch-alteration-semitones pitch))
83 (n-a (if (member (cons name alt-semitones) `((6 . -1) (6 . -2)))
84 (cons 7 (+ (if B-instead-of-Bb 1 0) alt-semitones))
85 (cons name alt-semitones))))
89 (conditional-string-downcase
90 (vector-ref #("C" "D" "E" "F" "G" "A" "H" "B") (car n-a))
92 (make-normal-size-super-markup
93 (accidental->markup (/ (cdr n-a) 2)))))))
95 (define-safe-public (note-name->german-markup pitch lowercase?)
96 (let* ((name (ly:pitch-notename pitch))
97 (alt-semitones (pitch-alteration-semitones pitch))
98 (n-a (if (member (cons name alt-semitones) `((6 . -1) (6 . -2)))
99 (cons 7 (+ 1 alt-semitones))
100 (cons name alt-semitones))))
104 (list-ref '("c" "d" "e" "f" "g" "a" "h" "b") (car n-a))
105 (if (or (equal? (car n-a) 2) (equal? (car n-a) 5))
106 (list-ref '( "ses" "s" "" "is" "isis") (+ 2 (cdr n-a)))
107 (list-ref '("eses" "es" "" "is" "isis") (+ 2 (cdr n-a)))))))))
109 (define-public ((chord-name->italian-markup re-with-eacute) pitch lowercase?)
110 "Return pitch markup for PITCH, using italian/french note names.
111 If re-with-eacute is set to #t, french 'ré' is returned for D instead of 're'
113 (let* ((name (ly:pitch-notename pitch))
114 (alt (ly:pitch-alteration pitch)))
118 (conditional-string-downcase
121 #("Do" "Ré" "Mi" "Fa" "Sol" "La" "Si")
122 #("Do" "Re" "Mi" "Fa" "Sol" "La" "Si"))
125 (accidental->markup-italian alt)
128 ;; fixme we should standardize on omit-root (or the other one.)
129 ;; perhaps the default should also be reversed --hwn
130 (define-safe-public (sequential-music-to-chord-exceptions seq . rest)
131 "Transform sequential music SEQ of type <<c d e>>-\\markup{ foobar }
132 to (cons CDE-PITCHES FOOBAR-MARKUP), or to (cons DE-PITCHES
133 FOOBAR-MARKUP) if OMIT-ROOT is given and non-false.
136 (define (chord-to-exception-entry m)
137 (let* ((elts (ly:music-property m 'elements))
138 (omit-root (and (pair? rest) (car rest)))
139 (pitches (map (lambda (x) (ly:music-property x 'pitch))
141 (lambda (y) (memq 'note-event
142 (ly:music-property y 'types)))
144 (sorted (sort pitches ly:pitch<?))
148 ;;(diff (ly:pitch-diff root (ly:make-pitch -1 0 0)))
149 ;; FIXME. This results in #<Pitch c> ...,
150 ;; but that is what we need because default octave for
151 ;; \chords has changed to c' too?
152 (diff (ly:pitch-diff root (ly:make-pitch 0 0 0)))
153 (normalized (map (lambda (x) (ly:pitch-diff x diff)) sorted))
154 (texts (map (lambda (x) (ly:music-property x 'text))
156 (lambda (y) (memq 'text-script-event
157 (ly:music-property y 'types)))
160 (text (if (null? texts) #f (if omit-root (car texts) texts))))
161 (cons (if omit-root (cdr normalized) normalized) text)))
163 (define (is-event-chord? m)
165 (memq 'event-chord (ly:music-property m 'types))
166 (not (equal? ZERO-MOMENT (ly:music-length m)))))
168 (let* ((elts (filter is-event-chord? (ly:music-property seq 'elements)))
169 (alist (map chord-to-exception-entry elts)))
170 (filter (lambda (x) (cdr x)) alist)))