2 ;;; chord-name.scm -- chord name utility functions
4 ;;; source file of the GNU LilyPond music typesetter
6 ;;; (c) 2000--2003 Jan Nieuwenhuizen <janneke@gnu.org>
8 ;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 (define (natural-chord-alteration p)
11 "Return the natural alteration for step P."
12 (if (= (ly:pitch-steps p) 6)
18 ;; TODO: make into markup.
20 (define-public (alteration->text-accidental-markup alteration)
26 (make-musicglyph-markup
27 (string-append "accidentals-" (number->string alteration))))))
29 (define (accidental->markup alteration)
30 "Return accidental markup for ALTERATION."
32 (make-line-markup (list empty-markup))
33 (conditional-kern-before
34 (alteration->text-accidental-markup alteration)
39 (define-public (note-name->markup pitch)
40 "Return pitch markup for PITCH."
44 (vector-ref #("C" "D" "E" "F" "G" "A" "B") (ly:pitch-notename pitch)))
45 (accidental->markup (ly:pitch-alteration pitch)))))
48 (define-public ((chord-name->german-markup B-instead-of-Bb) pitch)
49 "Return pitch markup for PITCH, using german note names.
50 If B-instead-of-Bb is set to #t real german names are returned.
51 Otherwise semi-german names (with Bb and below keeping the british names)
53 (let* ((name (ly:pitch-notename pitch))
54 (alt (ly:pitch-alteration pitch))
55 (n-a (if (member (cons name alt) '((6 . -1) (6 . -2)))
56 (cons 7 (+ (if B-instead-of-Bb 1 0) alt))
61 (vector-ref #("C" "D" "E" "F" "G" "A" "H" "B") (car n-a)))
62 (make-normal-size-super-markup
63 (accidental->markup (cdr n-a)))))))
66 (define-public (note-name->german-markup pitch)
67 (let* ((name (ly:pitch-notename pitch))
68 (alt (ly:pitch-alteration pitch))
69 (n-a (if (member (cons name alt) '((6 . -1) (6 . -2)))
75 (list-ref '("c" "d" "e" "f" "g" "a" "h" "b") (car n-a))
76 (if (or (equal? (car n-a) 2) (equal? (car n-a) 5))
77 (list-ref '( "ses" "s" "" "is" "isis") (+ 2 (cdr n-a)))
78 (list-ref '("eses" "es" "" "is" "isis") (+ 2 (cdr n-a)))))))))
80 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
83 ;; fixme we should standardize on omit-root (or the other one.)
84 ;; perhaps the default should also be reversed --hwn
85 (define-public (sequential-music-to-chord-exceptions seq . rest)
86 "Transform sequential music SEQ of type <<c d e>>-\markup{ foobar }
87 to (cons CDE-PITCHES FOOBAR-MARKUP), or to (cons DE-PITCHES
88 FOOBAR-MARKUP) if OMIT-ROOT is given and non-false.
91 (define (chord-to-exception-entry m)
92 (let* ((elts (ly:get-mus-property m 'elements))
93 (omit-root (and (pair? rest) (car rest)))
94 (pitches (map (lambda (x) (ly:get-mus-property x 'pitch))
96 (lambda (y) (memq 'note-event
97 (ly:get-mus-property y 'types)))
99 (sorted (sort pitches ly:pitch<?))
103 ;;(diff (ly:pitch-diff root (ly:make-pitch -1 0 0)))
104 ;; FIXME. This results in #<Pitch c> ...,
105 ;; but that is what we need because default octave for
106 ;; \chords has changed to c' too?
107 (diff (ly:pitch-diff root (ly:make-pitch 0 0 0)))
108 (normalized (map (lambda (x) (ly:pitch-diff x diff)) sorted))
109 (texts (map (lambda (x) (ly:get-mus-property x 'text))
111 (lambda (y) (memq 'text-script-event
112 (ly:get-mus-property y 'types)))
115 (text (if (null? texts) #f (if omit-root (car texts) texts))))
116 (cons (if omit-root (cdr normalized) normalized) text)))
118 (define (is-req-chord? m)
120 (memq 'event-chord (ly:get-mus-property m 'types))
121 (not (equal? (ly:make-moment 0 1) (ly:get-music-length m)))))
123 (let* ((elts (filter is-req-chord? (ly:get-mus-property seq 'elements)))
124 (alist (map chord-to-exception-entry elts)))
125 (filter (lambda (x) (cdr x)) alist)))