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
221 (let ((evens (filter-list (lambda (x) (!= 0 (modulo (cadr x) 2))) steps))
223 (filter-list (lambda (x)
224 (let ((n (cadr x)) (a (caddr x)))
225 (or (and (= 6 n) (!= -1 a))
230 (highest (let ((h (car (last-pair steps))))
231 (if (and (not (empty? h))
236 ;; Hmm, what if we have a step twice, can we ignore that?
237 (uniq-list (sort (apply append evens altered-unevens highest)
241 ;; FIXME: unLOOP, see ::additions
242 ;; find the pitches that are missing from `normal' chord
243 (define (chord::subtractions chord-pitches)
244 (let ((tonic (car chord-pitches)))
245 (let loop ((step 1) (pitches chord-pitches) (subtractions '()))
247 (let* ((pitch (car pitches))
248 (p-step (+ (- (pitch::note-pitch pitch)
249 (pitch::note-pitch tonic))
251 ;; pitch is an subtraction if
252 ;; a step is missing or
254 (loop (+ step 2) pitches
255 (cons (chord::step-pitch tonic step) subtractions))
256 ;; there are no pitches left, but base thirds are not yet done and
258 (= (length pitches) 1))
259 ;; present pitch is not missing step
261 (loop (+ step 2) pitches subtractions)
262 (loop (+ step 2) pitches
263 (cons (chord::step-pitch tonic step) subtractions)))
265 (loop (+ step 2) (cdr pitches) subtractions)
266 (loop step (cdr pitches) subtractions)))))
267 (reverse subtractions)))))
269 (define (chord::additions->text-banter additions subtractions)
270 (if (pair? additions)
272 (let ((step (step->text-banter (car additions))))
273 (if (or (pair? (cdr additions))
274 (pair? subtractions))
275 (text-append step "/")
277 (chord::additions->text-banter (cdr additions) subtractions))
280 (define (chord::subtractions->text-banter subtractions)
281 (if (pair? subtractions)
284 (let ((step (step->text-jazz (car subtractions))))
285 (if (pair? (cdr subtractions))
286 (text-append step "/")
288 (chord::subtractions->text-banter (cdr subtractions)))
291 (define (chord::bass-and-inversion->text-banter bass-and-inversion)
292 (if (and (pair? bass-and-inversion)
293 (or (car bass-and-inversion)
294 (cdr bass-and-inversion)))
295 (list "/" (if (car bass-and-inversion)
296 (pitch->note-name-text-banter
297 (car bass-and-inversion))
298 (pitch->note-name-text-banter
299 (cdr bass-and-inversion))))))
301 ;; FIXME: merge this function with inner-name-jazz, -american
302 ;; iso using chord::bass-and-inversion->text-banter,
303 ;; call (chord::restyle 'chord::bass-and-inversion->text- style)
304 ;; See: chord::exceptions-lookup
307 ;; Combine tonic, exception-part of chord name,
308 ;; additions, subtractions and bass or inversion into chord name
309 (define (chord::inner-name-banter tonic exception-part additions subtractions
310 bass-and-inversion steps)
311 (let ((tonic-text (pitch->chord-name-text-banter tonic steps))
312 (except-text exception-part)
313 (sep-text (if (and (string-match "super" (format "~s" exception-part))
314 (or (pair? additions)
315 (pair? subtractions)))
316 (list simple-super "/")))
317 (adds-text (chord::additions->text-banter additions subtractions))
318 (subs-text (chord::subtractions->text-banter subtractions))
319 (b+i-text (chord::bass-and-inversion->text-banter bass-and-inversion)))
321 tonic-text except-text sep-text
322 (list (list simple-super) adds-text subs-text)
325 (define (chord::name-banter tonic exception-part unmatched-steps
326 bass-and-inversion steps)
327 (let ((additions (chord::additions unmatched-steps))
328 (subtractions (chord::subtractions unmatched-steps)))
329 (chord::inner-name-banter tonic exception-part additions subtractions
330 bass-and-inversion steps)))
333 (define (c++-pitch->scm p)
335 (list (pitch-octave p) (pitch-notename p) (pitch-alteration p))
338 (define (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)))
345 (define (chord::restyle name style)
346 (primitive-eval (string->symbol
347 (string-append (symbol->string name)
348 (symbol->string style)))))
350 ;; check exceptions-alist for biggest matching part of try-steps
351 ;; return (MATCHED-EXCEPTION . UNMATCHED-STEPS)
352 (define (chord::exceptions-lookup-helper
353 exceptions-alist try-steps unmatched-steps exception-part)
354 (if (pair? try-steps)
355 ;; FIXME: junk '(0 . 0) from exceptions lists?
356 ;; if so: how to handle first '((0 . 0) . #f) entry?
358 ;; FIXME: either format exceptions list as real pitches, ie,
359 ;; including octave '((0 2 -1) ..), or drop octave
360 ;; from rest of calculations,
362 (map (lambda (x) (pitch->note-name x))
363 (append '((0 0 0)) try-steps))
366 (chord::exceptions-lookup-helper
367 #f '() unmatched-steps (cdr entry))
368 (let ((r (reverse try-steps)))
369 (chord::exceptions-lookup-helper
372 (cons (car r) unmatched-steps) #f))))
373 (cons exception-part unmatched-steps)))
375 ;; return (MATCHED-EXCEPTION . BASE-CHORD-WITH-UNMATCHED-STEPS)
376 ;; BASE-CHORD-WITH-UNMATCHED-STEPS always includes (tonic 3 5)
377 (define (chord::exceptions-lookup style steps)
378 (let* ((result (chord::exceptions-lookup-helper
379 (chord::restyle 'chord::names-alist- style)
381 (exception-part (car result))
382 (unmatched-steps (cdr result))
383 (matched-steps (if (= (length unmatched-steps) 0)
385 (+ 1 (- (length steps)
386 (length unmatched-steps)))))
387 (unmatched-with-1-3-5
388 (append (do ((i matched-steps (- i 1))
389 (base '() (cons `(0 ,(* (- i 1) 2) 0) base)))
393 (list exception-part unmatched-with-1-3-5)))
396 (define (chord::name->text style tonic steps bass-and-inversion)
397 (let* ((lookup (chord::exceptions-lookup style steps))
398 (exception-part (car lookup))
399 (unmatched-steps (cadr lookup)))
400 ((chord::restyle 'chord::name- style)
401 tonic exception-part unmatched-steps bass-and-inversion steps)))
405 ;; Check for each subset of chord, full chord first, if there's a
406 ;; user-override. Split the chord into user-overridden and to-be-done
407 ;; parts, complete the missing user-override matched part with normal
408 ;; chord to be name-calculated.
410 ;; CHORD: (pitches (bass . inversion))
411 (define (default-chord-name-function style chord)
412 (let* ((pitches (map c++-pitch->scm (car chord)))
413 (modifiers (cdr chord))
414 (bass-and-inversion (if (pair? modifiers)
415 (cons (c++-pitch->scm (car modifiers))
416 (c++-pitch->scm (cdr modifiers)))
418 (diff (pitch::diff '(0 0 0) (car pitches)))
419 (steps (if (cdr pitches) (map (lambda (x)
420 (pitch::transpose x diff))
423 (chord::name->text style (car pitches) steps bass-and-inversion)))
430 ;; NOTE: Duplicates of chord names defined elsewhere occur in this list
431 ;; in order to prevent spurious superscripting of various chord names,
432 ;; such as maj7, maj9, etc.
434 ;; See input/test/american-chords.ly
436 ;; James Hammons, <jlhamm@pacificnet.net>
439 ;; DONT use non-ascii characters, even if ``it works'' in Windows
441 (define chord::names-alist-american '())
443 (set! chord::names-alist-american
447 (((0 . 0) (2 . 0)) . #f)
449 (((0 . 0) (4 . 0)) . ("5"))
451 (((0 . 0) (2 . -1)) . ("m"))
452 (((0 . 0) (3 . 0) (4 . 0)) . ("sus"))
453 (((0 . 0) (2 . -1) (4 . -1)) . ("dim"))
454 ;Alternate: (((0 . 0) (2 . -1) (4 . -1)) . ("" (super "o")))
455 (((0 . 0) (2 . 0) (4 . 1)) . ("aug"))
456 ;Alternate: (((0 . 0) (2 . 0) (4 . 1)) . ("+"))
457 (((0 . 0) (1 . 0) (4 . 0)) . ("2"))
458 ;; Common seventh chords
459 (((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . ("" (super "o") " " "7"))
460 (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . ("maj7"))
461 ;; urg! should use (0 . 0 2 . -1) -> "m", and add "7" to that!!
462 (((0 . 0) (2 . -1) (4 . 0) (6 . -1)) . ("m7"))
463 (((0 . 0) (2 . 0) (4 . 0) (6 . -1)) . ("7"))
464 (((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . ("m(maj7)"))
465 ;jazz: the delta, see jazz-chords.ly
466 ;;(((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . (super ((font-family . math) "N"))
468 (((0 . 0) (2 . -1) (4 . -1) (6 . -1)) . (columns (super (overstrike "o") "/") " " "7"))
470 (((0 . 0) (2 . 0) (4 . 1) (6 . -1)) . ("aug7"))
471 (((0 . 0) (2 . 0) (4 . -1) (6 . 0)) . (columns "maj7" ((font-relative-size . -2) ((raise . 0.2) (music (named "accidentals--1")))) "5"))
472 (((0 . 0) (2 . 0) (4 . -1) (6 . -1)) . (columns "7" ((font-relative-size . -2) ((raise . 0.2) (music (named "accidentals--1")))) "5"))
473 (((0 . 0) (3 . 0) (4 . 0) (6 . -1)) . ("7sus4"))
474 ;; Common ninth chords
475 (((0 . 0) (2 . 0) (4 . 0) (5 . 0) (1 . 0)) . ("6/9")) ;; we don't want the '/no7'
476 (((0 . 0) (2 . 0) (4 . 0) (5 . 0)) . ("6"))
477 (((0 . 0) (2 . -1) (4 . 0) (5 . 0)) . ("m6"))
478 (((0 . 0) (2 . 0) (4 . 0) (1 . 0)) . ("add9"))
479 (((0 . 0) (2 . 0) (4 . 0) (6 . 0) (1 . 0)) . ("maj9"))
480 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . 0)) . ("9"))
481 (((0 . 0) (2 . -1) (4 . 0) (6 . -1) (1 . 0)) . ("m9"))
484 chord::names-alist-american))
487 ;; American style chordnames use no "no",
488 ;; but otherwise very similar to banter for now
489 (define (chord::name-american tonic exception-part unmatched-steps
490 bass-and-inversion steps)
491 (let ((additions (chord::additions unmatched-steps))
493 (chord::inner-name-banter tonic exception-part additions subtractions
494 bass-and-inversion steps)))
504 ;; Jazz chords, by Atte Andr'e Jensen <atte@post.com>
505 ;; NBs: This uses the american list as a bass.
506 ;; Some defs take up more than one line,
507 ;; be carefull when messing with ;'s!!
512 ;; This is getting out-of hand? Only exceptional chord names that
513 ;; cannot be generated should be here.
514 ;; Maybe we should have inner-name-jazz and inner-name-american functions;
518 ;; DONT use non-ascii characters, even if ``it works'' in Windows
520 (define chord::names-alist-jazz '())
521 (set! chord::names-alist-jazz
525 ; major sixth chord = 6
526 (((0 . 0) (2 . 0) (4 . 0) (5 . 0)) . (((raise . 0.5) "6")))
527 ; major seventh chord = triangle
528 ;; shouldn't this be a filled black triange, like this: ? --jcn
529 ;; (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . (((raise . 0.5)((font-family . math) "N"))))
530 (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . (((raise . 0.5)((font-family . math) "M"))))
531 ; major chord add nine = add9
532 (((0 . 0) (2 . 0) (4 . 0) (1 . 0)) . (((raise . 0.5) "add9")))
533 ; major sixth chord with nine = 6/9
534 (((0 . 0) (2 . 0) (4 . 0) (5 . 0) (1 . 0)) . (((raise . 0.5) "6/9")))
537 ; minor sixth chord = m6
538 (((0 . 0) (2 . -1) (4 . 0) (5 . 0)) . (columns("m")((raise . 0.5) "6")))
539 ;; minor major seventh chord = m triangle
540 ;; shouldn't this be a filled black triange, like this: ? --jcn
541 ;;(((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . (columns ("m") ((raise . 0.5)((font-family . math) "N"))))
542 (((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . (columns ("m") ((raise . 0.5)((font-family . math) "M"))))
543 ; minor seventh chord = m7
544 (((0 . 0) (2 . -1) (4 . 0) (6 . -1)) . (columns("m")((raise . 0.5) "7")))
545 ; minor sixth nine chord = m6/9
546 (((0 . 0) (2 . -1) (4 . 0) (5 . 0) (1 . 0)) . (columns("m")((raise . 0.5) "6/9")))
547 ; minor with added nine chord = madd9
548 (((0 . 0) (2 . -1) (4 . 0) (1 . 0)) . (columns("m")((raise . 0.5) "add9")))
549 ; minor ninth chord = m9
550 (((0 . 0) (2 . -1) (4 . 0) (6 . -1) (1 . 0)) . (columns("m")((raise . 0.5) "9")))
553 ; dominant seventh = 7
554 (((0 . 0) (2 . 0) (4 . 0) (6 . -1)) . (((raise . 0.5) "7")))
555 ; augmented dominant = +7
556 ;(((0 . 0) (2 . 0) (4 . +1) (6 . -1)) . (((raise . 0.5) "+7"))) ; +7 with both raised
557 (((0 . 0) (2 . 0) (4 . +1) (6 . -1)) . (columns("+")((raise . 0.5) "7"))) ; +7 with 7 raised
558 ;(((0 . 0) (2 . 0) (4 . +1) (6 . -1)) . (columns((raise . 0.5) "7(")
559 ; ((raise . 0.3)(music (named ("accidentals-1"))))
560 ; ((raise . 0.5) "5)"))); 7(#5)
561 ; dominant flat 5 = 7(b5)
562 (((0 . 0) (2 . 0) (4 . -1) (6 . -1)) . (columns((raise . 0.5) "7(")
563 ((raise . 0.3)(music (named ("accidentals--1"))))
564 ((raise . 0.5) "5)")))
566 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . 0)) . (((raise . 0.8)"7(9)")))
567 ; dominant flat 9 = 7(b9)
568 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . -1)) . (
570 ((raise . 0.3)(music (named ("accidentals--1"))))
571 ((raise . 0.8)"9)")))
572 ; dominant sharp 9 = 7(#9)
573 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . +1)) . (
575 ((raise . 0.3)(music (named ("accidentals-1"))))
576 ((raise . 0.8)"9)")))
577 ; dominant 13 = 7(13)
578 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (5 . 0)) . (((raise . 0.8)"7(13)")))
579 ; dominant flat 13 = 7(b13)
580 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (5 . -1)) . (
582 ((raise . 0.3)(music (named ("accidentals--1"))))
583 ((raise . 0.8)"13)")))
584 ; dominant 9, 13 = 7(9,13)
585 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . 0) (5 . 0)) . (((raise . 0.8)"7(9, 13)")))
586 ; dominant flat 9, 13 = 7(b9,13)
587 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . -1) (5 . 0)) . (
589 ((raise . 0.3)(music (named ("accidentals--1"))))
590 ((raise . 0.8)"9, 13)")))
591 ; dominant sharp 9, 13 = 7(#9,13)
592 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . +1) (5 . 0)) . (
594 ((raise . 0.3)(music (named ("accidentals-1"))))
595 ((raise . 0.8)"9, 13)")))
596 ; dominant 9, flat 13 = 7(9,b13)
597 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . 0) (5 . -1)) . (
598 ((raise . 0.8)"7(9, ")
599 ((raise . 0.3)(music (named ("accidentals--1"))))
600 ((raise . 0.8)"13)")))
601 ; dominant flat 9, flat 13 = 7(b9,b13)
602 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . -1) (5 . -1)) . (
604 ((raise . 0.3)(music (named ("accidentals--1"))))
606 ((raise . 0.3)(music (named ("accidentals--1"))))
607 ((raise . 0.8)"13)")))
608 ; dominant sharp 9, flat 13 = 7(#9,b13)
609 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . +1) (5 . -1)) . (
611 ((raise . 0.3)(music (named ("accidentals-1"))))
613 ((raise . 0.3)(music (named ("accidentals--1"))))
614 ((raise . 0.8)"13)")))
616 ;; diminished chord(s)
617 ; diminished seventh chord = o
620 ;; DONT use non-ascii characters, even if ``it works'' in Windows
622 ;;(((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . ((raise . 0.8) (size . -2) ("o")))
623 (((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . ("" (super "o")))
625 ;; half diminshed chords
626 ;; half diminished seventh chord = slashed o
627 ;; (((0 . 0) (2 . -1) (4 . -1) (6 . -1)) . (((raise . 0.8) "/o")))
628 (((0 . 0) (2 . -1) (4 . -1) (6 . -1)) . (columns (super (overstrike "o") "/") " " "7")) ; slashed o
630 ; half diminished seventh chord with major 9 = slashed o cancelation 9
631 (((0 . 0) (2 . -1) (4 . -1) (6 . -1) (1 . 0)) . (
633 ((raise . 0.3)(music (named ("accidentals-0"))))
634 ((raise . 0.8)"9)")));
636 ;; Missing jazz chord definitions go here (note new syntax: see american for hints)
639 chord::names-alist-american))
641 (define (step->text-alternate-jazz pitch)
643 (accidental->text (caddr pitch))
644 (number->string (+ (cadr pitch) (if (= (car pitch) 0) 1 8)))))
646 (define (step->text-jazz pitch)
647 (if (= (cadr pitch) 6)
649 ;; sharp 7 only included for completeness?
650 ((-2) (text-append (accidental->text -1) '("7")))
653 ((1) (text-append (accidental->text-super 1) '("7")))
654 ((2) (text-append (accidental->text-super 2) '("7"))))
655 (step->text-alternate-jazz pitch)))
657 (define (xchord::additions->text-jazz additions subtractions)
658 (if (pair? additions)
660 (let ((step (step->text-jazz (car additions))))
661 (if (or (pair? (cdr additions))
662 (pair? subtractions))
663 (text-append step "/")
665 (chord::additions->text-jazz (cdr additions) subtractions))
668 (define (chord::>5? x)
674 ;; Perhaps all logic like this should be done earlier,
675 ;; so that in this text-construction printing phase
676 ;; we can just blindly create text from all additions.
678 ;; This depends maybe on the fact of code sharing,
679 ;; in this layout, we can share the functions chord::additions
680 ;; and chord::subtractions with banter.
681 (define (chord::additions->text-jazz additions subtractions)
683 (chord::additions<=5->text-jazz (filter-out-list chord::>5? additions)
684 (filter-out-list chord::>5? subtractions))
685 (chord::additions>5->text-jazz (filter-list chord::>5? additions)
686 (filter-list chord::>5? subtractions))))
689 (define (chord::additions<=5->text-jazz additions subtractions)
690 (let ((sus (chord::sus-four-jazz additions)))
692 (text-append '("sus") (step->text-jazz (car sus)))
695 (define (chord::additions>5->text-jazz additions subtractions)
697 Compose text of all additions
699 * if there's a subtraction:
701 - list all up to highest
702 * list all steps that are below an chromatically altered step
705 (if (not (empty? subtractions)) "add" '())
706 (let ((radds (reverse additions)))
707 (reverse (chord::additions>5->text-jazz-helper
710 (if (or (empty? subtractions) (empty? radds))
713 (define (chord::additions>5->text-jazz-helper additions subtractions list-step)
715 Create texts for all additions
716 If list-step != #f, list all steps down to 5
717 If we encounter a chromatically altered step, turn on list-step
721 (if (not (member list-step subtractions))
722 (if (> 5 (cadr list-step))
723 (cons (step->text-jazz list-step)
724 (chord::additions>5->text-jazz-helper
727 (chord::get-create-step additions
728 (- (cadr list-step) 2))))
729 (step->text-jazz list-step))
730 (chord::get-create-step additions (- (cadr list-step) 2)))
731 (if (pair? additions)
732 (let ((step (car additions)))
733 (cons (step->text-jazz step)
734 (chord::additions>5->text-jazz-helper
737 (if (or (and (!= 6 (cadr step)) (!= 0 (caddr step)))
738 (and (= 6 (cadr step)) (!= -1 (caddr step))))
739 (chord::get-create-step additions (- (cadr step) 2))
743 (define (chord::sus-four-jazz chord-pitches)
744 "List of pitches that are step 2 or step 4"
745 (filter-list (lambda (x)
747 (or (= 1 (cadr x)) (= 3 (cadr x))))) chord-pitches))
749 (define (chord::get-create-step steps n)
750 (let* ((i (if (< n 0) (+ n 7) n))
751 (found (filter-list (lambda (x) (= i (cadr x))) steps)))
758 (define (chord::subtractions->text-jazz subtractions)
759 (if (pair? subtractions)
761 (if (= 5 (cadr (car subtractions)))
764 (let ((step (step->text-jazz (car subtractions))))
765 (if (pair? (cdr subtractions))
766 (text-append step "/")
769 (chord::subtractions->text-jazz (cdr subtractions)))
773 ;; TODO: maybe merge with inner-name-banter
774 ;; Combine tonic, exception-part of chord name,
775 ;; additions, subtractions and bass or inversion into chord name
776 (define (chord::inner-name-jazz tonic exception-part additions subtractions
777 bass-and-inversion steps)
779 (pitch->chord-name-text-banter tonic steps)
781 ;; why does list->string not work, format seems only hope...
782 (if (and (string-match "super" (format "~s" exception-part))
783 (or (pair? additions)
784 (pair? subtractions)))
785 (list simple-super "/"))
787 (list `(,simple-super)
788 (chord::additions->text-jazz additions subtractions)
789 (chord::subtractions->text-jazz subtractions))
790 (chord::bass-and-inversion->text-banter bass-and-inversion)))
792 ;; Jazz style--basically similar to american with minor changes
794 ;; Consider Dm6. When we get here:
795 ;; tonic = '(0 1 0) (note d=2)
796 ;; steps = '((0 0 0) '(0 2 -1) (0 4 0) (0 5 0))
797 ;; steps are transposed for tonic c, octave 0,
798 ;; so (car steps) is always (0 0 0)
800 ;; assuming that the exceptions-alist has an entry
801 ;; '(((0 . 0) (2 . -1)) . ("m"))
802 ;; (and NOT the full chord, like std jazz list, ugh)
803 ;; unmatch = '((0 0 0) (0 2 0) (0 4 0) (0 5 0))
806 ;; You can look very easily what happens, if you add some write-me calls,
807 ;; and run lilypond on a simple file, eg, containing only the chord c:m6:
809 ;; (let ((additions (write-me "adds: "
810 ;; (chord::additions (write-me "unmatched:"
811 ;; unmatched-steps))))
813 ;; If you set subtract #f, the chord::inner-name-jazz does not see any
814 ;; subtractions, ever, so they don't turn up in the chord name.
816 (define (chord::name-jazz tonic exception-part unmatched-steps
817 bass-and-inversion steps)
818 (let ((additions (chord::additions unmatched-steps))
819 ;; get no 'omit' or 'no'
820 ;; (subtractions #f))
821 (subtractions (chord::subtractions unmatched-steps)))
822 (chord::inner-name-jazz tonic exception-part additions subtractions
823 bass-and-inversion steps)))
825 ;; wip (set! chord::names-alist-jazz
826 (define chord::names-alist-jazz
829 (((0 . 0) (2 . -1)) . ("m"))
831 ;; some fixups -- jcn
832 ; major seventh chord = triangle
833 (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . (((raise . 0.5)((font-family . math) "N"))))
834 ;; (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . (((raise . 0.5)((font-family . math) "M"))))
836 ;; minor major seventh chord = m triangle
837 (((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . (columns ("m") ((raise . 0.5)((font-family . math) "N"))))
838 ;; (((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . (columns ("m") ((raise . 0.5)((font-family . math) "M"))))
842 chord::names-alist-american))