2 ;;; chord-name.scm -- Compile chord name
4 ;;; source file of the GNU LilyPond music typesetter
6 ;;; (c) 2000--2002 Jan Nieuwenhuizen <janneke@gnu.org>
17 ;; pitch = (octave notename accidental)
19 ;; note = (notename . accidental)
21 ;; text = scm markup text -- see font.scm and input/test/markup.ly
26 ;; Ugh : naming chord::... ; this is scheme not C++
28 ;; * easier tweakability:
29 ;; - split chord::names-alists up into logical bits,
30 ;; such as chord::exceptions-delta, exceptions-oslash
31 ;; - iso just the 'style parameter, use a list, eg:
32 ;; \property ChordNames.ChordName \set
33 ;; #'style = #'(jazz delta oslash german-tonic german-Bb)
37 ;; * clean split/merge of bass/banter/american stuff
41 (define-public chord::names-alist-banter '())
42 (set! chord::names-alist-banter
48 (((0 . 0) (2 . 0)) . #f)
50 (((0 . 0) (2 . -1)) . ("m"))
52 (((0 . 0) (1 . 0) (4 . 0)) . ("" (super "2") " "))
54 (((0 . 0) (3 . 0) (4 . 0)) . ("" (super "4") " " ))
56 (((0 . 0) (2 . -1) (4 . -1)) . ("dim"))
57 ; URG: Simply C:m5-/maj7 iso Cdim maj7
58 (((0 . 0) (2 . -1) (4 . -1) (6 . 0)) . ("m" (super "5-/maj7" " ")))
59 ; URG: Simply C:m5-/7 iso Cdim7
60 (((0 . 0) (2 . -1) (4 . -1) (6 . -1)) . ("m" (super "5-/7" " ")))
62 (((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . ("" (super "o") " "))
64 (((0 . 0) (2 . -1) (4 . -1) (6 . -2) (1 . -1)) . ("dim" (super "9") " "))
65 (((0 . 0) (2 . -1) (4 . -1) (6 . -2) (1 . -1) (3 . -1)) . ("dim" (super "11") " "))
67 chord::names-alist-banter))
71 ;; duh, no docstrings for
72 ;; "No real superscript, just raised and small"
73 '((raise . 1) (font-relative-size . -2)))
75 (define (accidental->textp acc pos)
78 (list '(music (font-relative-size . -2))
79 (list pos (string-append "accidentals-" (number->string acc))))))
81 (define (accidental->text acc) (accidental->textp acc 'columns))
82 (define (accidental->text-super acc) (accidental->textp acc 'simple-super))
83 (define (accidental->text-sub acc) (accidental->textp acc 'sub))
85 (define (pitch->note-name pitch)
86 (cons (cadr pitch) (caddr pitch)))
88 (define (pitch->text pitch)
91 '(font-relative-size . 2)
92 (make-string 1 (integer->char (+ (modulo (+ (cadr pitch) 2) 7) 65))))
93 (accidental->text-super (caddr pitch))))
96 ;;; Hooks to override chord names and note names,
97 ;;; see input/tricks/german-chords.ly
99 (define (pitch->text-banter pitch)
102 ;; We need also steps, to allow for Cc name override,
103 ;; see input/test/Cc-chords.ly
104 (define (pitch->chord-name-text-banter pitch steps)
105 (pitch->text-banter pitch))
107 (define (pitch->note-name-text-banter pitch)
108 (pitch->text-banter pitch))
110 (define (step->text pitch)
112 (number->string (+ (cadr pitch) (if (= (car pitch) 0) 1 8)))
120 (define (step->text-banter pitch)
121 (if (= (cadr pitch) 6)
130 (define pitch::semitone-vec (list->vector '(0 2 4 5 7 9 11)))
132 (define (pitch::semitone pitch)
133 (+ (* (car pitch) 12)
134 (vector-ref pitch::semitone-vec (modulo (cadr pitch) 7))
137 (define (pitch::< l r)
138 (< (pitch::semitone l) (pitch::semitone r)))
140 (define (pitch::transpose pitch delta)
141 (let ((simple-octave (+ (car pitch) (car delta)))
142 (simple-notename (+ (cadr pitch) (cadr delta))))
143 (let ((octave (+ simple-octave (quotient simple-notename 7)))
144 (notename (modulo simple-notename 7)))
145 (let ((accidental (- (+ (pitch::semitone pitch) (pitch::semitone delta))
146 (pitch::semitone `(,octave ,notename 0)))))
147 `(,octave ,notename ,accidental)))))
149 (define (pitch::diff pitch tonic)
150 (let ((simple-octave (- (car pitch) (car tonic)))
151 (simple-notename (- (cadr pitch) (cadr tonic))))
152 (let ((octave (+ simple-octave (quotient simple-notename 7)
153 (if (< simple-notename 0) -1 0)))
154 (notename (modulo simple-notename 7)))
155 (let ((accidental (- (pitch::semitone pitch)
156 (pitch::semitone tonic)
157 (pitch::semitone `(,octave ,notename 0)))))
158 `(,octave ,notename ,accidental)))))
160 (define (pitch::note-pitch pitch)
161 (+ (* (car pitch) 7) (cadr pitch)))
163 (define (chord::text? text)
164 (not (or (not text) (null? text) (unspecified? text))))
166 ;; FIXME: remove need for me, use text-append throughout
167 (define (chord::text-cleanup dirty)
169 Recursively remove '() #f, and #<unspecified> from markup text tree.
170 This allows us to leave else parts of (if # #) off.
171 Otherwise, you'd have to do (if # # '()), and you'd have to
172 filter-out the '() anyway.
175 (let ((r (car dirty)))
177 (cons (if (pair? r) (chord::text-cleanup r) r)
178 (chord::text-cleanup (cdr dirty)))
179 (chord::text-cleanup (cdr dirty))))
180 (if (chord::text? dirty)
184 (define (text-append l . r)
185 (if (not (chord::text? r))
187 (if (not (chord::text? l))
190 (list 'columns l (car r))
191 (text-append (list 'columns l (car r)) (cdr r))))))
193 (define (chord::step tonic pitch)
194 (- (pitch::note-pitch pitch) (pitch::note-pitch tonic)))
196 ;; text: list of word
197 ;; word: string + optional list of property
198 ;; property: axis, kern, font (?), size
200 (define chord::minor-major-vec (list->vector '(0 -1 -1 0 -1 -1 0)))
203 ;; compute the relative-to-tonic pitch that goes with 'step'
204 (define (chord::step-pitch tonic step)
205 ;; urg, we only do this for thirds
206 (if (= (modulo step 2) 0)
208 (let loop ((i 1) (pitch tonic))
212 pitch `(0 2 ,(vector-ref chord::minor-major-vec
213 ;; -1 (step=1 -> vector=0) + 7 = 6
214 (modulo (+ i 6) 7)))))))))
216 (define (chord::additions steps)
218 * any even step (2, 4, 6)
219 * any uneven step that is chromatically altered,
220 (where 7-- == -1, 7- == 0, 7 == +1)
223 ?and jazz needs also:
225 * TODO: any uneven step that's lower than an uneven step which is
226 chromatically altered
228 (let ((evens (filter-list (lambda (x) (!= 0 (modulo (cadr x) 2))) steps))
230 (filter-list (lambda (x)
231 (let ((n (cadr x)) (a (caddr x)))
232 (or (and (= 6 n) (!= -1 a))
237 (highest (let ((h (car (last-pair steps))))
238 (if (and (not (null? h))
243 ;; Hmm, what if we have a step twice, can we ignore that?
244 (uniq-list (sort (apply append evens altered-unevens highest)
248 ;; FIXME: unLOOP, see ::additions
249 ;; find the pitches that are missing from `normal' chord
250 (define (chord::subtractions chord-pitches)
251 (let ((tonic (car chord-pitches)))
252 (let loop ((step 1) (pitches chord-pitches) (subtractions '()))
254 (let* ((pitch (car pitches))
255 (p-step (+ (- (pitch::note-pitch pitch)
256 (pitch::note-pitch tonic))
258 ;; pitch is an subtraction if
259 ;; a step is missing or
261 (loop (+ step 2) pitches
262 (cons (chord::step-pitch tonic step) subtractions))
263 ;; there are no pitches left, but base thirds are not yet done and
265 (= (length pitches) 1))
266 ;; present pitch is not missing step
268 (loop (+ step 2) pitches subtractions)
269 (loop (+ step 2) pitches
270 (cons (chord::step-pitch tonic step) subtractions)))
272 (loop (+ step 2) (cdr pitches) subtractions)
273 (loop step (cdr pitches) subtractions)))))
274 (reverse subtractions)))))
276 (define (chord::additions->text-banter additions subtractions)
277 (if (pair? additions)
279 (let ((step (step->text-banter (car additions))))
280 (if (or (pair? (cdr additions))
281 (pair? subtractions))
282 (text-append step "/")
284 (chord::additions->text-banter (cdr additions) subtractions))
287 (define (chord::subtractions->text-banter subtractions)
288 (if (pair? subtractions)
291 (let ((step (step->text-jazz (car subtractions))))
292 (if (pair? (cdr subtractions))
293 (text-append step "/")
295 (chord::subtractions->text-banter (cdr subtractions)))
298 (define (chord::bass-and-inversion->text-banter bass-and-inversion)
299 (if (and (pair? bass-and-inversion)
300 (or (car bass-and-inversion)
301 (cdr bass-and-inversion)))
302 (list "/" (if (car bass-and-inversion)
303 (pitch->note-name-text-banter
304 (car bass-and-inversion))
305 (pitch->note-name-text-banter
306 (cdr bass-and-inversion))))))
308 ;; FIXME: merge this function with inner-name-jazz, -american
309 ;; iso using chord::bass-and-inversion->text-banter,
310 ;; call (chord::restyle 'chord::bass-and-inversion->text- style)
311 ;; See: chord::exceptions-lookup
314 ;; Combine tonic, exception-part of chord name,
315 ;; additions, subtractions and bass or inversion into chord name
316 (define (chord::inner-name-banter tonic exception-part additions subtractions
317 bass-and-inversion steps)
318 (let* ((tonic-text (pitch->chord-name-text-banter tonic steps))
319 (except-text exception-part)
320 (sep-text (if (and (string-match "super" (format "~s" except-text))
321 (or (pair? additions)
322 (pair? subtractions)))
323 (list simple-super "/")))
324 (adds-text (chord::additions->text-banter additions subtractions))
325 (subs-text (chord::subtractions->text-banter subtractions))
326 (b+i-text (chord::bass-and-inversion->text-banter bass-and-inversion)))
328 tonic-text except-text sep-text
329 ;;(list (list simple-super) adds-text subs-text)
330 (list (list '((raise . 1) (font-relative-size . -1))) adds-text subs-text)
333 (define (c++-pitch->scm p)
335 (list (ly:pitch-octave p) (ly:pitch-notename p) (ly:pitch-alteration p))
338 (define-public (chord::name-banter tonic exception-part unmatched-steps
339 bass-and-inversion steps)
340 (let ((additions (chord::additions unmatched-steps))
341 (subtractions (chord::subtractions unmatched-steps)))
342 (chord::inner-name-banter tonic exception-part additions subtractions
343 bass-and-inversion steps)))
346 (define (chord::restyle name style)
347 (primitive-eval (string->symbol
348 (string-append (symbol->string name)
349 (symbol->string style)))))
351 ;; check exceptions-alist for biggest matching part of try-steps
352 ;; return (MATCHED-EXCEPTION . UNMATCHED-STEPS)
353 (define (chord::exceptions-lookup-helper
354 exceptions-alist try-steps unmatched-steps exception-part)
355 (if (pair? try-steps)
356 ;; FIXME: junk '(0 . 0) from exceptions lists?
357 ;; if so: how to handle first '((0 . 0) . #f) entry?
359 ;; FIXME: either format exceptions list as real pitches, ie,
360 ;; including octave '((0 2 -1) ..), or drop octave
361 ;; from rest of calculations,
363 (map (lambda (x) (pitch->note-name x))
364 (append '((0 0 0)) try-steps))
367 (chord::exceptions-lookup-helper
368 #f '() unmatched-steps (cdr entry))
369 (let ((r (reverse try-steps)))
370 (chord::exceptions-lookup-helper
373 (cons (car r) unmatched-steps) #f))))
374 (cons exception-part unmatched-steps)))
376 ;; return (MATCHED-EXCEPTION . BASE-CHORD-WITH-UNMATCHED-STEPS)
377 ;; BASE-CHORD-WITH-UNMATCHED-STEPS always includes (tonic 3 5)
378 (define (chord::exceptions-lookup style steps)
379 (let* ((result (chord::exceptions-lookup-helper
380 (chord::restyle 'chord::names-alist- style)
382 (exception-part (car result))
383 (unmatched-steps (cdr result))
384 (matched-steps (if (= (length unmatched-steps) 0)
386 (+ 1 (- (length steps)
387 (length unmatched-steps)))))
388 (unmatched-with-1-3-5
389 (append (do ((i matched-steps (- i 1))
390 (base '() (cons `(0 ,(* (- i 1) 2) 0) base)))
394 (list exception-part unmatched-with-1-3-5)))
397 (define (chord::name->text style tonic steps bass-and-inversion)
398 (let* ((lookup (chord::exceptions-lookup style steps))
399 (exception-part (car lookup))
400 (unmatched-steps (cadr lookup)))
402 ((chord::restyle 'chord::name- style)
403 tonic exception-part unmatched-steps bass-and-inversion steps))))
407 ;; Check for each subset of chord, full chord first, if there's a
408 ;; user-override. Split the chord into user-overridden and to-be-done
409 ;; parts, complete the missing user-override matched part with normal
410 ;; chord to be name-calculated.
412 ;; CHORD: (pitches (bass . inversion))
413 (define-public (default-chord-name-function style chord)
414 (let* ((pitches (map c++-pitch->scm (car chord)))
415 (modifiers (cdr chord))
416 (bass-and-inversion (if (pair? modifiers)
417 (cons (c++-pitch->scm (car modifiers))
418 (c++-pitch->scm (cdr modifiers)))
420 (diff (pitch::diff '(0 0 0) (car pitches)))
421 (steps (if (cdr pitches) (map (lambda (x)
422 (pitch::transpose x diff))
425 ; (display (chord::name->text style (car pitches) steps bass-and-inversion))
426 (chord::name->text style (car pitches) steps bass-and-inversion)
436 ;; NOTE: Duplicates of chord names defined elsewhere occur in this list
437 ;; in order to prevent spurious superscripting of various chord names,
438 ;; such as maj7, maj9, etc.
440 ;; See input/test/american-chords.ly
442 ;; James Hammons, <jlhamm@pacificnet.net>
445 ;; DONT use non-ascii characters, even if ``it works'' in Windows
447 (define-public chord::names-alist-american '())
449 (set! chord::names-alist-american
453 (((0 . 0) (2 . 0)) . #f)
455 (((0 . 0) (4 . 0)) . ("5"))
457 (((0 . 0) (2 . -1)) . ("m"))
458 (((0 . 0) (3 . 0) (4 . 0)) . ("sus"))
459 (((0 . 0) (2 . -1) (4 . -1)) . ("dim"))
460 ;Alternate: (((0 . 0) (2 . -1) (4 . -1)) . ("" (super "o")))
461 (((0 . 0) (2 . 0) (4 . 1)) . ("aug"))
462 ;Alternate: (((0 . 0) (2 . 0) (4 . 1)) . ("+"))
463 (((0 . 0) (1 . 0) (4 . 0)) . ("2"))
464 ;; Common seventh chords
465 (((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . ("" (super "o") " " "7"))
466 (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . ("maj7"))
467 ;; urg! should use (0 . 0 2 . -1) -> "m", and add "7" to that!!
468 (((0 . 0) (2 . -1) (4 . 0) (6 . -1)) . ("m7"))
469 (((0 . 0) (2 . 0) (4 . 0) (6 . -1)) . ("7"))
470 (((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . ("m(maj7)"))
471 ;jazz: the delta, see jazz-chords.ly
472 ;;(((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . (super ((font-family . math) "N"))
474 (((0 . 0) (2 . -1) (4 . -1) (6 . -1)) . (columns (super (overstrike "o") "/") " " "7"))
476 (((0 . 0) (2 . 0) (4 . 1) (6 . -1)) . ("aug7"))
477 (((0 . 0) (2 . 0) (4 . -1) (6 . 0)) . (columns "maj7" ((font-relative-size . -2) ((raise . 0.2) (music (named "accidentals--1")))) "5"))
478 (((0 . 0) (2 . 0) (4 . -1) (6 . -1)) . (columns "7" ((font-relative-size . -2) ((raise . 0.2) (music (named "accidentals--1")))) "5"))
479 (((0 . 0) (3 . 0) (4 . 0) (6 . -1)) . ("7sus4"))
480 ;; Common ninth chords
481 (((0 . 0) (2 . 0) (4 . 0) (5 . 0) (1 . 0)) . ("6/9")) ;; we don't want the '/no7'
482 (((0 . 0) (2 . 0) (4 . 0) (5 . 0)) . ("6"))
483 (((0 . 0) (2 . -1) (4 . 0) (5 . 0)) . ("m6"))
484 (((0 . 0) (2 . 0) (4 . 0) (1 . 0)) . ("add9"))
485 (((0 . 0) (2 . 0) (4 . 0) (6 . 0) (1 . 0)) . ("maj9"))
486 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . 0)) . ("9"))
487 (((0 . 0) (2 . -1) (4 . 0) (6 . -1) (1 . 0)) . ("m9"))
490 chord::names-alist-american))
493 ;; American style chordnames use no "no",
494 ;; but otherwise very similar to banter for now
495 (define-public (chord::name-american tonic exception-part unmatched-steps
496 bass-and-inversion steps)
497 (let ((additions (chord::additions unmatched-steps))
499 (chord::inner-name-banter tonic exception-part additions subtractions
500 bass-and-inversion steps)))
510 ;; Jazz chords, by Atte Andr'e Jensen <atte@post.com>
511 ;; NBs: This uses the american list as a bass.
512 ;; Some defs take up more than one line,
513 ;; be carefull when messing with ;'s!!
518 ;; This is getting out-of hand? Only exceptional chord names that
519 ;; cannot be generated should be here.
520 ;; Maybe we should have inner-name-jazz and inner-name-american functions;
524 ;; DONT use non-ascii characters, even if ``it works'' in Windows
526 (define-public chord::names-alist-jazz '())
527 (set! chord::names-alist-jazz
531 ; major sixth chord = 6
532 (((0 . 0) (2 . 0) (4 . 0) (5 . 0)) . (((raise . 0.5) "6")))
533 ; major seventh chord = triangle
534 ;; shouldn't this be a filled black triange, like this: ? --jcn
535 ;; (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . (((raise . 0.5)((font-family . math) "N"))))
536 (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . (((raise . 0.5)((font-family . math) "M"))))
537 ; major chord add nine = add9
538 (((0 . 0) (2 . 0) (4 . 0) (1 . 0)) . (((raise . 0.5) "add9")))
539 ; major sixth chord with nine = 6/9
540 (((0 . 0) (2 . 0) (4 . 0) (5 . 0) (1 . 0)) . (((raise . 0.5) "6/9")))
543 ; minor sixth chord = m6
544 (((0 . 0) (2 . -1) (4 . 0) (5 . 0)) . (columns("m")((raise . 0.5) "6")))
545 ;; minor major seventh chord = m triangle
546 ;; shouldn't this be a filled black triange, like this: ? --jcn
547 ;;(((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . (columns ("m") ((raise . 0.5)((font-family . math) "N"))))
548 (((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . (columns ("m") ((raise . 0.5)((font-family . math) "M"))))
549 ; minor seventh chord = m7
550 (((0 . 0) (2 . -1) (4 . 0) (6 . -1)) . (columns("m")((raise . 0.5) "7")))
551 ; minor sixth nine chord = m6/9
552 (((0 . 0) (2 . -1) (4 . 0) (5 . 0) (1 . 0)) . (columns("m")((raise . 0.5) "6/9")))
553 ; minor with added nine chord = madd9
554 (((0 . 0) (2 . -1) (4 . 0) (1 . 0)) . (columns("m")((raise . 0.5) "add9")))
555 ; minor ninth chord = m9
556 (((0 . 0) (2 . -1) (4 . 0) (6 . -1) (1 . 0)) . (columns("m")((raise . 0.5) "9")))
559 ; dominant seventh = 7
560 (((0 . 0) (2 . 0) (4 . 0) (6 . -1)) . (((raise . 0.5) "7")))
561 ; augmented dominant = +7
562 ;(((0 . 0) (2 . 0) (4 . +1) (6 . -1)) . (((raise . 0.5) "+7"))) ; +7 with both raised
563 (((0 . 0) (2 . 0) (4 . +1) (6 . -1)) . (columns("+")((raise . 0.5) "7"))) ; +7 with 7 raised
564 ;(((0 . 0) (2 . 0) (4 . +1) (6 . -1)) . (columns((raise . 0.5) "7(")
565 ; ((raise . 0.3)(music (named ("accidentals-1"))))
566 ; ((raise . 0.5) "5)"))); 7(#5)
567 ; dominant flat 5 = 7(b5)
568 (((0 . 0) (2 . 0) (4 . -1) (6 . -1)) . (columns((raise . 0.5) "7(")
569 ((raise . 0.3)(music (named ("accidentals--1"))))
570 ((raise . 0.5) "5)")))
572 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . 0)) . (((raise . 0.8)"7(9)")))
573 ; dominant flat 9 = 7(b9)
574 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . -1)) . (
576 ((raise . 0.3)(music (named ("accidentals--1"))))
577 ((raise . 0.8)"9)")))
578 ; dominant sharp 9 = 7(#9)
579 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . +1)) . (
581 ((raise . 0.3)(music (named ("accidentals-1"))))
582 ((raise . 0.8)"9)")))
583 ; dominant 13 = 7(13)
584 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (5 . 0)) . (((raise . 0.8)"7(13)")))
585 ; dominant flat 13 = 7(b13)
586 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (5 . -1)) . (
588 ((raise . 0.3)(music (named ("accidentals--1"))))
589 ((raise . 0.8)"13)")))
590 ; dominant 9, 13 = 7(9,13)
591 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . 0) (5 . 0)) . (((raise . 0.8)"7(9, 13)")))
592 ; dominant flat 9, 13 = 7(b9,13)
593 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . -1) (5 . 0)) . (
595 ((raise . 0.3)(music (named ("accidentals--1"))))
596 ((raise . 0.8)"9, 13)")))
597 ; dominant sharp 9, 13 = 7(#9,13)
598 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . +1) (5 . 0)) . (
600 ((raise . 0.3)(music (named ("accidentals-1"))))
601 ((raise . 0.8)"9, 13)")))
602 ; dominant 9, flat 13 = 7(9,b13)
603 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . 0) (5 . -1)) . (
604 ((raise . 0.8)"7(9, ")
605 ((raise . 0.3)(music (named ("accidentals--1"))))
606 ((raise . 0.8)"13)")))
607 ; dominant flat 9, flat 13 = 7(b9,b13)
608 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . -1) (5 . -1)) . (
610 ((raise . 0.3)(music (named ("accidentals--1"))))
612 ((raise . 0.3)(music (named ("accidentals--1"))))
613 ((raise . 0.8)"13)")))
614 ; dominant sharp 9, flat 13 = 7(#9,b13)
615 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . +1) (5 . -1)) . (
617 ((raise . 0.3)(music (named ("accidentals-1"))))
619 ((raise . 0.3)(music (named ("accidentals--1"))))
620 ((raise . 0.8)"13)")))
622 ;; diminished chord(s)
623 ; diminished seventh chord = o
626 ;; DONT use non-ascii characters, even if ``it works'' in Windows
628 ;;(((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . ((raise . 0.8) (size . -2) ("o")))
629 (((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . ("" (super "o")))
631 ;; half diminshed chords
632 ;; half diminished seventh chord = slashed o
633 ;; (((0 . 0) (2 . -1) (4 . -1) (6 . -1)) . (((raise . 0.8) "/o")))
634 (((0 . 0) (2 . -1) (4 . -1) (6 . -1)) . (columns (super (overstrike "o") "/") " " "7")) ; slashed o
636 ; half diminished seventh chord with major 9 = slashed o cancelation 9
637 (((0 . 0) (2 . -1) (4 . -1) (6 . -1) (1 . 0)) . (
639 ((raise . 0.3)(music (named ("accidentals-0"))))
640 ((raise . 0.8)"9)")));
642 ;; Missing jazz chord definitions go here (note new syntax: see american for hints)
645 chord::names-alist-american))
647 (define (step->text-alternate-jazz pitch)
649 (accidental->text (caddr pitch))
650 (number->string (+ (cadr pitch) (if (= (car pitch) 0) 1 8)))))
652 (define (step->text-jazz pitch)
653 (if (= (cadr pitch) 6)
655 ;; sharp 7 only included for completeness?
656 ((-2) (text-append (accidental->text -1) '("7")))
659 ((1) (text-append (accidental->text-super 1) '("7")))
660 ((2) (text-append (accidental->text-super 2) '("7"))))
661 (step->text-alternate-jazz pitch)))
663 (define (xchord::additions->text-jazz additions subtractions)
664 (if (pair? additions)
666 (let ((step (step->text-jazz (car additions))))
667 (if (or (pair? (cdr additions))
668 (pair? subtractions))
669 (text-append step "/")
671 (chord::additions->text-jazz (cdr additions) subtractions))
674 (define (chord::>5? x)
680 ;; Perhaps all logic like this should be done earlier,
681 ;; so that in this text-construction printing phase
682 ;; we can just blindly create text from all additions.
684 ;; This depends maybe on the fact of code sharing,
685 ;; in this layout, we can share the functions chord::additions
686 ;; and chord::subtractions with banter.
687 (define (chord::additions->text-jazz additions subtractions)
689 (chord::additions<=5->text-jazz (filter-out-list chord::>5? additions)
690 (filter-out-list chord::>5? subtractions))
691 (chord::additions>5->text-jazz (filter-list chord::>5? additions)
692 (filter-list chord::>5? subtractions))))
695 (define (chord::additions<=5->text-jazz additions subtractions)
696 (let ((sus (chord::sus-four-jazz additions)))
698 (text-append '("sus") (step->text-jazz (car sus)))
701 (define (chord::additions>5->text-jazz additions subtractions)
703 Compose text of all additions
705 * if there's a subtraction:
707 - list all up to highest
708 * list all steps that are below an chromatically altered step
711 (if (not (null? subtractions)) "add" '())
712 (let ((radds (reverse additions)))
713 (reverse (chord::additions>5->text-jazz-helper
716 (if (or (null? subtractions) (null? radds))
719 (define (chord::additions>5->text-jazz-helper additions subtractions list-step)
721 Create texts for all additions
722 If list-step != #f, list all steps down to 5
723 If we encounter a chromatically altered step, turn on list-step
727 (if (not (member list-step subtractions))
728 (if (> 5 (cadr list-step))
729 (cons (step->text-jazz list-step)
730 (chord::additions>5->text-jazz-helper
733 (chord::get-create-step additions
734 (- (cadr list-step) 2))))
735 (step->text-jazz list-step))
736 (chord::get-create-step additions (- (cadr list-step) 2)))
737 (if (pair? additions)
738 (let ((step (car additions)))
739 (cons (step->text-jazz step)
740 (chord::additions>5->text-jazz-helper
743 (if (or (and (!= 6 (cadr step)) (!= 0 (caddr step)))
744 (and (= 6 (cadr step)) (!= -1 (caddr step))))
745 (chord::get-create-step additions (- (cadr step) 2))
749 (define (chord::sus-four-jazz chord-pitches)
750 "List of pitches that are step 2 or step 4"
751 (filter-list (lambda (x)
753 (or (= 1 (cadr x)) (= 3 (cadr x))))) chord-pitches))
755 (define (chord::get-create-step steps n)
756 (let* ((i (if (< n 0) (+ n 7) n))
757 (found (filter-list (lambda (x) (= i (cadr x))) steps)))
764 (define (chord::subtractions->text-jazz subtractions)
765 (if (pair? subtractions)
767 (if (= 5 (cadr (car subtractions)))
770 (let ((step (step->text-jazz (car subtractions))))
771 (if (pair? (cdr subtractions))
772 (text-append step "/")
775 (chord::subtractions->text-jazz (cdr subtractions)))
779 ;; TODO: maybe merge with inner-name-banter
780 ;; Combine tonic, exception-part of chord name,
781 ;; additions, subtractions and bass or inversion into chord name
782 (define (chord::inner-name-jazz tonic exception-part additions subtractions
783 bass-and-inversion steps)
785 (pitch->chord-name-text-banter tonic steps)
787 ;; why does list->string not work, format seems only hope...
788 (if (and (string-match "super" (format "~s" exception-part))
789 (or (pair? additions)
790 (pair? subtractions)))
791 (list simple-super "/"))
793 (list `(,simple-super)
794 (chord::additions->text-jazz additions subtractions)
795 (chord::subtractions->text-jazz subtractions))
796 (chord::bass-and-inversion->text-banter bass-and-inversion)))
798 ;; Jazz style--basically similar to american with minor changes
800 ;; Consider Dm6. When we get here:
801 ;; tonic = '(0 1 0) (note d=2)
802 ;; steps = '((0 0 0) '(0 2 -1) (0 4 0) (0 5 0))
803 ;; steps are transposed for tonic c, octave 0,
804 ;; so (car steps) is always (0 0 0)
806 ;; assuming that the exceptions-alist has an entry
807 ;; '(((0 . 0) (2 . -1)) . ("m"))
808 ;; (and NOT the full chord, like std jazz list, ugh)
809 ;; unmatch = '((0 0 0) (0 2 0) (0 4 0) (0 5 0))
812 ;; You can look very easily what happens, if you add some write-me calls,
813 ;; and run lilypond on a simple file, eg, containing only the chord c:m6:
815 ;; (let ((additions (write-me "adds: "
816 ;; (chord::additions (write-me "unmatched:"
817 ;; unmatched-steps))))
819 ;; If you set subtract #f, the chord::inner-name-jazz does not see any
820 ;; subtractions, ever, so they don't turn up in the chord name.
822 (define-public (chord::name-jazz tonic exception-part unmatched-steps
823 bass-and-inversion steps)
824 (let ((additions (chord::additions unmatched-steps))
825 ;; get no 'omit' or 'no'
826 ;; (subtractions #f))
827 (subtractions (chord::subtractions unmatched-steps)))
828 (chord::inner-name-jazz tonic exception-part additions subtractions
829 bass-and-inversion steps)))
831 ;; wip (set! chord::names-alist-jazz
832 (define chord::names-alist-jazz
835 (((0 . 0) (2 . -1)) . ("m"))
837 ;; some fixups -- jcn
838 ; major seventh chord = triangle
839 (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . (((raise . 0.5)((font-family . math) "N"))))
840 ;; (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . (((raise . 0.5)((font-family . math) "M"))))
842 ;; minor major seventh chord = m triangle
843 (((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . (columns ("m") ((raise . 0.5)((font-family . math) "N"))))
844 ;; (((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . (columns ("m") ((raise . 0.5)((font-family . math) "M"))))
848 chord::names-alist-american))