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: align, 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 (pitch-octave p) (pitch-notename p) (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 (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 (chord::name->text style (car pitches) steps bass-and-inversion)))
432 ;; NOTE: Duplicates of chord names defined elsewhere occur in this list
433 ;; in order to prevent spurious superscripting of various chord names,
434 ;; such as maj7, maj9, etc.
436 ;; See input/test/american-chords.ly
438 ;; James Hammons, <jlhamm@pacificnet.net>
441 ;; DONT use non-ascii characters, even if ``it works'' in Windows
443 (define-public chord::names-alist-american '())
445 (set! chord::names-alist-american
449 (((0 . 0) (2 . 0)) . #f)
451 (((0 . 0) (4 . 0)) . ("5"))
453 (((0 . 0) (2 . -1)) . ("m"))
454 (((0 . 0) (3 . 0) (4 . 0)) . ("sus"))
455 (((0 . 0) (2 . -1) (4 . -1)) . ("dim"))
456 ;Alternate: (((0 . 0) (2 . -1) (4 . -1)) . ("" (super "o")))
457 (((0 . 0) (2 . 0) (4 . 1)) . ("aug"))
458 ;Alternate: (((0 . 0) (2 . 0) (4 . 1)) . ("+"))
459 (((0 . 0) (1 . 0) (4 . 0)) . ("2"))
460 ;; Common seventh chords
461 (((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . ("" (super "o") " " "7"))
462 (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . ("maj7"))
463 ;; urg! should use (0 . 0 2 . -1) -> "m", and add "7" to that!!
464 (((0 . 0) (2 . -1) (4 . 0) (6 . -1)) . ("m7"))
465 (((0 . 0) (2 . 0) (4 . 0) (6 . -1)) . ("7"))
466 (((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . ("m(maj7)"))
467 ;jazz: the delta, see jazz-chords.ly
468 ;;(((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . (super ((font-family . math) "N"))
470 (((0 . 0) (2 . -1) (4 . -1) (6 . -1)) . (columns (super (overstrike "o") "/") " " "7"))
472 (((0 . 0) (2 . 0) (4 . 1) (6 . -1)) . ("aug7"))
473 (((0 . 0) (2 . 0) (4 . -1) (6 . 0)) . (columns "maj7" ((font-relative-size . -2) ((raise . 0.2) (music (named "accidentals--1")))) "5"))
474 (((0 . 0) (2 . 0) (4 . -1) (6 . -1)) . (columns "7" ((font-relative-size . -2) ((raise . 0.2) (music (named "accidentals--1")))) "5"))
475 (((0 . 0) (3 . 0) (4 . 0) (6 . -1)) . ("7sus4"))
476 ;; Common ninth chords
477 (((0 . 0) (2 . 0) (4 . 0) (5 . 0) (1 . 0)) . ("6/9")) ;; we don't want the '/no7'
478 (((0 . 0) (2 . 0) (4 . 0) (5 . 0)) . ("6"))
479 (((0 . 0) (2 . -1) (4 . 0) (5 . 0)) . ("m6"))
480 (((0 . 0) (2 . 0) (4 . 0) (1 . 0)) . ("add9"))
481 (((0 . 0) (2 . 0) (4 . 0) (6 . 0) (1 . 0)) . ("maj9"))
482 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . 0)) . ("9"))
483 (((0 . 0) (2 . -1) (4 . 0) (6 . -1) (1 . 0)) . ("m9"))
486 chord::names-alist-american))
489 ;; American style chordnames use no "no",
490 ;; but otherwise very similar to banter for now
491 (define-public (chord::name-american tonic exception-part unmatched-steps
492 bass-and-inversion steps)
493 (let ((additions (chord::additions unmatched-steps))
495 (chord::inner-name-banter tonic exception-part additions subtractions
496 bass-and-inversion steps)))
506 ;; Jazz chords, by Atte Andr'e Jensen <atte@post.com>
507 ;; NBs: This uses the american list as a bass.
508 ;; Some defs take up more than one line,
509 ;; be carefull when messing with ;'s!!
514 ;; This is getting out-of hand? Only exceptional chord names that
515 ;; cannot be generated should be here.
516 ;; Maybe we should have inner-name-jazz and inner-name-american functions;
520 ;; DONT use non-ascii characters, even if ``it works'' in Windows
522 (define-public chord::names-alist-jazz '())
523 (set! chord::names-alist-jazz
527 ; major sixth chord = 6
528 (((0 . 0) (2 . 0) (4 . 0) (5 . 0)) . (((raise . 0.5) "6")))
529 ; major seventh chord = triangle
530 ;; shouldn't this be a filled black triange, like this: ? --jcn
531 ;; (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . (((raise . 0.5)((font-family . math) "N"))))
532 (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . (((raise . 0.5)((font-family . math) "M"))))
533 ; major chord add nine = add9
534 (((0 . 0) (2 . 0) (4 . 0) (1 . 0)) . (((raise . 0.5) "add9")))
535 ; major sixth chord with nine = 6/9
536 (((0 . 0) (2 . 0) (4 . 0) (5 . 0) (1 . 0)) . (((raise . 0.5) "6/9")))
539 ; minor sixth chord = m6
540 (((0 . 0) (2 . -1) (4 . 0) (5 . 0)) . (columns("m")((raise . 0.5) "6")))
541 ;; minor major seventh chord = m triangle
542 ;; shouldn't this be a filled black triange, like this: ? --jcn
543 ;;(((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . (columns ("m") ((raise . 0.5)((font-family . math) "N"))))
544 (((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . (columns ("m") ((raise . 0.5)((font-family . math) "M"))))
545 ; minor seventh chord = m7
546 (((0 . 0) (2 . -1) (4 . 0) (6 . -1)) . (columns("m")((raise . 0.5) "7")))
547 ; minor sixth nine chord = m6/9
548 (((0 . 0) (2 . -1) (4 . 0) (5 . 0) (1 . 0)) . (columns("m")((raise . 0.5) "6/9")))
549 ; minor with added nine chord = madd9
550 (((0 . 0) (2 . -1) (4 . 0) (1 . 0)) . (columns("m")((raise . 0.5) "add9")))
551 ; minor ninth chord = m9
552 (((0 . 0) (2 . -1) (4 . 0) (6 . -1) (1 . 0)) . (columns("m")((raise . 0.5) "9")))
555 ; dominant seventh = 7
556 (((0 . 0) (2 . 0) (4 . 0) (6 . -1)) . (((raise . 0.5) "7")))
557 ; augmented dominant = +7
558 ;(((0 . 0) (2 . 0) (4 . +1) (6 . -1)) . (((raise . 0.5) "+7"))) ; +7 with both raised
559 (((0 . 0) (2 . 0) (4 . +1) (6 . -1)) . (columns("+")((raise . 0.5) "7"))) ; +7 with 7 raised
560 ;(((0 . 0) (2 . 0) (4 . +1) (6 . -1)) . (columns((raise . 0.5) "7(")
561 ; ((raise . 0.3)(music (named ("accidentals-1"))))
562 ; ((raise . 0.5) "5)"))); 7(#5)
563 ; dominant flat 5 = 7(b5)
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)")))
568 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . 0)) . (((raise . 0.8)"7(9)")))
569 ; dominant flat 9 = 7(b9)
570 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . -1)) . (
572 ((raise . 0.3)(music (named ("accidentals--1"))))
573 ((raise . 0.8)"9)")))
574 ; dominant sharp 9 = 7(#9)
575 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . +1)) . (
577 ((raise . 0.3)(music (named ("accidentals-1"))))
578 ((raise . 0.8)"9)")))
579 ; dominant 13 = 7(13)
580 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (5 . 0)) . (((raise . 0.8)"7(13)")))
581 ; dominant flat 13 = 7(b13)
582 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (5 . -1)) . (
584 ((raise . 0.3)(music (named ("accidentals--1"))))
585 ((raise . 0.8)"13)")))
586 ; dominant 9, 13 = 7(9,13)
587 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . 0) (5 . 0)) . (((raise . 0.8)"7(9, 13)")))
588 ; dominant flat 9, 13 = 7(b9,13)
589 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . -1) (5 . 0)) . (
591 ((raise . 0.3)(music (named ("accidentals--1"))))
592 ((raise . 0.8)"9, 13)")))
593 ; dominant sharp 9, 13 = 7(#9,13)
594 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . +1) (5 . 0)) . (
596 ((raise . 0.3)(music (named ("accidentals-1"))))
597 ((raise . 0.8)"9, 13)")))
598 ; dominant 9, flat 13 = 7(9,b13)
599 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . 0) (5 . -1)) . (
600 ((raise . 0.8)"7(9, ")
601 ((raise . 0.3)(music (named ("accidentals--1"))))
602 ((raise . 0.8)"13)")))
603 ; dominant flat 9, flat 13 = 7(b9,b13)
604 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . -1) (5 . -1)) . (
606 ((raise . 0.3)(music (named ("accidentals--1"))))
608 ((raise . 0.3)(music (named ("accidentals--1"))))
609 ((raise . 0.8)"13)")))
610 ; dominant sharp 9, flat 13 = 7(#9,b13)
611 (((0 . 0) (2 . 0) (4 . 0) (6 . -1) (1 . +1) (5 . -1)) . (
613 ((raise . 0.3)(music (named ("accidentals-1"))))
615 ((raise . 0.3)(music (named ("accidentals--1"))))
616 ((raise . 0.8)"13)")))
618 ;; diminished chord(s)
619 ; diminished seventh chord = o
622 ;; DONT use non-ascii characters, even if ``it works'' in Windows
624 ;;(((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . ((raise . 0.8) (size . -2) ("o")))
625 (((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . ("" (super "o")))
627 ;; half diminshed chords
628 ;; half diminished seventh chord = slashed o
629 ;; (((0 . 0) (2 . -1) (4 . -1) (6 . -1)) . (((raise . 0.8) "/o")))
630 (((0 . 0) (2 . -1) (4 . -1) (6 . -1)) . (columns (super (overstrike "o") "/") " " "7")) ; slashed o
632 ; half diminished seventh chord with major 9 = slashed o cancelation 9
633 (((0 . 0) (2 . -1) (4 . -1) (6 . -1) (1 . 0)) . (
635 ((raise . 0.3)(music (named ("accidentals-0"))))
636 ((raise . 0.8)"9)")));
638 ;; Missing jazz chord definitions go here (note new syntax: see american for hints)
641 chord::names-alist-american))
643 (define (step->text-alternate-jazz pitch)
645 (accidental->text (caddr pitch))
646 (number->string (+ (cadr pitch) (if (= (car pitch) 0) 1 8)))))
648 (define (step->text-jazz pitch)
649 (if (= (cadr pitch) 6)
651 ;; sharp 7 only included for completeness?
652 ((-2) (text-append (accidental->text -1) '("7")))
655 ((1) (text-append (accidental->text-super 1) '("7")))
656 ((2) (text-append (accidental->text-super 2) '("7"))))
657 (step->text-alternate-jazz pitch)))
659 (define (xchord::additions->text-jazz additions subtractions)
660 (if (pair? additions)
662 (let ((step (step->text-jazz (car additions))))
663 (if (or (pair? (cdr additions))
664 (pair? subtractions))
665 (text-append step "/")
667 (chord::additions->text-jazz (cdr additions) subtractions))
670 (define (chord::>5? x)
676 ;; Perhaps all logic like this should be done earlier,
677 ;; so that in this text-construction printing phase
678 ;; we can just blindly create text from all additions.
680 ;; This depends maybe on the fact of code sharing,
681 ;; in this layout, we can share the functions chord::additions
682 ;; and chord::subtractions with banter.
683 (define (chord::additions->text-jazz additions subtractions)
685 (chord::additions<=5->text-jazz (filter-out-list chord::>5? additions)
686 (filter-out-list chord::>5? subtractions))
687 (chord::additions>5->text-jazz (filter-list chord::>5? additions)
688 (filter-list chord::>5? subtractions))))
691 (define (chord::additions<=5->text-jazz additions subtractions)
692 (let ((sus (chord::sus-four-jazz additions)))
694 (text-append '("sus") (step->text-jazz (car sus)))
697 (define (chord::additions>5->text-jazz additions subtractions)
699 Compose text of all additions
701 * if there's a subtraction:
703 - list all up to highest
704 * list all steps that are below an chromatically altered step
707 (if (not (null? subtractions)) "add" '())
708 (let ((radds (reverse additions)))
709 (reverse (chord::additions>5->text-jazz-helper
712 (if (or (null? subtractions) (null? radds))
715 (define (chord::additions>5->text-jazz-helper additions subtractions list-step)
717 Create texts for all additions
718 If list-step != #f, list all steps down to 5
719 If we encounter a chromatically altered step, turn on list-step
723 (if (not (member list-step subtractions))
724 (if (> 5 (cadr list-step))
725 (cons (step->text-jazz list-step)
726 (chord::additions>5->text-jazz-helper
729 (chord::get-create-step additions
730 (- (cadr list-step) 2))))
731 (step->text-jazz list-step))
732 (chord::get-create-step additions (- (cadr list-step) 2)))
733 (if (pair? additions)
734 (let ((step (car additions)))
735 (cons (step->text-jazz step)
736 (chord::additions>5->text-jazz-helper
739 (if (or (and (!= 6 (cadr step)) (!= 0 (caddr step)))
740 (and (= 6 (cadr step)) (!= -1 (caddr step))))
741 (chord::get-create-step additions (- (cadr step) 2))
745 (define (chord::sus-four-jazz chord-pitches)
746 "List of pitches that are step 2 or step 4"
747 (filter-list (lambda (x)
749 (or (= 1 (cadr x)) (= 3 (cadr x))))) chord-pitches))
751 (define (chord::get-create-step steps n)
752 (let* ((i (if (< n 0) (+ n 7) n))
753 (found (filter-list (lambda (x) (= i (cadr x))) steps)))
760 (define (chord::subtractions->text-jazz subtractions)
761 (if (pair? subtractions)
763 (if (= 5 (cadr (car subtractions)))
766 (let ((step (step->text-jazz (car subtractions))))
767 (if (pair? (cdr subtractions))
768 (text-append step "/")
771 (chord::subtractions->text-jazz (cdr subtractions)))
775 ;; TODO: maybe merge with inner-name-banter
776 ;; Combine tonic, exception-part of chord name,
777 ;; additions, subtractions and bass or inversion into chord name
778 (define (chord::inner-name-jazz tonic exception-part additions subtractions
779 bass-and-inversion steps)
781 (pitch->chord-name-text-banter tonic steps)
783 ;; why does list->string not work, format seems only hope...
784 (if (and (string-match "super" (format "~s" exception-part))
785 (or (pair? additions)
786 (pair? subtractions)))
787 (list simple-super "/"))
789 (list `(,simple-super)
790 (chord::additions->text-jazz additions subtractions)
791 (chord::subtractions->text-jazz subtractions))
792 (chord::bass-and-inversion->text-banter bass-and-inversion)))
794 ;; Jazz style--basically similar to american with minor changes
796 ;; Consider Dm6. When we get here:
797 ;; tonic = '(0 1 0) (note d=2)
798 ;; steps = '((0 0 0) '(0 2 -1) (0 4 0) (0 5 0))
799 ;; steps are transposed for tonic c, octave 0,
800 ;; so (car steps) is always (0 0 0)
802 ;; assuming that the exceptions-alist has an entry
803 ;; '(((0 . 0) (2 . -1)) . ("m"))
804 ;; (and NOT the full chord, like std jazz list, ugh)
805 ;; unmatch = '((0 0 0) (0 2 0) (0 4 0) (0 5 0))
808 ;; You can look very easily what happens, if you add some write-me calls,
809 ;; and run lilypond on a simple file, eg, containing only the chord c:m6:
811 ;; (let ((additions (write-me "adds: "
812 ;; (chord::additions (write-me "unmatched:"
813 ;; unmatched-steps))))
815 ;; If you set subtract #f, the chord::inner-name-jazz does not see any
816 ;; subtractions, ever, so they don't turn up in the chord name.
818 (define-public (chord::name-jazz tonic exception-part unmatched-steps
819 bass-and-inversion steps)
820 (let ((additions (chord::additions unmatched-steps))
821 ;; get no 'omit' or 'no'
822 ;; (subtractions #f))
823 (subtractions (chord::subtractions unmatched-steps)))
824 (chord::inner-name-jazz tonic exception-part additions subtractions
825 bass-and-inversion steps)))
827 ;; wip (set! chord::names-alist-jazz
828 (define chord::names-alist-jazz
831 (((0 . 0) (2 . -1)) . ("m"))
833 ;; some fixups -- jcn
834 ; major seventh chord = triangle
835 (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . (((raise . 0.5)((font-family . math) "N"))))
836 ;; (((0 . 0) (2 . 0) (4 . 0) (6 . 0)) . (((raise . 0.5)((font-family . math) "M"))))
838 ;; minor major seventh chord = m triangle
839 (((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . (columns ("m") ((raise . 0.5)((font-family . math) "N"))))
840 ;; (((0 . 0) (2 . -1) (4 . 0) (6 . 0)) . (columns ("m") ((raise . 0.5)((font-family . math) "M"))))
844 chord::names-alist-american))