2 ;;; chord-name.scm -- Compile chord name
4 ;;; source file of the GNU LilyPond music typesetter
6 ;;; (c) 2000--2001 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 ;; * easier tweakability:
27 ;; - split chord::names-alists up into logical bits,
28 ;; such as chord::exceptions-delta, exceptions-oslash
29 ;; - iso just the 'style parameter, use a list, eg:
30 ;; \property ChordNames.ChordName \set
31 ;; #'style = #'(jazz delta oslash german-tonic german-Bb)
35 ;; * clean split/merge of bass/banter/american stuff
39 (define chord::names-alist-banter '())
40 (set! chord::names-alist-banter
46 (((0 . 0) (2 . 0)) . #f)
48 (((0 . 0) (2 . -1)) . ("m"))
50 (((0 . 0) (1 . 0) (4 . 0)) . ("" (super "2") " "))
52 (((0 . 0) (3 . 0) (4 . 0)) . ("" (super "4") " " ))
54 (((0 . 0) (2 . -1) (4 . -1)) . ("dim"))
56 (((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . ("" (super "o") " "))
58 (((0 . 0) (2 . -1) (4 . -1) (6 . -2) (1 . -1)) . ("dim" (super "9") " "))
59 (((0 . 0) (2 . -1) (4 . -1) (6 . -2) (1 . -1) (3 . -1)) . ("dim" (super "11") " "))
61 chord::names-alist-banter))
65 ;; duh, no docstrings for
66 ;; "No real superscript, just raised and small"
67 '((raise . 1) (font-relative-size . -2)))
69 (define (accidental->textp acc pos)
72 (list '(music (font-relative-size . -2))
73 (list pos (string-append "accidentals-" (number->string acc))))))
75 (define (accidental->text acc) (accidental->textp acc 'columns))
76 (define (accidental->text-super acc) (accidental->textp acc 'simple-super))
77 (define (accidental->text-sub acc) (accidental->textp acc 'sub))
79 (define (pitch->note-name pitch)
80 (cons (cadr pitch) (caddr pitch)))
82 (define (pitch->text pitch)
85 '(font-relative-size . 2)
86 (make-string 1 (integer->char (+ (modulo (+ (cadr pitch) 2) 7) 65))))
87 (accidental->text-super (caddr pitch))))
90 ;;; Hooks to override chord names and note names,
91 ;;; see input/tricks/german-chords.ly
93 (define (pitch->text-banter pitch)
96 ;; We need also steps, to allow for Cc name override,
97 ;; see input/test/Cc-chords.ly
98 (define (pitch->chord-name-text-banter pitch steps)
99 (pitch->text-banter pitch))
101 (define (pitch->note-name-text-banter pitch)
102 (pitch->text-banter pitch))
104 (define (step->text pitch)
106 (number->string (+ (cadr pitch) (if (= (car pitch) 0) 1 8)))
114 (define (step->text-banter pitch)
115 (if (= (cadr pitch) 6)
124 (define pitch::semitone-vec (list->vector '(0 2 4 5 7 9 11)))
126 (define (pitch::semitone pitch)
127 (+ (* (car pitch) 12)
128 (vector-ref pitch::semitone-vec (modulo (cadr pitch) 7))
131 (define (pitch::< l r)
132 (< (pitch::semitone l) (pitch::semitone r)))
134 (define (pitch::transpose pitch delta)
135 (let ((simple-octave (+ (car pitch) (car delta)))
136 (simple-notename (+ (cadr pitch) (cadr delta))))
137 (let ((octave (+ simple-octave (quotient simple-notename 7)))
138 (notename (modulo simple-notename 7)))
139 (let ((accidental (- (+ (pitch::semitone pitch) (pitch::semitone delta))
140 (pitch::semitone `(,octave ,notename 0)))))
141 `(,octave ,notename ,accidental)))))
143 (define (pitch::diff pitch tonic)
144 (let ((simple-octave (- (car pitch) (car tonic)))
145 (simple-notename (- (cadr pitch) (cadr tonic))))
146 (let ((octave (+ simple-octave (quotient simple-notename 7)
147 (if (< simple-notename 0) -1 0)))
148 (notename (modulo simple-notename 7)))
149 (let ((accidental (- (pitch::semitone pitch)
150 (pitch::semitone tonic)
151 (pitch::semitone `(,octave ,notename 0)))))
152 `(,octave ,notename ,accidental)))))
154 (define (pitch::note-pitch pitch)
155 (+ (* (car pitch) 7) (cadr pitch)))
157 (define (chord::text? text)
158 (not (or (not text) (empty? text) (unspecified? text))))
160 (define (chord::text-cleanup dirty)
162 Recursively remove '() #f, and #<unspecified> from markup text tree.
163 This allows us to leave else parts of (if # #) off.
164 Otherwise, you'd have to do (if # # '()), and you'd have to
165 filter-out the '() anyway.
168 (let ((r (car dirty)))
170 (cons (if (pair? r) (chord::text-cleanup r) r)
171 (chord::text-cleanup (cdr dirty)))
172 (chord::text-cleanup (cdr dirty))))
173 (if (chord::text? dirty)
177 (define (text-append l . r)
178 (if (not (chord::text? r))
180 (if (not (chord::text? l))
183 (list 'columns l (car r))
184 (text-append (list 'columns l (car r)) (cdr r))))))
186 (define (chord::step tonic pitch)
187 (- (pitch::note-pitch pitch) (pitch::note-pitch tonic)))
189 ;; text: list of word
190 ;; word: string + optional list of property
191 ;; property: align, kern, font (?), size
193 (define chord::minor-major-vec (list->vector '(0 -1 -1 0 -1 -1 0)))
196 ;; compute the relative-to-tonic pitch that goes with 'step'
197 (define (chord::step-pitch tonic step)
198 ;; urg, we only do this for thirds
199 (if (= (modulo step 2) 0)
201 (let loop ((i 1) (pitch tonic))
205 pitch `(0 2 ,(vector-ref chord::minor-major-vec
206 ;; -1 (step=1 -> vector=0) + 7 = 6
207 (modulo (+ i 6) 7)))))))))
209 (define (chord::additions steps)
211 * any even step (2, 4, 6)
212 * any uneven step that is chromatically altered,
213 (where 7-- == -1, 7- == 0, 7 == +1)
216 ?and jazz needs also:
218 * TODO: any uneven step that's lower than an uneven step which is
219 chromatically altered
222 (let ((evens (filter-list (lambda (x) (!= 0 (modulo (cadr x) 2))) steps))
224 (filter-list (lambda (x)
225 (let ((n (cadr x)) (a (caddr x)))
226 (or (and (= 6 n) (!= -1 a))
231 (highest (let ((h (car (last-pair steps))))
232 (if (and (not (empty? h))
237 ;; Hmm, what if we have a step twice, can we ignore that?
238 (uniq-list (sort (apply append evens altered-unevens highest)
242 ;; FIXME: unLOOP, see ::additions
243 ;; find the pitches that are missing from `normal' chord
244 (define (chord::subtractions chord-pitches)
245 (write-me "subs: " (let ((tonic (car chord-pitches)))
246 (let loop ((step 1) (pitches chord-pitches) (subtractions '()))
248 (let* ((pitch (car pitches))
249 (p-step (+ (- (pitch::note-pitch pitch)
250 (pitch::note-pitch tonic))
252 ;; pitch is an subtraction if
253 ;; a step is missing or
255 (loop (+ step 2) pitches
256 (cons (chord::step-pitch tonic step) subtractions))
257 ;; there are no pitches left, but base thirds are not yet done and
259 (= (length pitches) 1))
260 ;; present pitch is not missing step
262 (loop (+ step 2) pitches subtractions)
263 (loop (+ step 2) pitches
264 (cons (chord::step-pitch tonic step) subtractions)))
266 (loop (+ step 2) (cdr pitches) subtractions)
267 (loop step (cdr pitches) subtractions)))))
268 (reverse subtractions))))))
270 (define (chord::additions->text-banter additions subtractions)
271 (if (pair? additions)
273 (let ((step (step->text-banter (car additions))))
274 (if (or (pair? (cdr additions))
275 (pair? subtractions))
276 (text-append step "/")
278 (chord::additions->text-banter (cdr additions) subtractions))
281 (define (chord::subtractions->text-banter subtractions)
282 (if (pair? subtractions)
285 (let ((step (step->text-jazz (car subtractions))))
286 (if (pair? (cdr subtractions))
287 (text-append step "/")
289 (chord::subtractions->text-banter (cdr subtractions)))
292 (define (chord::bass-and-inversion->text-banter bass-and-inversion)
293 (if (and (pair? bass-and-inversion)
294 (or (car bass-and-inversion)
295 (cdr bass-and-inversion)))
296 (list "/" (if (car bass-and-inversion)
297 (pitch->note-name-text-banter
298 (car bass-and-inversion))
299 (pitch->note-name-text-banter
300 (cdr bass-and-inversion))))))
302 ;; FIXME: merge this function with inner-name-jazz, -american
303 ;; iso using chord::bass-and-inversion->text-banter,
304 ;; call (chord::restyle 'chord::bass-and-inversion->text- style)
305 ;; See: chord::exceptions-lookup
308 ;; Combine tonic, exception-part of chord name,
309 ;; additions, subtractions and bass or inversion into chord name
310 (define (chord::inner-name-banter tonic exception-part additions subtractions
311 bass-and-inversion steps)
312 (let ((tonic-text (pitch->chord-name-text-banter tonic steps))
313 (except-text exception-part)
314 (sep-text (if (and (string-match "super" (format "~s" exception-part))
315 (or (pair? additions)
316 (pair? subtractions)))
317 (list simple-super "/")))
318 (adds-text (chord::additions->text-banter additions subtractions))
319 (subs-text (chord::subtractions->text-banter subtractions))
320 (b+i-text (chord::bass-and-inversion->text-banter bass-and-inversion)))
322 tonic-text except-text sep-text
323 (list (list simple-super) adds-text subs-text)
326 (define (chord::name-banter tonic exception-part unmatched-steps
327 bass-and-inversion steps)
328 (let ((additions (chord::additions unmatched-steps))
329 (subtractions (chord::subtractions unmatched-steps)))
330 (chord::inner-name-banter tonic exception-part additions subtractions
331 bass-and-inversion steps)))
334 (define (c++-pitch->scm p)
336 (list (pitch-octave p) (pitch-notename p) (pitch-alteration p))
339 (define (chord::name-banter tonic exception-part unmatched-steps
340 bass-and-inversion steps)
341 (let ((additions (chord::additions unmatched-steps))
342 (subtractions (chord::subtractions unmatched-steps)))
343 (chord::inner-name-banter tonic exception-part additions subtractions
344 bass-and-inversion steps)))
346 (define (chord::restyle name style)
347 (ly-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 (write-me "xl: " (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)))
401 ((chord::restyle 'chord::name- style)
402 tonic exception-part unmatched-steps bass-and-inversion steps)))
406 ;; Check for each subset of chord, full chord first, if there's a
407 ;; user-override. Split the chord into user-overridden and to-be-done
408 ;; parts, complete the missing user-override matched part with normal
409 ;; chord to be name-calculated.
411 ;; CHORD: (pitches (bass . inversion))
412 (define (default-chord-name-function style chord)
413 (let* ((pitches (map c++-pitch->scm (car chord)))
414 (modifiers (cdr chord))
415 (bass-and-inversion (if (pair? modifiers)
416 (cons (c++-pitch->scm (car modifiers))
417 (c++-pitch->scm (cdr modifiers)))
419 (diff (pitch::diff '(0 0 0) (car pitches)))
420 (steps (if (cdr pitches) (map (lambda (x)
421 (pitch::transpose x diff))
424 (chord::name->text style (car pitches) steps bass-and-inversion)))
431 ;; NOTE: Duplicates of chord names defined elsewhere occur in this list
432 ;; in order to prevent spurious superscripting of various chord names,
433 ;; such as maj7, maj9, etc.
435 ;; See input/test/american-chords.ly
437 ;; James Hammons, <jlhamm@pacificnet.net>
440 ;; DONT use non-ascii characters, even if ``it works'' in Windows
442 (define chord::names-alist-american '())
444 (set! chord::names-alist-american
448 (((0 . 0) (2 . 0)) . #f)
450 (((0 . 0) (4 . 0)) . ("5"))
452 (((0 . 0) (2 . -1)) . ("m"))
453 (((0 . 0) (3 . 0) (4 . 0)) . ("sus"))
454 (((0 . 0) (2 . -1) (4 . -1)) . ("dim"))
455 ;Alternate: (((0 . 0) (2 . -1) (4 . -1)) . ("" (super "o")))
456 (((0 . 0) (2 . 0) (4 . 1)) . ("aug"))
457 ;Alternate: (((0 . 0) (2 . 0) (4 . 1)) . ("+"))
458 (((0 . 0) (1 . 0) (4 . 0)) . ("2"))
459 ;; Common seventh chords
460 (((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . ("" (super "o") " " "7"))
461 (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . ("maj7"))
462 ;; urg! should use (0 . 0 2 . -1) -> "m", and add "7" to that!!
463 (((0 . 0) (2 . -1) (4 . 0) (6 . -1)) . ("m7"))
464 (((0 . 0) (2 . 0) (4 . 0) (6 . -1)) . ("7"))
465 (((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . ("m(maj7)"))
466 ;jazz: the delta, see jazz-chords.ly
467 ;;(((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . (super ((font-family . math) "N"))
469 (((0 . 0) (2 . -1) (4 . -1) (6 . -1)) . (columns (super (overstrike "o") "/") " " "7"))
471 (((0 . 0) (2 . 0) (4 . 1) (6 . -1)) . ("aug7"))
472 (((0 . 0) (2 . 0) (4 . -1) (6 . 0)) . (columns "maj7" ((font-relative-size . -2) ((raise . 0.2) (music (named "accidentals--1")))) "5"))
473 (((0 . 0) (2 . 0) (4 . -1) (6 . -1)) . (columns "7" ((font-relative-size . -2) ((raise . 0.2) (music (named "accidentals--1")))) "5"))
474 (((0 . 0) (3 . 0) (4 . 0) (6 . -1)) . ("7sus4"))
475 ;; Common ninth chords
476 (((0 . 0) (2 . 0) (4 . 0) (5 . 0) (1 . 0)) . ("6/9")) ;; we don't want the '/no7'
477 (((0 . 0) (2 . 0) (4 . 0) (5 . 0)) . ("6"))
478 (((0 . 0) (2 . -1) (4 . 0) (5 . 0)) . ("m6"))
479 (((0 . 0) (2 . 0) (4 . 0) (1 . 0)) . ("add9"))
480 (((0 . 0) (2 . 0) (4 . 0) (6 . 0) (1 . 0)) . ("maj9"))
481 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . 0)) . ("9"))
482 (((0 . 0) (2 . -1) (4 . 0) (6 . -1) (1 . 0)) . ("m9"))
485 chord::names-alist-american))
488 ;; American style chordnames use no "no",
489 ;; but otherwise very similar to banter for now
490 (define (chord::name-american tonic exception-part unmatched-steps
491 bass-and-inversion steps)
492 (let ((additions (chord::additions unmatched-steps))
494 (chord::inner-name-banter tonic exception-part additions subtractions
495 bass-and-inversion steps)))
505 ;; Jazz chords, by Atte Andr'e Jensen <atte@post.com>
506 ;; NBs: This uses the american list as a bass.
507 ;; Some defs take up more than one line,
508 ;; be carefull when messing with ;'s!!
513 ;; This is getting out-of hand? Only exceptional chord names that
514 ;; cannot be generated should be here.
515 ;; Maybe we should have inner-name-jazz and inner-name-american functions;
519 ;; DONT use non-ascii characters, even if ``it works'' in Windows
521 (define chord::names-alist-jazz '())
522 (set! chord::names-alist-jazz
526 ; major sixth chord = 6
527 (((0 . 0) (2 . 0) (4 . 0) (5 . 0)) . (((raise . 0.5) "6")))
528 ; major seventh chord = triangle
529 ;; shouldn't this be a filled black triange, like this: ? --jcn
530 ;; (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . (((raise . 0.5)((font-family . math) "N"))))
531 (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . (((raise . 0.5)((font-family . math) "M"))))
532 ; major chord add nine = add9
533 (((0 . 0) (2 . 0) (4 . 0) (1 . 0)) . (((raise . 0.5) "add9")))
534 ; major sixth chord with nine = 6/9
535 (((0 . 0) (2 . 0) (4 . 0) (5 . 0) (1 . 0)) . (((raise . 0.5) "6/9")))
538 ; minor sixth chord = m6
539 (((0 . 0) (2 . -1) (4 . 0) (5 . 0)) . (columns("m")((raise . 0.5) "6")))
540 ;; minor major seventh chord = m triangle
541 ;; shouldn't this be a filled black triange, like this: ? --jcn
542 ;;(((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . (columns ("m") ((raise . 0.5)((font-family . math) "N"))))
543 (((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . (columns ("m") ((raise . 0.5)((font-family . math) "M"))))
544 ; minor seventh chord = m7
545 (((0 . 0) (2 . -1) (4 . 0) (6 . -1)) . (columns("m")((raise . 0.5) "7")))
546 ; minor sixth nine chord = m6/9
547 (((0 . 0) (2 . -1) (4 . 0) (5 . 0) (1 . 0)) . (columns("m")((raise . 0.5) "6/9")))
548 ; minor with added nine chord = madd9
549 (((0 . 0) (2 . -1) (4 . 0) (1 . 0)) . (columns("m")((raise . 0.5) "add9")))
550 ; minor ninth chord = m9
551 (((0 . 0) (2 . -1) (4 . 0) (6 . -1) (1 . 0)) . (columns("m")((raise . 0.5) "9")))
554 ; dominant seventh = 7
555 (((0 . 0) (2 . 0) (4 . 0) (6 . -1)) . (((raise . 0.5) "7")))
556 ; augmented dominant = +7
557 ;(((0 . 0) (2 . 0) (4 . +1) (6 . -1)) . (((raise . 0.5) "+7"))) ; +7 with both raised
558 (((0 . 0) (2 . 0) (4 . +1) (6 . -1)) . (columns("+")((raise . 0.5) "7"))) ; +7 with 7 raised
559 ;(((0 . 0) (2 . 0) (4 . +1) (6 . -1)) . (columns((raise . 0.5) "7(")
560 ; ((raise . 0.3)(music (named ("accidentals-1"))))
561 ; ((raise . 0.5) "5)"))); 7(#5)
562 ; dominant flat 5 = 7(b5)
563 (((0 . 0) (2 . 0) (4 . -1) (6 . -1)) . (columns((raise . 0.5) "7(")
564 ((raise . 0.3)(music (named ("accidentals--1"))))
565 ((raise . 0.5) "5)")))
567 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . 0)) . (((raise . 0.8)"7(9)")))
568 ; dominant flat 9 = 7(b9)
569 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . -1)) . (
571 ((raise . 0.3)(music (named ("accidentals--1"))))
572 ((raise . 0.8)"9)")))
573 ; dominant sharp 9 = 7(#9)
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 13 = 7(13)
579 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (5 . 0)) . (((raise . 0.8)"7(13)")))
580 ; dominant flat 13 = 7(b13)
581 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (5 . -1)) . (
583 ((raise . 0.3)(music (named ("accidentals--1"))))
584 ((raise . 0.8)"13)")))
585 ; dominant 9, 13 = 7(9,13)
586 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . 0) (5 . 0)) . (((raise . 0.8)"7(9, 13)")))
587 ; dominant flat 9, 13 = 7(b9,13)
588 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . -1) (5 . 0)) . (
590 ((raise . 0.3)(music (named ("accidentals--1"))))
591 ((raise . 0.8)"9, 13)")))
592 ; dominant sharp 9, 13 = 7(#9,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 9, flat 13 = 7(9,b13)
598 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . 0) (5 . -1)) . (
599 ((raise . 0.8)"7(9, ")
600 ((raise . 0.3)(music (named ("accidentals--1"))))
601 ((raise . 0.8)"13)")))
602 ; dominant flat 9, flat 13 = 7(b9,b13)
603 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . -1) (5 . -1)) . (
605 ((raise . 0.3)(music (named ("accidentals--1"))))
607 ((raise . 0.3)(music (named ("accidentals--1"))))
608 ((raise . 0.8)"13)")))
609 ; dominant sharp 9, flat 13 = 7(#9,b13)
610 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . +1) (5 . -1)) . (
612 ((raise . 0.3)(music (named ("accidentals-1"))))
614 ((raise . 0.3)(music (named ("accidentals--1"))))
615 ((raise . 0.8)"13)")))
617 ;; diminished chord(s)
618 ; diminished seventh chord = o
621 ;; DONT use non-ascii characters, even if ``it works'' in Windows
623 ;;(((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . ((raise . 0.8) (size . -2) ("o")))
624 (((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . ("" (super "o")))
626 ;; half diminshed chords
627 ;; half diminished seventh chord = slashed o
628 ;; (((0 . 0) (2 . -1) (4 . -1) (6 . -1)) . (((raise . 0.8) "/o")))
629 (((0 . 0) (2 . -1) (4 . -1) (6 . -1)) . (columns (super (overstrike "o") "/") " " "7")) ; slashed o
631 ; half diminished seventh chord with major 9 = slashed o cancelation 9
632 (((0 . 0) (2 . -1) (4 . -1) (6 . -1) (1 . 0)) . (
634 ((raise . 0.3)(music (named ("accidentals-0"))))
635 ((raise . 0.8)"9)")));
637 ;; Missing jazz chord definitions go here (note new syntax: see american for hints)
640 chord::names-alist-american))
642 (define (step->text-alternate-jazz pitch)
644 (accidental->text (caddr pitch))
645 (number->string (+ (cadr pitch) (if (= (car pitch) 0) 1 8)))))
647 (define (step->text-jazz pitch)
648 (if (= (cadr pitch) 6)
650 ;; sharp 7 only included for completeness?
651 ((-2) (text-append (accidental->text -1) '("7")))
654 ((1) (text-append (accidental->text-super 1) '("7")))
655 ((2) (text-append (accidental->text-super 2) '("7"))))
656 (step->text-alternate-jazz pitch)))
658 (define (xchord::additions->text-jazz additions subtractions)
659 (if (pair? additions)
661 (let ((step (step->text-jazz (car additions))))
662 (if (or (pair? (cdr additions))
663 (pair? subtractions))
664 (text-append step "/")
666 (chord::additions->text-jazz (cdr additions) subtractions))
669 (define (chord::>5? x)
675 ;; Perhaps all logic like this should be done earlier,
676 ;; so that in this text-construction printing phase
677 ;; we can just blindly create text from all additions.
679 ;; This depends maybe on the fact of code sharing,
680 ;; in this layout, we can share the functions chord::additions
681 ;; and chord::subtractions with banter.
682 (define (chord::additions->text-jazz additions subtractions)
684 (chord::additions<=5->text-jazz (filter-out-list chord::>5? additions)
685 (filter-out-list chord::>5? subtractions))
686 (chord::additions>5->text-jazz (filter-list chord::>5? additions)
687 (filter-list chord::>5? subtractions))))
690 (define (chord::additions<=5->text-jazz additions subtractions)
691 (let ((sus (chord::sus-four-jazz additions)))
693 (text-append '("sus") (step->text-jazz (car sus)))
696 (define (chord::additions>5->text-jazz additions subtractions)
698 Compose text of all additions
700 * if there's a subtraction:
702 - list all up to highest
703 * list all steps that are below an chromatically altered step
706 (if (not (empty? subtractions)) "add" '())
707 (let ((radds (reverse additions)))
708 (reverse (chord::additions>5->text-jazz-helper
711 (if (or (empty? subtractions) (empty? radds))
714 (define (chord::additions>5->text-jazz-helper additions subtractions list-step)
716 Create texts for all additions
717 If list-step != #f, list all steps down to 5
718 If we encounter a chromatically altered step, turn on list-step
722 (if (not (member list-step subtractions))
723 (if (> 5 (cadr list-step))
724 (cons (step->text-jazz list-step)
725 (chord::additions>5->text-jazz-helper
728 (chord::get-create-step additions
729 (- (cadr list-step) 2))))
730 (step->text-jazz list-step))
731 (chord::get-create-step additions (- (cadr list-step) 2)))
732 (if (pair? additions)
733 (let ((step (car additions)))
734 (cons (step->text-jazz step)
735 (chord::additions>5->text-jazz-helper
738 (if (or (and (!= 6 (cadr step)) (!= 0 (caddr step)))
739 (and (= 6 (cadr step)) (!= -1 (caddr step))))
740 (chord::get-create-step additions (- (cadr step) 2))
744 (define (chord::sus-four-jazz chord-pitches)
745 "List of pitches that are step 2 or step 4"
746 (filter-list (lambda (x)
748 (or (= 1 (cadr x)) (= 3 (cadr x))))) chord-pitches))
750 (define (chord::get-create-step steps n)
751 (let* ((i (if (< n 0) (+ n 7) n))
752 (found (filter-list (lambda (x) (= i (cadr x))) steps)))
759 (define (chord::subtractions->text-jazz subtractions)
760 (if (pair? subtractions)
762 (if (= 5 (cadr (car subtractions)))
765 (let ((step (step->text-jazz (car subtractions))))
766 (if (pair? (cdr subtractions))
767 (text-append step "/")
770 (chord::subtractions->text-jazz (cdr subtractions)))
774 ;; TODO: maybe merge with inner-name-banter
775 ;; Combine tonic, exception-part of chord name,
776 ;; additions, subtractions and bass or inversion into chord name
777 (define (chord::inner-name-jazz tonic exception-part additions subtractions
778 bass-and-inversion steps)
780 (pitch->chord-name-text-banter tonic steps)
782 ;; why does list->string not work, format seems only hope...
783 (if (and (string-match "super" (format "~s" exception-part))
784 (or (pair? additions)
785 (pair? subtractions)))
786 (list simple-super "/"))
788 (list `(,simple-super)
789 (chord::additions->text-jazz additions subtractions)
790 (chord::subtractions->text-jazz subtractions))
791 (chord::bass-and-inversion->text-banter bass-and-inversion)))
793 ;; Jazz style--basically similar to american with minor changes
795 ;; Consider Dm6. When we get here:
796 ;; tonic = '(0 1 0) (note d=2)
797 ;; steps = '((0 0 0) '(0 2 -1) (0 4 0) (0 5 0))
798 ;; steps are transposed for tonic c, octave 0,
799 ;; so (car steps) is always (0 0 0)
801 ;; assuming that the exceptions-alist has an entry
802 ;; '(((0 . 0) (2 . -1)) . ("m"))
803 ;; (and NOT the full chord, like std jazz list, ugh)
804 ;; unmatch = '((0 0 0) (0 2 0) (0 4 0) (0 5 0))
807 ;; You can look very easily what happens, if you add some write-me calls,
808 ;; and run lilypond on a simple file, eg, containing only the chord c:m6:
810 ;; (let ((additions (write-me "adds: "
811 ;; (chord::additions (write-me "unmatched:"
812 ;; unmatched-steps))))
814 ;; If you set subtract #f, the chord::inner-name-jazz does not see any
815 ;; subtractions, ever, so they don't turn up in the chord name.
817 (define (chord::name-jazz tonic exception-part unmatched-steps
818 bass-and-inversion steps)
819 (let ((additions (chord::additions unmatched-steps))
820 ;; get no 'omit' or 'no'
821 ;; (subtractions #f))
822 (subtractions (chord::subtractions unmatched-steps)))
823 (chord::inner-name-jazz tonic exception-part additions subtractions
824 bass-and-inversion steps)))
826 ;; wip (set! chord::names-alist-jazz
827 (define chord::names-alist-jazz
830 (((0 . 0) (2 . -1)) . ("m"))
832 ;; some fixups -- jcn
833 ; major seventh chord = triangle
834 (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . (((raise . 0.5)((font-family . math) "N"))))
835 ;; (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . (((raise . 0.5)((font-family . math) "M"))))
837 ;; minor major seventh chord = m triangle
838 (((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . (columns ("m") ((raise . 0.5)((font-family . math) "N"))))
839 ;; (((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . (columns ("m") ((raise . 0.5)((font-family . math) "M"))))
843 chord::names-alist-american))