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)
26 ;; TODO: make into markup.
28 (define-public (alteration->text-accidental-markup alteration)
32 (if (= alteration FLAT)
35 (make-musicglyph-markup
36 (assoc-get alteration standard-alteration-glyph-name-alist "")))))
38 (define (accidental->markup alteration)
39 "Return accidental markup for ALTERATION."
41 (make-line-markup (list empty-markup))
42 (conditional-kern-before
43 (alteration->text-accidental-markup alteration)
44 (= alteration FLAT) 0.2)))
46 (define (accidental->markup-italian alteration)
47 "Return accidental markup for ALTERATION, for use after an italian chord root name."
49 (make-hspace-markup 0.2)
52 (make-hspace-markup (if (= alteration FLAT) 0.7 0.5))
53 (make-raise-markup 0.7 (alteration->text-accidental-markup alteration))
54 (make-hspace-markup (if (= alteration SHARP) 0.2 0.1))
57 (define-public (note-name->markup pitch)
58 "Return pitch markup for PITCH."
62 (vector-ref #("C" "D" "E" "F" "G" "A" "B") (ly:pitch-notename pitch)))
63 (accidental->markup (ly:pitch-alteration pitch)))))
65 (define (pitch-alteration-semitones pitch)
66 (inexact->exact (round (* (ly:pitch-alteration pitch) 2))))
68 (define-safe-public ((chord-name->german-markup B-instead-of-Bb) pitch)
69 "Return pitch markup for PITCH, using german note names.
70 If B-instead-of-Bb is set to #t real german names are returned.
71 Otherwise semi-german names (with Bb and below keeping the british names)
73 (let* ((name (ly:pitch-notename pitch))
74 (alt-semitones (pitch-alteration-semitones pitch))
75 (n-a (if (member (cons name alt-semitones) `((6 . -1) (6 . -2)))
76 (cons 7 (+ (if B-instead-of-Bb 1 0) alt-semitones))
77 (cons name alt-semitones))))
81 (vector-ref #("C" "D" "E" "F" "G" "A" "H" "B") (car n-a)))
82 (make-normal-size-super-markup
83 (accidental->markup (/ (cdr n-a) 2)))))))
85 (define-safe-public (note-name->german-markup pitch)
86 (let* ((name (ly:pitch-notename pitch))
87 (alt-semitones (pitch-alteration-semitones pitch))
88 (n-a (if (member (cons name alt-semitones) `((6 . -1) (6 . -2)))
89 (cons 7 (+ 1 alt-semitones))
90 (cons name alt-semitones))))
94 (list-ref '("c" "d" "e" "f" "g" "a" "h" "b") (car n-a))
95 (if (or (equal? (car n-a) 2) (equal? (car n-a) 5))
96 (list-ref '( "ses" "s" "" "is" "isis") (+ 2 (cdr n-a)))
97 (list-ref '("eses" "es" "" "is" "isis") (+ 2 (cdr n-a)))))))))
99 (define-public ((chord-name->italian-markup re-with-eacute) pitch)
100 "Return pitch markup for PITCH, using italian/french note names.
101 If re-with-eacute is set to #t, french 'ré' is returned for D instead of 're'
103 (let* ((name (ly:pitch-notename pitch))
104 (alt (ly:pitch-alteration pitch)))
110 #("Do" "Ré" "Mi" "Fa" "Sol" "La" "Si")
111 #("Do" "Re" "Mi" "Fa" "Sol" "La" "Si"))
113 (accidental->markup-italian alt)
116 ;; fixme we should standardize on omit-root (or the other one.)
117 ;; perhaps the default should also be reversed --hwn
118 (define-safe-public (sequential-music-to-chord-exceptions seq . rest)
119 "Transform sequential music SEQ of type <<c d e>>-\\markup{ foobar }
120 to (cons CDE-PITCHES FOOBAR-MARKUP), or to (cons DE-PITCHES
121 FOOBAR-MARKUP) if OMIT-ROOT is given and non-false.
124 (define (chord-to-exception-entry m)
125 (let* ((elts (ly:music-property m 'elements))
126 (omit-root (and (pair? rest) (car rest)))
127 (pitches (map (lambda (x) (ly:music-property x 'pitch))
129 (lambda (y) (memq 'note-event
130 (ly:music-property y 'types)))
132 (sorted (sort pitches ly:pitch<?))
136 ;;(diff (ly:pitch-diff root (ly:make-pitch -1 0 0)))
137 ;; FIXME. This results in #<Pitch c> ...,
138 ;; but that is what we need because default octave for
139 ;; \chords has changed to c' too?
140 (diff (ly:pitch-diff root (ly:make-pitch 0 0 0)))
141 (normalized (map (lambda (x) (ly:pitch-diff x diff)) sorted))
142 (texts (map (lambda (x) (ly:music-property x 'text))
144 (lambda (y) (memq 'text-script-event
145 (ly:music-property y 'types)))
148 (text (if (null? texts) #f (if omit-root (car texts) texts))))
149 (cons (if omit-root (cdr normalized) normalized) text)))
151 (define (is-event-chord? m)
153 (memq 'event-chord (ly:music-property m 'types))
154 (not (equal? ZERO-MOMENT (ly:music-length m)))))
156 (let* ((elts (filter is-event-chord? (ly:music-property seq 'elements)))
157 (alist (map chord-to-exception-entry elts)))
158 (filter (lambda (x) (cdr x)) alist)))