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>
18 (define-public (write-me x)
19 "Write and return X. For debugging purposes. "
20 (write x) (newline) x)
22 ;(define (dbg x) (write-me x))
25 ;;(define (write-me x) (write x) (newline) x)
26 ;;(define (write-me-2 x y) (write "FOO") (write x) (write y) (newline) y)
32 * Use lilypond Pitch objects -- SCM pitch objects lead to
33 duplication. LilyPond pitch objects force meaningful names
34 (i.e. (ly:pitch-octave PITCH) )
36 * Pitches are musical objects. The pitches -> markup step should
37 happen earlier (during interpreting), brew-molecule () should only
38 dump reinterpret the markup as a molecule.
40 * chord:: prefix is a poor-man's namespace device.
41 We have a module system to prevent export to userland.
42 Nested functions can take care of many other clashes. --hwn.
44 * easier tweakability:
46 - split chord::names-alists up into logical bits,
47 such as chord::exceptions-delta, exceptions-oslash
48 - iso just the 'style parameter, use a list, eg:
49 \property ChordNames.ChordName \set
50 #'style = #'(jazz delta oslash german-tonic german-Bb)
52 * clean split/merge of bass/banter/american stuff.
53 GET RID OF code duplication.
61 ;; " hey Emacs: string has ended
64 ;; pitch = (octave notename alteration)
66 ;; note = (notename . alteration)
68 ;; markup = markup text -- see font.scm and input/test/markup.ly
71 (define-public chord::exception-alist-banter
74 (((0 . 0)) . ,empty-markup)
76 (((0 . 0) (2 . 0)) . ,empty-markup)
78 (((0 . 0) (2 . -1)) . ,(make-simple-markup "m"))
80 (((0 . 0) (1 . 0) (4 . 0))
81 . ,(make-normal-size-super-markup (make-simple-markup "2 ")))
83 (((0 . 0) (3 . 0) (4 . 0))
84 . ,(make-normal-size-super-markup (make-simple-markup "4 ")))
86 (((0 . 0) (2 . -1) (4 . -1)) . ,(make-simple-markup "dim"))
87 ; URG: Simply C:m5-/maj7 iso Cdim maj7
88 (((0 . 0) (2 . -1) (4 . -1) (6 . 0))
91 (make-simple-markup "m")
92 (make-normal-size-super-markup (make-simple-markup "5-/maj7 ")))))
93 ; URG: Simply C:m5-/7 iso Cdim7
94 (((0 . 0) (2 . -1) (4 . -1) (6 . -1))
97 (make-simple-markup "m")
98 (make-normal-size-super-markup (make-simple-markup "5-/7 ")))))
100 (((0 . 0) (2 . -1) (4 . -1) (6 . -2))
101 . ,(make-super-markup (make-simple-markup "o")))
103 (((0 . 0) (2 . -1) (4 . -1) (6 . -2) (1 . -1))
105 (list (make-simple-markup "dim")
106 (make-normal-size-super-markup (make-simple-markup "9 ")))))
107 (((0 . 0) (2 . -1) (4 . -1) (6 . -2) (1 . -1) (3 . -1))
109 (list (make-simple-markup "dim")
110 (make-normal-size-super-markup
111 (make-simple-markup "11 ")))))
115 ; pitch->note-name: drops octave
116 (define (pitch->note-name pitch)
117 (cons (cadr pitch) (caddr pitch)))
119 (define (accidental->markup acc)
120 "ACC is an int, return a markup making an accidental."
122 (make-line-markup (list empty-markup))
123 (make-smaller-markup (make-musicglyph-markup
124 (string-append "accidentals-"
125 (number->string acc))))))
128 (define (accidental->markupp acc pos)
132 (let ((acc-markup (make-musicglyph-markup
133 (string-append "accidentals-"
134 (number->string acc)))))
136 (if (equal? pos 'columns)
137 (make-line-markup (list (make-smaller-markup acc-markup)))
138 (if (equal? pos 'super)
139 (make-line-markup (list (make-super-markup acc-markup)))
140 ;; not 'super or 'columns must be 'sub...
141 (make-line-markup (list (make-sub-markup acc-markup))))))))
146 ;; FIXME: possibly to be used for american/jazz style
147 ;; However, only pos == columns is used, which seems to do
148 ;; exactly what accidental->markup does...
149 (define (amy-accidental->text acc) (accidental->textp acc 'columns))
153 ;;;(define (accidental->text-super acc) (accidental->textp acc 'simple-super))
154 ;;(define (accidental->text-super acc) (accidental->textp acc 'super))
155 ;;(define (accidental->text-sub acc) (accidental->textp acc 'sub))
159 ;; TODO: invent sensible way to make note name tweaking possible?
161 (define (pitch->markup pitch)
165 (vector-ref #("C" "D" "E" "F" "G" "A" "B") (cadr pitch)))
166 (make-normal-size-super-markup
167 (accidental->markup (caddr pitch))))))
169 ;;; Hooks to override chord names and note names,
170 ;;; see input/tricks/german-chords.ly
172 (define pitch->markup-banter pitch->markup)
174 ;; We need also steps, to allow for Cc name override,
175 ;; see input/test/Cc-chords.ly
176 (define (pitch->chord-name-markup-banter pitch steps)
177 (pitch->markup-banter pitch))
179 (define pitch->note-name-markup-banter pitch->markup-banter)
181 (define (step->markup pitch)
183 (number->string (+ (cadr pitch) (if (= (car pitch) 0) 1 8)))
191 (define (step->markup-banter pitch)
193 (if (= (cadr pitch) 6)
200 (step->markup pitch))))
202 (define (step->markup-previously-alternate-jazz pitch)
205 (accidental->markup (caddr pitch))
207 (number->string (+ (cadr pitch) (if (= (car pitch) 0) 1 8)))))))
209 (define (step->markup-previously-jazz pitch)
210 (if (= (cadr pitch) 6)
212 ;; sharp 7 only included for completeness?
213 ((-2) (make-line-markup
215 (accidental->markup -1)
216 (make-simple-markup "7"))))
217 ((-1) (make-simple-markup "7"))
218 ((0) (make-simple-markup "maj7"))
219 ;;((0) (make-line-markup
220 ;; (list (make-simple-markup "maj7"))))
221 ((1) (make-line-markup
223 (accidental->markup 1) (make-simple-markup "7"))))
224 ((2) (make-line-markup
225 (list (accidental->markup 1)
226 (make-simple-markup "7")))))
227 (step->markup-previously-alternate-jazz pitch)))
230 (define pitch::semitone-vec #(0 2 4 5 7 9 11))
232 (define (pitch::semitone pitch)
233 (+ (* (car pitch) 12)
234 (vector-ref pitch::semitone-vec (modulo (cadr pitch) 7))
237 (define (pitch::< l r)
238 (< (pitch::semitone l) (pitch::semitone r)))
240 (define (pitch::transpose pitch delta)
241 (let ((simple-octave (+ (car pitch) (car delta)))
242 (simple-notename (+ (cadr pitch) (cadr delta))))
243 (let ((octave (+ simple-octave (quotient simple-notename 7)))
244 (notename (modulo simple-notename 7)))
245 (let ((accidental (- (+ (pitch::semitone pitch) (pitch::semitone delta))
246 (pitch::semitone `(,octave ,notename 0)))))
247 `(,octave ,notename ,accidental)))))
249 (define (pitch::diff pitch tonic)
250 (let ((simple-octave (- (car pitch) (car tonic)))
251 (simple-notename (- (cadr pitch) (cadr tonic))))
252 (let ((octave (+ simple-octave (quotient simple-notename 7)
253 (if (< simple-notename 0) -1 0)))
254 (notename (modulo simple-notename 7)))
255 (let ((accidental (- (pitch::semitone pitch)
256 (pitch::semitone tonic)
257 (pitch::semitone `(,octave ,notename 0)))))
258 `(,octave ,notename ,accidental)))))
260 (define (pitch::note-pitch pitch)
261 (+ (* (car pitch) 7) (cadr pitch)))
265 (define chord::minor-major-vec #(0 -1 -1 0 -1 -1 0))
268 ;; compute the relative-to-tonic pitch that goes with 'step'
269 (define (chord::step-pitch tonic step)
270 ;; urg, we only do this for thirds
271 (if (= (modulo step 2) 0)
273 (let loop ((i 1) (pitch tonic))
277 pitch `(0 2 ,(vector-ref chord::minor-major-vec
278 ;; -1 (step=1 -> vector=0) + 7 = 6
279 (modulo (+ i 6) 7)))))))))
281 (define (chord::additions steps)
283 * any even step (2, 4, 6)
284 * any uneven step that is chromatically altered,
285 (where 7-- == -1, 7- == 0, 7 == +1)
288 ?and jazz needs also:
290 * TODO: any uneven step that's lower than an uneven step which is
291 chromatically altered
293 (let ((evens (filter-list (lambda (x) (!= 0 (modulo (cadr x) 2))) steps))
295 (filter-list (lambda (x)
296 (let ((n (cadr x)) (a (caddr x)))
297 (or (and (= 6 n) (!= -1 a))
302 (highest (let ((h (car (last-pair steps))))
303 (if (and (not (null? h))
308 ;; Hmm, what if we have a step twice, can we ignore that?
309 (uniq-list (sort (apply append evens altered-unevens highest)
313 ;; FIXME: unLOOP, see ::additions
314 ;; find the pitches that are missing from `normal' chord
315 (define (chord::subtractions chord-pitches)
316 (let ((tonic (car chord-pitches)))
317 (let loop ((step 1) (pitches chord-pitches) (subtractions '()))
319 (let* ((pitch (car pitches))
320 (p-step (+ (- (pitch::note-pitch pitch)
321 (pitch::note-pitch tonic))
323 ;; pitch is an subtraction if
324 ;; a step is missing or
326 (loop (+ step 2) pitches
327 (cons (chord::step-pitch tonic step) subtractions))
328 ;; there are no pitches left, but base thirds are not yet done and
330 (= (length pitches) 1))
331 ;; present pitch is not missing step
333 (loop (+ step 2) pitches subtractions)
334 (loop (+ step 2) pitches
335 (cons (chord::step-pitch tonic step) subtractions)))
337 (loop (+ step 2) (cdr pitches) subtractions)
338 (loop step (cdr pitches) subtractions)))))
339 (reverse subtractions)))))
341 (define (chord::additions->markup-banter additions subtractions)
342 (if (pair? additions)
345 (let ((step (step->markup-banter (car additions))))
346 (if (or (pair? (cdr additions))
347 (pair? subtractions))
349 (list step (make-simple-markup "/")))
351 (chord::additions->markup-banter (cdr additions) subtractions)))
354 (define (chord::subtractions->markup-banter subtractions)
355 (if (pair? subtractions)
358 (make-simple-markup "no")
359 (let ((step (step->markup-previously-jazz
360 (car subtractions))))
361 (if (pair? (cdr subtractions))
363 (list step (make-simple-markup "/")))
365 (chord::subtractions->markup-banter (cdr subtractions))))
368 (define (chord::bass-and-inversion->markup-banter bass-and-inversion)
369 (if (and (pair? bass-and-inversion)
370 (or (car bass-and-inversion)
371 (cdr bass-and-inversion)))
374 (make-simple-markup "/")
375 (pitch->note-name-markup-banter
376 (if (car bass-and-inversion)
377 (car bass-and-inversion)
378 (cdr bass-and-inversion)))))
381 ;; FIXME: merge this function with inner-name-jazz, -american
382 ;; iso using chord::bass-and-inversion->markup-banter,
383 ;; See: chord::exceptions-lookup
384 (define (chord::inner-name-banter tonic exception-part additions subtractions
385 bass-and-inversion steps)
389 Combine tonic, exception-part of chord name,
390 additions, subtractions and bass or inversion into chord name
393 (let* ((tonic-markup (pitch->chord-name-markup-banter tonic steps))
394 (except-markup (if exception-part exception-part empty-markup))
395 (sep-markup (if (and exception-part
396 (let ((s (format "~s" except-markup)))
398 (string-match "super" s)
400 ;; python: `except_markup`[-5:] != '"o"))'
404 (- (string-length s) 5))))))
405 (or (pair? additions)
406 (pair? subtractions)))
407 (make-super-markup (make-simple-markup "/"))
409 (adds-markup (chord::additions->markup-banter additions subtractions))
410 (subs-markup (chord::subtractions->markup-banter subtractions))
411 (b+i-markup (chord::bass-and-inversion->markup-banter
412 bass-and-inversion)))
419 (make-normal-size-super-markup
420 (make-line-markup (list adds-markup subs-markup)))
423 (define (c++-pitch->scm p)
425 (list (ly:pitch-octave p) (ly:pitch-notename p) (ly:pitch-alteration p))
428 (define (chord::name-banter tonic exception-part unmatched-steps
429 bass-and-inversion steps)
430 (let ((additions (chord::additions unmatched-steps))
431 (subtractions (chord::subtractions unmatched-steps)))
433 (chord::inner-name-banter tonic exception-part additions subtractions
434 bass-and-inversion steps)))
438 (define (chord::exceptions-lookup exceptions steps)
440 return (MATCHED-EXCEPTION . BASE-CHORD-WITH-UNMATCHED-STEPS)
441 BASE-CHORD-WITH-UNMATCHED-STEPS always includes (tonic 3 5)
444 ;; this is unintelligible.
446 (define (chord::exceptions-lookup-helper
447 exception-alist try-steps unmatched-steps exception-part)
450 check exception-alist for biggest matching part of try-steps
451 return (MATCHED-EXCEPTION . UNMATCHED-STEPS)
454 (if (pair? try-steps)
455 ;; FIXME: junk '(0 . 0) from exceptions lists?
456 ;; if so: how to handle first '((0 . 0) . #f) entry?
458 ;; FIXME: either format exceptions list as real pitches, ie,
459 ;; including octave '((0 2 -1) ..), or drop octave
460 ;; from rest of calculations,
462 (map (lambda (x) (pitch->note-name x))
463 (append '((0 0 0)) try-steps))
466 (chord::exceptions-lookup-helper
467 #f '() unmatched-steps (cdr entry))
468 (let ((r (reverse try-steps)))
469 (chord::exceptions-lookup-helper
472 (cons (car r) unmatched-steps) #f))))
473 (cons exception-part unmatched-steps)))
475 (let* ((result (chord::exceptions-lookup-helper
478 (exception-part (car result))
479 (unmatched-steps (cdr result))
480 (matched-steps (if (= (length unmatched-steps) 0)
482 (+ 1 (- (length steps)
483 (length unmatched-steps)))))
484 (unmatched-with-1-3-5
485 (append (do ((i matched-steps (- i 1))
486 (base '() (cons `(0 ,(* (- i 1) 2) 0) base)))
490 (list exception-part unmatched-with-1-3-5)))
497 ;; See input/test/american-chords.ly
499 ;; Original Version by James Hammons, <jlhamm@pacificnet.net>
500 ;; Complete rewrite by Amelie Zapf, <amy@loueymoss.com>
502 ;; DONT use non-ascii characters, even if ``it works'' in Windows
505 (define mathm-markup-object
506 (make-override-markup '(font-family . math) (make-simple-markup "M")))
509 (define mathn-markup-object
510 (make-override-markup '(font-family . math) (make-simple-markup "N")))
512 (define (step->markup-accidental pitch)
514 ((-2) (accidental->markup -2))
515 ((-1) (accidental->markup -1))
517 ((1) (accidental->markup 1))
518 ((2) (accidental->markup 2)))
519 (make-simple-markup (number->string (+ (cadr pitch) (if (= (car pitch) 0) 1 8)))))
521 (define-public chord::exception-alist-american
523 (((0 . 0)) . ,empty-markup)
524 (((0 . 0) (2 . -1)) . ,(make-simple-markup "m"))
526 ;; these should probably be normal-size? --jcn
527 ;;(((0 . 0) (4 . 0)) . ,(make-super-markup (make-simple-markup "5 ")))
528 ;;(((0 . 0) (1 . 0) (4 . 0)) . ,(make-super-markup (make-simple-markup "2 ")))
530 (((0 . 0) (4 . 0)) . ,(make-normal-size-super-markup (make-simple-markup "5 ")))
531 (((0 . 0) (1 . 0) (4 . 0)) . ,(make-normal-size-super-markup (make-simple-markup "2 ")))
533 ;;choose your symbol for the fully diminished chord
534 (((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . ,(make-simple-markup "dim"))
535 ;;(((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . ,(make-line-markup (list empty-markup (make-super-markup (make-simple-markup "o")))))
538 (define (step->markup-american pitch)
540 ((6) (case (caddr pitch)
541 ((-2) (make-line-markup (list (accidental->markup -1) (make-simple-markup "7"))))
542 ((-1) (make-simple-markup "7"))
543 ((0) (make-simple-markup "maj7"))
544 ((1) (make-line-markup (list (accidental->markup 1) (make-simple-markup "7"))))
545 ((2) (make-line-markup (list (accidental->markup 2) (make-simple-markup "7"))))))
546 ((4) (case (caddr pitch)
547 ((-2) (make-line-markup (list (accidental->markup -2) (make-simple-markup "5"))))
548 ;;choose your symbol for the diminished fifth
549 ((-1) (make-simple-markup "-5"))
550 ;;((-1) (make-line-markup (list (accidental->markup -1) (make-simple-markup "5")))))
552 ;;choose your symbol for the augmented fifth
553 ;;((1) (make-simple-markup "aug"))
554 ;;((1) (make-line-markup (list (accidental->markup 1) (make-simple-markup "5")))))
555 ((1) (make-simple-markup "+5"))
556 ((2) (make-line-markup (list (accidental->markup 2) (make-simple-markup "5"))))))
557 (else (if (and (= (car pitch) 0)
560 (make-simple-markup "sus4")
561 (step->markup-accidental pitch)))))
563 (define (chord::additions->markup-american additions subtractions)
564 (if (pair? additions)
565 ;; I don't like all this reasoning here, when we're actually typesetting.
566 (if(and(pair? (cdr additions)) ;a further addition left over
567 (or(and(= 0 (caddr(car additions))) ;this addition natural
568 (not(= 6 (cadr(car additions)))))
569 (and(= -1 (caddr(car additions)))
570 (= 6 (cadr(car additions)))))
571 (or(and(= 0 (caddr(cadr additions))) ;the following addition natural
572 (not(= 6 (cadr(cadr additions)))))
573 (and(= -1 (caddr(cadr additions)))
574 (= 6 (cadr(cadr additions)))))
575 (or(and(= (car(car additions)) (car(cadr additions))) ;both a third apart
576 (= 2 (- (cadr(cadr additions)) (cadr(car additions)))))
577 (and(= 1 (- (car(cadr additions)) (car(car additions))))
578 (= 5 (- (cadr(car additions)) (cadr(cadr additions))))))
579 (or(null? subtractions) ;this or clause protects the "adds"
580 (and (pair? subtractions)
581 (or (< (car(cadr additions)) (car(car subtractions)))
582 (and(= (car(cadr additions)) (car(car subtractions)))
583 (< (cadr(cadr additions)) (cadr(car subtractions))))))))
584 (chord::additions->markup-american (cdr additions) subtractions)
587 (let ((step (step->markup-american (car additions))))
588 (if (or (pair? (cdr additions))
589 (pair? subtractions))
590 (if (and (pair? (cdr additions))
591 (or(< 3 (- (cadr(cadr additions)) (cadr(car additions))))
592 (and(< 0 (- (car(cadr additions)) (car(car additions))))
593 (> 4 (- (cadr(car additions)) (cadr(cadr additions)))))))
594 (make-line-markup (list step (make-simple-markup " add")))
595 ;; tweak your favorite separator here
596 ;; (make-line-markup (list step (make-simple-markup "/")))
597 (make-line-markup (list step (make-simple-markup " "))))
599 (chord::additions->markup-american (cdr additions) subtractions))))
602 (define (chord::inner-name-american tonic exception-part additions subtractions
603 bass-and-inversion steps)
604 (let* ((tonic-markup (pitch->chord-name-markup-banter tonic steps))
605 (except-markup (if exception-part exception-part empty-markup))
606 (sep-markup (if (and (string-match "super" (format "~s" except-markup))
607 (or (pair? additions)
608 (pair? subtractions)))
609 (make-super-markup (make-simple-markup "/"))
611 ;;this list contains all the additions that go "in line"
615 (let ((o (car x)) (n (cadr x)) (a (caddr x)))
616 (and (not (and (= 0 o) (= 2 n))) ;gets rid of unwanted thirds
617 ;;change this if you want it differently
618 (not (and (= 0 o) (= 3 n) (= 0 a))) ;sus4
619 (not (and (= 0 o) (= 4 n) (!= 0 a)))))) ;alt5
621 ;;this list contains all the additions that are patched onto the end
622 ;;of the chord symbol, usually sus4 and altered 5ths.
624 ;;take out the reverse if it bothers you in a pathological chord
628 (let ((o (car x)) (n (cadr x)) (a (caddr x)))
629 (and(not (and (= 0 o) (= 2 n))) ;gets rid of unwanted thirds
630 ;;change this correspondingly
631 (or(and (= 0 o) (= 3 n) (= 0 a)) ;sus4
632 (and (= 0 o) (= 4 n) (!= 0 a)))))) ;alt5
634 (relevant-subs (filter-list
635 (lambda (x) ;catches subtractions higher than 5th
636 (let((o (car x)) (n (cadr x)))
640 (pref-markup (chord::additions->markup-american prefixes relevant-subs))
641 (suff-markup (chord::additions->markup-american suffixes relevant-subs))
642 (b+i-markup (chord::bass-and-inversion->markup-banter bass-and-inversion)))
645 tonic-markup except-markup sep-markup
646 (make-normal-size-super-markup
647 (make-line-markup (list pref-markup suff-markup)))
650 (define (chord::additions-american steps)
651 (let ((evens (filter-list (lambda (x) (!= 0 (modulo (cadr x) 2))) steps))
652 ;we let all the unevens pass for now, we'll fix that later.
654 (filter-list (lambda (x)
655 (let ((n (cadr x)) (a (caddr x)))
656 (or (and (= 6 n) (!= -1 a))
658 (= 0 (modulo n 2))))))
660 (highest (let ((h (car (last-pair steps))))
661 (if (and (not (null? h))
666 (uniq-list (sort (apply append evens unevens highest)
669 ;; American style chordnames use no "no",
670 ;; but otherwise very similar to banter for now
671 (define-public (chord::name-american tonic exception-part unmatched-steps
672 bass-and-inversion steps)
673 (let ((additions (chord::additions-american unmatched-steps))
674 (subtractions (chord::subtractions unmatched-steps)))
675 (chord::inner-name-american tonic exception-part additions subtractions
676 bass-and-inversion steps)))
680 ;; Jazz chords, by Atte Andr'e Jensen <atte@post.com>
681 ;; Complete rewrite by Amelie Zapf (amy@loueymoss.com)
683 ;; FIXME: identical to chord::exception-alist-american, apart from commented
684 ;; dim chord. should merge.
685 (define-public chord::exception-alist-jazz
687 (((0 . 0)) . ,empty-markup)
688 (((0 . 0) (2 . -1)) . ,(make-simple-markup "m"))
690 ;; these should probably be normal-size? --jcn
691 ;;(((0 . 0) (4 . 0)) . ,(make-super-markup (make-simple-markup "5 ")))
692 ;;(((0 . 0) (1 . 0) (4 . 0)) . ,(make-super-markup (make-simple-markup "2 ")))
694 (((0 . 0) (4 . 0)) . ,(make-normal-size-super-markup (make-simple-markup "5 ")))
695 (((0 . 0) (1 . 0) (4 . 0)) . ,(make-normal-size-super-markup (make-simple-markup "2 ")))
697 ;;choose your symbol for the fully diminished chord
698 ;;(((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . ,(make-simple-markup "dim"))
699 (((0 . 0) (2 . -1) (4 . -1) (6 . -2)) . ,(make-line-markup (list (make-simple-markup "") (make-super-markup (make-simple-markup "o")))))
702 ;; FIXME: rather similar to step->markup-american. should merge.
703 (define (step->markup-jazz pitch)
705 ((6) (case (caddr pitch)
706 ((-2) (make-line-markup (list (accidental->markup -1) (make-simple-markup "7"))))
707 ((-1) (make-simple-markup "7"))
708 ;;Pick your favorite maj7
709 ((0) mathm-markup-object) ;;a white triangle
710 ;;((0) mathn-markup-object) ;;a black triangle
711 ;;((0) (make-simple-markup "maj7")) ;;good old maj7
712 ((1) (make-line-markup (list (accidental->markup 1) (make-simple-markup "7"))))
713 ((2) (make-line-markup (list (accidental->markup 2) (make-simple-markup "7"))))))
714 ((4) (case (caddr pitch)
715 ((-2) (make-line-markup (list (accidental->markup -2) (make-simple-markup "5"))))
716 ;;choose your symbol for the diminished fifth
717 ;;((-1) (make-simple-markup "-5"))
718 ((-1) (make-line-markup (list (accidental->markup -1) (make-simple-markup "5"))))
720 ;;choose your symbol for the augmented fifth
721 ;;((1) (make-simple-markup "aug"))
722 ((1) (make-line-markup (list (accidental->markup 1) (make-simple-markup "5"))))
723 ;;((1) (make-simple-markup "+5"))
724 ((2) (make-line-markup (list (accidental->markup 2) (make-simple-markup "5"))))))
725 (else (if (and (= (car pitch) 0)
728 (make-simple-markup "sus4")
729 (step->markup-accidental pitch)))))
731 ;; FIXME: identical to chord::additions->markup-american,
732 ;; except for -jazz / -american suffixes on calls
733 (define (chord::additions->markup-jazz additions subtractions)
734 (if (pair? additions)
735 ;; I don't like all this reasoning here, when we're actually typesetting.
736 (if(and(pair? (cdr additions)) ;a further addition left over
737 (or(and(= 0 (caddr(car additions))) ;this addition natural
738 (not(= 6 (cadr(car additions)))))
739 (and(= -1 (caddr(car additions)))
740 (= 6 (cadr(car additions)))))
741 (or(and(= 0 (caddr(cadr additions))) ;the following addition natural
742 (not(= 6 (cadr(cadr additions)))))
743 (and(= -1 (caddr(cadr additions)))
744 (= 6 (cadr(cadr additions)))))
745 (or(and(= (car(car additions)) (car(cadr additions))) ;both a third apart
746 (= 2 (- (cadr(cadr additions)) (cadr(car additions)))))
747 (and(= 1 (- (car(cadr additions)) (car(car additions))))
748 (= 5 (- (cadr(car additions)) (cadr(cadr additions))))))
749 (or(null? subtractions) ;this or clause protects the "adds"
750 (and (pair? subtractions)
751 (or (< (car(cadr additions)) (car(car subtractions)))
752 (and(= (car(cadr additions)) (car(car subtractions)))
753 (< (cadr(cadr additions)) (cadr(car subtractions))))))))
754 (chord::additions->markup-jazz (cdr additions) subtractions)
757 (let ((step (step->markup-jazz (car additions))))
758 (if (or (pair? (cdr additions))
759 (pair? subtractions))
760 (if (and (pair? (cdr additions))
761 (or(< 3 (- (cadr(cadr additions)) (cadr(car additions))))
762 (and(< 0 (- (car(cadr additions)) (car(car additions))))
763 (> 4 (- (cadr(car additions)) (cadr(cadr additions)))))))
764 (make-line-markup (list step (make-simple-markup " add")))
765 ;; tweak your favorite separator here
766 ;; (make-line-markup (list step (make-simple-markup "/")))
767 (make-line-markup (list step (make-simple-markup " "))))
769 (chord::additions->markup-jazz (cdr additions) subtractions))))
772 ;; FIXME: identical to chord::additions->markup-american.
773 ;; except for -jazz / -american suffixes on calls
774 (define (chord::inner-name-jazz tonic exception-part additions subtractions
775 bass-and-inversion steps)
776 (let* ((tonic-markup (pitch->chord-name-markup-banter tonic steps))
777 (except-markup (if exception-part exception-part empty-markup))
778 (sep-markup (if (and (string-match "super" (format "~s" except-markup))
779 (or (pair? additions)
780 (pair? subtractions)))
781 (make-super-markup (make-simple-markup "/"))
783 ;;this list contains all the additions that go "in line"
787 (let ((o (car x)) (n (cadr x)) (a (caddr x)))
788 (and (not (and (= 0 o) (= 2 n))) ;gets rid of unwanted thirds
789 ;;change this if you want it differently
790 (not (and (= 0 o) (= 3 n) (= 0 a))) ;sus4
791 (not (and (= 0 o) (= 4 n) (!= 0 a)))))) ;alt5
793 ;;this list contains all the additions that are patched onto the end
794 ;;of the chord symbol, usually sus4 and altered 5ths.
796 ;;take out the reverse if it bothers you in a pathological chord
800 (let ((o (car x)) (n (cadr x)) (a (caddr x)))
801 (and(not (and (= 0 o) (= 2 n))) ;gets rid of unwanted thirds
802 ;;change this correspondingly
803 (or(and (= 0 o) (= 3 n) (= 0 a)) ;sus4
804 (and (= 0 o) (= 4 n) (!= 0 a)))))) ;alt5
806 (relevant-subs (filter-list
807 (lambda (x) ;catches subtractions higher than 5th
808 (let((o (car x)) (n (cadr x)))
812 (pref-markup (chord::additions->markup-jazz prefixes relevant-subs))
813 (suff-markup (chord::additions->markup-jazz suffixes relevant-subs))
814 (b+i-markup (chord::bass-and-inversion->markup-banter bass-and-inversion)))
817 tonic-markup except-markup sep-markup
818 (make-normal-size-super-markup
819 (make-line-markup (list pref-markup suff-markup)))
822 (define (chord::name-jazz tonic exception-part unmatched-steps
823 bass-and-inversion steps)
824 (let ((additions (chord::additions-american unmatched-steps))
825 (subtractions (chord::subtractions unmatched-steps)))
826 (chord::inner-name-jazz tonic exception-part additions subtractions
827 bass-and-inversion steps)))
830 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
833 (define-public (new-chord->markup func ly-pitches bass inversion exceptions)
834 "Entry point for New_chord_name_engraver. See chord-name.scm for the
835 signature of FUNC. LY-PITCHES, BASS and INVERSION are lily
836 pitches. EXCEPTIONS is an alist (see scm file).
839 (let* ((pitches (map c++-pitch->scm ly-pitches))
841 (cons (c++-pitch->scm bass)
842 (c++-pitch->scm inversion)))
843 (diff (pitch::diff '(0 0 0) (car pitches)))
844 (steps (if (cdr pitches) (map (lambda (x)
845 (pitch::transpose x diff))
848 (lookup (dbg (chord::exceptions-lookup exceptions steps)))
849 (exception-part (dbg (car lookup)))
850 (unmatched-steps (cadr lookup))
851 (tonic (car pitches))
854 (func tonic exception-part unmatched-steps bass-and-inversion steps)
857 (define-public (chord->markup-jazz . args)
858 (apply new-chord->markup (cons chord::name-jazz args))
861 (define-public (chord->markup-american . args)
862 (apply new-chord->markup (cons chord::name-american args))
865 (define-public (chord->markup-banter . args)
866 (apply new-chord->markup (cons chord::name-banter args))
869 (define-public (new-chord-name-brew-molecule grob)
872 (ws (ly:get-grob-property grob 'word-space))
873 (markup (ly:get-grob-property grob 'text))
874 (molecule (interpret-markup grob
875 (cons '((word-space . 0.0))
876 (Font_interface::get_property_alist_chain grob))
881 ;; chord names aren't in staffs, so WS is in global staff space.
883 (ly:combine-molecule-at-edge
885 X RIGHT (ly:make-molecule "" (cons 0 ws) '(-1 . 1) )
890 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
892 (define-public (set-chord-name-style sym)
893 "Return music expressions that set the chord naming style. For
894 inline use in .ly file"
896 (define (chord-name-style-setter function exceptions)
898 (make-sequential-music
899 (list (make-property-set 'chordNameFunction function)
900 (make-property-set 'chordNameExceptions exceptions)))
908 (chord-name-style-setter chord->markup-jazz
909 chord::exception-alist-jazz))
911 (chord-name-style-setter chord->markup-banter
912 chord::exception-alist-banter))
914 (chord-name-style-setter chord->markup-american
915 chord::exception-alist-american))