1 ;;;; chord-name.scm -- chord name utility functions
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2004 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 (define (natural-chord-alteration p)
9 "Return the natural alteration for step P."
10 (if (= (ly:pitch-steps p) 6)
15 ;; TODO: make into markup.
17 (define-public (alteration->text-accidental-markup alteration)
20 (if (= alteration FLAT)
23 (make-musicglyph-markup
24 (string-append "accidentals-" (number->string alteration))))))
26 (define (accidental->markup alteration)
27 "Return accidental markup for ALTERATION."
29 (make-line-markup (list empty-markup))
30 (conditional-kern-before
31 (alteration->text-accidental-markup alteration)
32 (= alteration FLAT) 0.2)))
34 (define-public (note-name->markup pitch)
35 "Return pitch markup for PITCH."
39 (vector-ref #("C" "D" "E" "F" "G" "A" "B") (ly:pitch-notename pitch)))
40 (accidental->markup (ly:pitch-alteration pitch)))))
42 (define-public ((chord-name->german-markup B-instead-of-Bb) pitch)
43 "Return pitch markup for PITCH, using german note names.
44 If B-instead-of-Bb is set to #t real german names are returned.
45 Otherwise semi-german names (with Bb and below keeping the british names)
47 (let* ((name (ly:pitch-notename pitch))
48 (alt (ly:pitch-alteration pitch))
49 (n-a (if (member (cons name alt) `((6 . ,FLAT) (6 . ,DOUBLE-FLAT)))
50 (cons 7 (+ (if B-instead-of-Bb SEMI-TONE 0) alt))
55 (vector-ref #("C" "D" "E" "F" "G" "A" "H" "B") (car n-a)))
56 (make-normal-size-super-markup
57 (accidental->markup (cdr n-a)))))))
59 (define-public (note-name->german-markup pitch)
60 (let* ((name (ly:pitch-notename pitch))
61 (alt (ly:pitch-alteration pitch))
62 (n-a (if (member (cons name alt) `((6 . ,FLAT) (6 . ,DOUBLE-FLAT)))
63 (cons 7 (+ SEMI-TONE alt))
68 (list-ref '("c" "d" "e" "f" "g" "a" "h" "b") (car n-a))
69 (if (or (equal? (car n-a) 2) (equal? (car n-a) 5))
70 (list-ref '( "ses" "s" "" "is" "isis") (+ 2 (/ (cdr n-a) 2)))
71 (list-ref '("eses" "es" "" "is" "isis") (+ 2 (/ (cdr n-a) 2)))))))))
73 ;; fixme we should standardize on omit-root (or the other one.)
74 ;; perhaps the default should also be reversed --hwn
75 (define-public (sequential-music-to-chord-exceptions seq . rest)
76 "Transform sequential music SEQ of type <<c d e>>-\\markup{ foobar }
77 to (cons CDE-PITCHES FOOBAR-MARKUP), or to (cons DE-PITCHES
78 FOOBAR-MARKUP) if OMIT-ROOT is given and non-false.
81 (define (chord-to-exception-entry m)
82 (let* ((elts (ly:music-property m 'elements))
83 (omit-root (and (pair? rest) (car rest)))
84 (pitches (map (lambda (x) (ly:music-property x 'pitch))
86 (lambda (y) (memq 'note-event
87 (ly:music-property y 'types)))
89 (sorted (sort pitches ly:pitch<?))
93 ;;(diff (ly:pitch-diff root (ly:make-pitch -1 0 0)))
94 ;; FIXME. This results in #<Pitch c> ...,
95 ;; but that is what we need because default octave for
96 ;; \chords has changed to c' too?
97 (diff (ly:pitch-diff root (ly:make-pitch 0 0 0)))
98 (normalized (map (lambda (x) (ly:pitch-diff x diff)) sorted))
99 (texts (map (lambda (x) (ly:music-property x 'text))
101 (lambda (y) (memq 'text-script-event
102 (ly:music-property y 'types)))
105 (text (if (null? texts) #f (if omit-root (car texts) texts))))
106 (cons (if omit-root (cdr normalized) normalized) text)))
108 (define (is-req-chord? m)
110 (memq 'event-chord (ly:music-property m 'types))
111 (not (equal? ZERO-MOMENT (ly:music-length m)))))
113 (let* ((elts (filter is-req-chord? (ly:music-property seq 'elements)))
114 (alist (map chord-to-exception-entry elts)))
115 (filter (lambda (x) (cdr x)) alist)))