2 ;;; chord-name.scm -- chord name utility functions
4 ;;; source file of the GNU LilyPond music typesetter
6 ;;; (c) 2000--2004 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)
23 (if (= alteration FLAT)
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)
35 (= alteration FLAT) 0.2
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 . ,FLAT) (6 . ,DOUBLE-FLAT)))
56 (cons 7 (+ (if B-instead-of-Bb SEMI-TONE 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 . ,FLAT) (6 . ,DOUBLE-FLAT)))
70 (cons 7 (+ SEMI-TONE alt))
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) 2) ))
78 (list-ref '("eses" "es" "" "is" "isis") (+ 2 (/ (cdr n-a) 2) ))
81 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
84 ;; fixme we should standardize on omit-root (or the other one.)
85 ;; perhaps the default should also be reversed --hwn
86 (define-public (sequential-music-to-chord-exceptions seq . rest)
87 "Transform sequential music SEQ of type <<c d e>>-\\markup{ foobar }
88 to (cons CDE-PITCHES FOOBAR-MARKUP), or to (cons DE-PITCHES
89 FOOBAR-MARKUP) if OMIT-ROOT is given and non-false.
92 (define (chord-to-exception-entry m)
93 (let* ((elts (ly:music-property m 'elements))
94 (omit-root (and (pair? rest) (car rest)))
95 (pitches (map (lambda (x) (ly:music-property x 'pitch))
97 (lambda (y) (memq 'note-event
98 (ly:music-property y 'types)))
100 (sorted (sort pitches ly:pitch<?))
104 ;;(diff (ly:pitch-diff root (ly:make-pitch -1 0 0)))
105 ;; FIXME. This results in #<Pitch c> ...,
106 ;; but that is what we need because default octave for
107 ;; \chords has changed to c' too?
108 (diff (ly:pitch-diff root (ly:make-pitch 0 0 0)))
109 (normalized (map (lambda (x) (ly:pitch-diff x diff)) sorted))
110 (texts (map (lambda (x) (ly:music-property x 'text))
112 (lambda (y) (memq 'text-script-event
113 (ly:music-property y 'types)))
116 (text (if (null? texts) #f (if omit-root (car texts) texts))))
117 (cons (if omit-root (cdr normalized) normalized) text)))
119 (define (is-req-chord? m)
121 (memq 'event-chord (ly:music-property m 'types))
122 (not (equal? ZERO-MOMENT (ly:music-length m)))))
124 (let* ((elts (filter is-req-chord? (ly:music-property seq 'elements)))
125 (alist (map chord-to-exception-entry elts)))
126 (filter (lambda (x) (cdr x)) alist)))