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>
9 (define (natural-chord-alteration p)
10 "Return the natural alteration for step P."
11 (if (= (ly:pitch-steps p) 6)
16 (define-public (alteration->text-accidental-markup alteration)
22 (make-musicglyph-markup
23 (string-append "accidentals-" (number->string alteration))))))
25 (define (accidental->markup alteration)
26 "Return accidental markup for ALTERATION."
28 (make-line-markup (list empty-markup))
29 (conditional-kern-before
30 (alteration->text-accidental-markup alteration)
35 (define-public (note-name->markup pitch)
36 "Return pitch markup for PITCH."
40 (vector-ref #("C" "D" "E" "F" "G" "A" "B") (ly:pitch-notename pitch)))
41 (make-normal-size-super-markup
42 (accidental->markup (ly:pitch-alteration pitch))))))
45 (define-public ((chord-name->german-markup B-instead-of-Bb) pitch)
46 "Return pitch markup for PITCH, using german note names.
47 If B-instead-of-Bb is set to #t real german names are returned.
48 Otherwise semi-german names (with Bb and below keeping the british names)
50 (let* ((name (ly:pitch-notename pitch))
51 (alt (ly:pitch-alteration pitch))
52 (n-a (if (member (cons name alt) '((6 . -1) (6 . -2)))
53 (cons 7 (+ (if B-instead-of-Bb 1 0) alt))
58 (vector-ref #("C" "D" "E" "F" "G" "A" "H" "B") (car n-a)))
59 (make-normal-size-super-markup
60 (accidental->markup (cdr n-a)))))))
63 (define-public (note-name->german-markup pitch)
64 (let* ((name (ly:pitch-notename pitch))
65 (alt (ly:pitch-alteration pitch))
66 (n-a (if (member (cons name alt) '((6 . -1) (6 . -2)))
72 (list-ref '("c" "d" "e" "f" "g" "a" "h" "b") (car n-a))
73 (if (or (equal? (car n-a) 2) (equal? (car n-a) 5))
74 (list-ref '( "ses" "s" "" "is" "isis") (+ 2 (cdr n-a)))
75 (list-ref '("eses" "es" "" "is" "isis") (+ 2 (cdr n-a)))))))))
77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
80 (define-public (sequential-music-to-chord-exceptions seq omit-root)
81 "Transform sequential music SEQ of type <<c d e>>-\markup{ foobar }
82 to (cons CDE-PITCHES FOOBAR-MARKUP), or to (cons DE-PITCHES
83 FOOBAR-MARKUP) if OMIT-ROOT.
85 (define (chord-to-exception-entry m)
86 (let* ((elts (ly:get-mus-property m 'elements))
87 (pitches (map (lambda (x) (ly:get-mus-property x 'pitch))
89 (lambda (y) (memq 'note-event
90 (ly:get-mus-property y 'types)))
92 (sorted (sort pitches ly:pitch<?))
94 (normalized (map (lambda (x) (ly:pitch-diff x root)) sorted))
95 (texts (map (lambda (x) (ly:get-mus-property x 'text))
97 (lambda (y) (memq 'text-script-event
98 (ly:get-mus-property y 'types)))
100 (text (if (null? texts) #f (car texts))))
101 (cons (if omit-root (cdr normalized) normalized) text)))
103 (define (is-req-chord? m)
105 (memq 'event-chord (ly:get-mus-property m 'types))
106 (not (equal? (ly:make-moment 0 1) (ly:get-music-length m)))))
108 (let* ((elts (filter-list is-req-chord? (ly:get-mus-property seq 'elements)))
109 (alist (map chord-to-exception-entry elts)))
110 (filter-list (lambda (x) (cdr x)) alist)))
113 (define-public (new-chord-name-brew-molecule grob)
116 (ws (ly:get-grob-property grob 'word-space))
117 (markup (ly:get-grob-property grob 'text))
118 (molecule (interpret-markup grob
119 (cons '((word-space . 0.0))
120 (Font_interface::get_property_alist_chain grob))
125 ;; chord names aren't in staffs, so WS is in global staff space.
127 (ly:molecule-combine-at-edge
129 X RIGHT (ly:make-molecule "" (cons 0 ws) '(-1 . 1) )
134 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
136 (define-public (set-chord-name-style sym)
137 "Return music expressions that set the chord naming style. For
138 inline use in .ly file"
140 (define (chord-name-style-setter function exceptions)
142 (make-sequential-music
143 (list (make-property-set 'chordNameFunction function)
144 (make-property-set 'chordNameExceptions exceptions)))
152 (chord-name-style-setter ignatzek-chord-names
155 (chord-name-style-setter double-plus-new-chord->markup-banter
156 chord::exception-alist-banter))
159 (chord-name-style-setter double-plus-new-chord->markup-jazz
160 chord::exception-alist-jazz))
163 ;; can't put this in double-plus-new-chord-name.scm, because we can't
164 ;; ly:load that very easily.
165 (define-public (set-double-plus-new-chord-name-style style options)
166 "Return music expressions that set the chord naming style. For
167 inline use in .ly file"
169 (define (chord-name-style-setter function)
171 (make-sequential-music
172 (list (make-property-set 'chordNameFunction function)
174 ;; urg , misuse of chordNameExceptions function.
175 (make-property-set 'chordNameExceptions options)))
181 (chord-name-style-setter double-plus-new-chord->markup-banter))
184 (chord-name-style-setter double-plus-new-chord->markup-jazz)))))