1 (define (natural-chord-alteration p)
2 "Return the natural alteration for step P."
3 (if (= (ly:pitch-steps p) 6)
8 (define-public (alteration->text-accidental-markup alteration)
14 (make-musicglyph-markup
15 (string-append "accidentals-" (number->string alteration))))))
17 (define (accidental->markup alteration)
18 "Return accidental markup for ALTERATION."
20 (make-line-markup (list empty-markup))
21 (conditional-kern-before
22 (alteration->text-accidental-markup alteration)
27 (define-public (note-name->markup pitch)
28 "Return pitch markup for PITCH."
32 (vector-ref #("C" "D" "E" "F" "G" "A" "B") (ly:pitch-notename pitch)))
33 (make-normal-size-super-markup
34 (accidental->markup (ly:pitch-alteration pitch))))))
37 (define-public ((chord-name->german-markup B-instead-of-Bb) pitch)
38 "Return pitch markup for PITCH, using german note names.
39 If B-instead-of-Bb is set to #t real german names are returned.
40 Otherwise semi-german names (with Bb and below keeping the british names)
42 (let* ((name (ly:pitch-notename pitch))
43 (alt (ly:pitch-alteration pitch))
44 (n-a (if (member (cons name alt) '((6 . -1) (6 . -2)))
45 (cons 7 (+ (if B-instead-of-Bb 1 0) alt))
50 (vector-ref #("C" "D" "E" "F" "G" "A" "H" "B") (car n-a)))
51 (make-normal-size-super-markup
52 (accidental->markup (cdr n-a)))))))
55 (define-public (note-name->german-markup pitch)
56 (let* ((name (ly:pitch-notename pitch))
57 (alt (ly:pitch-alteration pitch))
58 (n-a (if (member (cons name alt) '((6 . -1) (6 . -2)))
64 (list-ref '("c" "d" "e" "f" "g" "a" "h" "b") (car n-a))
65 (if (or (equal? (car n-a) 2) (equal? (car n-a) 5))
66 (list-ref '( "ses" "s" "" "is" "isis") (+ 2 (cdr n-a)))
67 (list-ref '("eses" "es" "" "is" "isis") (+ 2 (cdr n-a)))))))))
69 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
72 (define-public (sequential-music-to-chord-exceptions seq)
73 "Transform sequential music of <<a b c>>-\markup{ foobar } type to
74 (cons ABC-PITCHES FOOBAR-MARKUP)
77 (define (is-req-chord? m)
79 (memq 'event-chord (ly:get-mus-property m 'types))
80 (not (equal? (ly:make-moment 0 1) (ly:get-music-length m)))
83 (define (chord-to-exception-entry m)
86 (elts (ly:get-mus-property m 'elements))
89 (ly:get-mus-property x 'pitch)
92 (lambda (y) (memq 'note-event (ly:get-mus-property y 'types)))
94 (sorted (sort pitches ly:pitch<? ))
96 (non-root (map (lambda (x) (ly:pitch-diff x root)) (cdr sorted)))
99 (ly:get-mus-property x 'text)
104 (memq 'text-script-event
105 (ly:get-mus-property y 'types))) elts)
107 (text (if (null? texts)
117 (elts (filter-list is-req-chord? (ly:get-mus-property seq 'elements)))
118 (alist (map chord-to-exception-entry elts))
120 (filter-list (lambda (x) (cdr x)) alist)
124 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
129 ;; after Klaus Ignatzek, Die Jazzmethode fuer Klavier 1.
131 ;; The idea is: split chords into
133 ;; ROOT PREFIXES MAIN-NAME ALTERATIONS SUFFIXES ADDITIONS
135 ;; and put that through a layout routine.
137 ;; the split is a procedural process, with lots of set!.
141 ;; todo: naming is confusing: steps (0 based) vs. steps (1 based).
142 (define (pitch-step p)
143 "Musicological notation for an interval. Eg. C to D is 2."
144 (+ 1 (ly:pitch-steps p)))
146 (define (get-step x ps)
147 "Does PS have the X step? Return that step if it does."
150 (if (= (- x 1) (ly:pitch-steps (car ps)))
152 (get-step x (cdr ps)))
155 (define (replace-step p ps)
156 "Copy PS, but replace the step of P in PS."
161 (t (replace-step p (cdr ps)))
164 (if (= (ly:pitch-steps p) (ly:pitch-steps (car ps)))
171 (define (remove-step x ps)
172 "Copy PS, but leave out the Xth step."
177 (t (remove-step x (cdr ps)))
180 (if (= (- x 1) (ly:pitch-steps (car ps)))
187 (define-public (ignatzek-chord-names
188 in-pitches bass inversion
191 (define (remove-uptil-step x ps)
192 "Copy PS, but leave out everything below the Xth step."
195 (if (< (ly:pitch-steps (car ps)) (- x 1))
196 (remove-uptil-step x (cdr ps))
200 (define name-root (ly:get-context-property context 'chordRootNamer))
202 (let ((nn (ly:get-context-property context 'chordNoteNamer)))
204 ; replacing the next line with name-root gives guile-error...? -rz
205 (ly:get-context-property context 'chordRootNamer)
208 (define (is-natural-alteration? p)
209 (= (natural-chord-alteration p) (ly:pitch-alteration p))
213 (define (ignatzek-format-chord-name
223 "Format for the given (lists of) pitches. This is actually more
224 work than classifying the pitches."
226 (define (filter-main-name p)
227 "The main name: don't print anything for natural 5 or 3."
229 (or (not (ly:pitch? p))
230 (and (is-natural-alteration? p)
231 (or (= (pitch-step p) 5)
232 (= (pitch-step p) 3))))
237 (define (glue-word-to-step word x)
240 (make-simple-markup word)
244 (define (suffix-modifier->markup mod)
245 (if (or (= 4 (pitch-step mod))
246 (= 2 (pitch-step mod)))
247 (glue-word-to-step "sus" mod)
248 (glue-word-to-step "huh" mod)
251 (define (prefix-modifier->markup mod)
252 (if (and (= 3 (pitch-step mod))
253 (= -1 (ly:pitch-alteration mod)))
254 (make-simple-markup "m")
255 (make-simple-markup "huh")
258 (define (filter-alterations alters)
259 "Filter out uninteresting (natural) pitches from ALTERS."
262 (not (is-natural-alteration? p)))
269 (l (filter-list altered? alters))
270 (lp (last-pair alters))
273 ;; we want the highest also if unaltered
274 (if (and (not (altered? (car lp)))
275 (> (pitch-step (car lp)) 5))
276 (append l (last-pair alters))
280 (define (name-step pitch)
281 (define (step-alteration pitch)
282 (- (ly:pitch-alteration pitch)
283 (natural-chord-alteration pitch)
288 (num-markup (make-simple-markup
289 (number->string (pitch-step pitch))))
290 (args (list num-markup))
291 (total (if (= (ly:pitch-alteration pitch) 0)
292 (if (= (pitch-step pitch) 7)
293 (list (ly:get-context-property context 'majorSevenSymbol))
295 (cons (accidental->markup (step-alteration pitch)) args)
299 (make-line-markup total)))
303 (sep (ly:get-context-property context 'chordNameSeparator))
304 (root-markup (name-root root))
305 (add-markups (map (lambda (x)
306 (glue-word-to-step "add" x))
308 (filtered-alterations (filter-alterations alteration-pitches))
309 (alterations (map name-step filtered-alterations))
310 (suffixes (map suffix-modifier->markup suffix-modifiers))
311 (prefixes (map prefix-modifier->markup prefix-modifiers))
312 (main-markups (filter-main-name main-name))
313 (to-be-raised-stuff (markup-join
319 (base-stuff (if bass-pitch
320 (list sep (name-note bass-pitch))
327 (markup-join prefixes sep)
328 (make-super-markup to-be-raised-stuff))
330 (make-line-markup base-stuff)
336 (root (car in-pitches))
337 (pitches (map (lambda (x) (ly:pitch-diff x root)) (cdr in-pitches)))
338 (exceptions (ly:get-context-property context 'chordNameExceptions))
339 (exception (assoc-get-default pitches exceptions #f))
351 (list (name-root root) exception))
353 (begin ; no exception.
355 ; handle sus4 and sus2 suffix: if there is a 3 together with
356 ; sus2 or sus4, then we explicitly say add3.
359 (if (get-step j pitches)
361 (if (get-step 3 pitches)
363 (set! add-steps (cons (get-step 3 pitches) add-steps))
364 (set! pitches (remove-step 3 pitches))
366 (set! suffixes (cons (get-step j pitches) suffixes))
371 ;; do minor-3rd modifier.
372 (if (and (get-step 3 pitches)
373 (= (ly:pitch-alteration (get-step 3 pitches)) -1))
374 (set! prefixes (cons (get-step 3 pitches) prefixes))
377 ;; lazy bum. Should write loop.
379 ((get-step 7 pitches) (set! main-name (get-step 7 pitches)))
380 ((get-step 6 pitches) (set! main-name (get-step 6 pitches)))
381 ((get-step 5 pitches) (set! main-name (get-step 5 pitches)))
382 ((get-step 4 pitches) (set! main-name (get-step 4 pitches)))
383 ((get-step 3 pitches) (set! main-name (get-step 3 pitches)))
388 (3-diff? (lambda (x y)
389 (= (- (pitch-step y) (pitch-step x)) 2)))
390 (split (split-at 3-diff? (remove-uptil-step 5 pitches)))
392 (set! alterations (append alterations (car split)))
393 (set! add-steps (append add-steps (cdr split)))
394 (set! alterations (delq main-name alterations))
395 (set! add-steps (delq main-name add-steps))
397 (if (ly:pitch? inversion)
398 (set! bass-note inversion)
402 (set! bass-note bass)
405 ;; chords with natural (5 7 9 11 13) or leading subsequence.
406 ;; etc. are named by the top pitch, without any further
409 (ly:pitch? main-name)
410 (= 7 (pitch-step main-name))
411 (is-natural-alteration? main-name)
412 (pair? (remove-uptil-step 7 alterations))
413 (reduce (lambda (x y) (and x y))
414 (map is-natural-alteration? alterations)))
416 (set! main-name (tail alterations))
417 (set! alterations '())
420 (ignatzek-format-chord-name root prefixes main-name alterations add-steps suffixes bass-note)