1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2000--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 ;;;; LilyPond is free software: you can redistribute it and/or modify
6 ;;;; it under the terms of the GNU General Public License as published by
7 ;;;; the Free Software Foundation, either version 3 of the License, or
8 ;;;; (at your option) any later version.
10 ;;;; LilyPond is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;;; GNU General Public License for more details.
15 ;;;; You should have received a copy of the GNU General Public License
16 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;; after Klaus Ignatzek, Die Jazzmethode fuer Klavier 1.
27 ;; The idea is: split chords into
29 ;; ROOT PREFIXES MAIN-NAME ALTERATIONS SUFFIXES ADDITIONS
31 ;; and put that through a layout routine.
33 ;; the split is a procedural process, with lots of set!.
37 ;; todo: naming is confusing: steps (0 based) vs. steps (1 based).
38 (define (pitch-step p)
39 "Musicological notation for an interval. Eg. C to D is 2."
40 (+ 1 (ly:pitch-steps p)))
42 (define (get-step x ps)
43 "Does PS have the X step? Return that step if it does."
46 (if (= (- x 1) (ly:pitch-steps (car ps)))
48 (get-step x (cdr ps)))))
50 (define (replace-step p ps)
51 "Copy PS, but replace the step of P in PS."
54 (let* ((t (replace-step p (cdr ps))))
55 (if (= (ly:pitch-steps p) (ly:pitch-steps (car ps)))
59 (define (remove-step x ps)
60 "Copy PS, but leave out the Xth step."
63 (let* ((t (remove-step x (cdr ps))))
64 (if (= (- x 1) (ly:pitch-steps (car ps)))
69 (define-public (ignatzek-chord-names
70 in-pitches bass inversion
73 (define (remove-uptil-step x ps)
74 "Copy PS, but leave out everything below the Xth step."
77 (if (< (ly:pitch-steps (car ps)) (- x 1))
78 (remove-uptil-step x (cdr ps))
81 (define name-root (ly:context-property context 'chordRootNamer))
83 (let ((nn (ly:context-property context 'chordNoteNamer)))
85 ;; replacing the next line with name-root gives guile-error...? -rz
87 ;; apparently sequence of defines is equivalent to let, not let* ? -hwn
88 (ly:context-property context 'chordRootNamer)
92 (define (is-natural-alteration? p)
93 (= (natural-chord-alteration p) (ly:pitch-alteration p)))
95 (define (ignatzek-format-chord-name
104 "Format for the given (lists of) pitches. This is actually more
105 work than classifying the pitches."
107 (define (filter-main-name p)
108 "The main name: don't print anything for natural 5 or 3."
110 (or (not (ly:pitch? p))
111 (and (is-natural-alteration? p)
112 (or (= (pitch-step p) 5)
113 (= (pitch-step p) 3))))
115 (list (name-step p))))
117 (define (glue-word-to-step word x)
120 (make-simple-markup word)
123 (define (suffix-modifier->markup mod)
124 (if (or (= 4 (pitch-step mod))
125 (= 2 (pitch-step mod)))
126 (glue-word-to-step "sus" mod)
127 (glue-word-to-step "huh" mod)))
129 (define (prefix-modifier->markup mod)
130 (if (and (= 3 (pitch-step mod))
131 (= FLAT (ly:pitch-alteration mod)))
132 (make-simple-markup "m")
133 (make-simple-markup "huh")))
135 (define (filter-alterations alters)
136 "Filter out uninteresting (natural) pitches from ALTERS."
139 (not (is-natural-alteration? p)))
144 (let* ((lst (filter altered? alters))
145 (lp (last-pair alters)))
147 ;; we want the highest also if unaltered
148 (if (and (not (altered? (car lp)))
149 (> (pitch-step (car lp)) 5))
150 (append lst (last-pair alters))
153 (define (name-step pitch)
154 (define (step-alteration pitch)
155 (- (ly:pitch-alteration pitch)
156 (natural-chord-alteration pitch)))
158 (let* ((num-markup (make-simple-markup
159 (number->string (pitch-step pitch))))
160 (args (list num-markup))
161 (total (if (= (ly:pitch-alteration pitch) 0)
162 (if (= (pitch-step pitch) 7)
163 (list (ly:context-property context 'majorSevenSymbol))
165 (cons (accidental->markup (step-alteration pitch)) args))))
167 (make-line-markup total)))
169 (let* ((sep (ly:context-property context 'chordNameSeparator))
170 (root-markup (name-root root))
171 (add-markups (map (lambda (x) (glue-word-to-step "add" x))
173 (filtered-alterations (filter-alterations alteration-pitches))
174 (alterations (map name-step filtered-alterations))
175 (suffixes (map suffix-modifier->markup suffix-modifiers))
176 (prefixes (map prefix-modifier->markup prefix-modifiers))
177 (main-markups (filter-main-name main-name))
178 (to-be-raised-stuff (markup-join
184 (base-stuff (if (ly:pitch? bass-pitch)
185 (list sep (name-note bass-pitch))
191 (conditional-kern-before (markup-join prefixes sep)
192 (and (not (null? prefixes))
193 (= (ly:pitch-alteration root) NATURAL))
194 (ly:context-property context 'chordPrefixSpacer))
195 (make-super-markup to-be-raised-stuff))
197 (make-line-markup base-stuff)))
199 (define (ignatzek-format-exception
209 ,(if (ly:pitch? bass-pitch)
210 (list (ly:context-property context 'chordNameSeparator)
211 (name-note bass-pitch))
214 (let* ((root (car in-pitches))
215 (pitches (map (lambda (x) (ly:pitch-diff x root)) (cdr in-pitches)))
216 (exceptions (ly:context-property context 'chordNameExceptions))
217 (exception (assoc-get pitches exceptions))
223 (if (ly:pitch? inversion)
229 (ignatzek-format-exception root exception bass-note)
233 ;; handle sus4 and sus2 suffix: if there is a 3 together with
234 ;; sus2 or sus4, then we explicitly say add3.
237 (if (get-step j pitches)
239 (if (get-step 3 pitches)
241 (set! add-steps (cons (get-step 3 pitches) add-steps))
242 (set! pitches (remove-step 3 pitches))))
243 (set! suffixes (cons (get-step j pitches) suffixes)))))
246 ;; do minor-3rd modifier.
247 (if (and (get-step 3 pitches)
248 (= (ly:pitch-alteration (get-step 3 pitches)) FLAT))
249 (set! prefixes (cons (get-step 3 pitches) prefixes)))
251 ;; lazy bum. Should write loop.
253 ((get-step 7 pitches) (set! main-name (get-step 7 pitches)))
254 ((get-step 6 pitches) (set! main-name (get-step 6 pitches)))
255 ((get-step 5 pitches) (set! main-name (get-step 5 pitches)))
256 ((get-step 4 pitches) (set! main-name (get-step 4 pitches)))
257 ((get-step 3 pitches) (set! main-name (get-step 3 pitches))))
259 (let* ((3-diff? (lambda (x y)
260 (= (- (pitch-step y) (pitch-step x)) 2)))
261 (split (split-at-predicate
262 3-diff? (remove-uptil-step 5 pitches))))
263 (set! alterations (append alterations (car split)))
264 (set! add-steps (append add-steps (cdr split)))
265 (set! alterations (delq main-name alterations))
266 (set! add-steps (delq main-name add-steps))
269 ;; chords with natural (5 7 9 11 13) or leading subsequence.
270 ;; etc. are named by the top pitch, without any further
273 (ly:pitch? main-name)
274 (= 7 (pitch-step main-name))
275 (is-natural-alteration? main-name)
276 (pair? (remove-uptil-step 7 alterations))
277 (reduce (lambda (x y) (and x y)) #t
278 (map is-natural-alteration? alterations)))
280 (set! main-name (last alterations))
281 (set! alterations '())))
283 (ignatzek-format-chord-name
284 root prefixes main-name alterations add-steps suffixes bass-note))))))