1 ;;;; chord-generic-names.scm -- Compile chord names
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2003-2004 Jan Nieuwenhuizen <janneke@gnu.org>
8 ;;;; NOTE: this is experimental code
9 ;;;; Base and inversion are ignored.
10 ;;;; Naming of the base chord (steps 1-5) is handled by exceptions only
11 ;;;; see input/test/chord-names-dpnj.ly
13 (define (markup-or-empty-markup markup)
14 "Return MARKUP if markup, else empty-markup"
15 (if (markup? markup) markup empty-markup))
17 (define (conditional-kern-before markup bool amount)
18 "Add AMOUNT of space before MARKUP if BOOL is true."
21 (list (make-hspace-markup amount)
25 (define-public (banter-chord-names pitches bass inversion context)
26 (ugh-compat-double-plus-new-chord->markup
27 'banter pitches bass inversion context '())
31 (define-public (jazz-chord-names pitches bass inversion context)
32 (ugh-compat-double-plus-new-chord->markup
33 'jazz pitches bass inversion context '())
37 (define-public (ugh-compat-double-plus-new-chord->markup
38 style pitches bass inversion context options)
39 "Entry point for New_chord_name_engraver.
41 FIXME: func, options/context have changed
43 double-plus-new-chord-name.scm for the signature of STYLE. PITCHES,
44 BASS and INVERSION are lily pitches. OPTIONS is an alist-alist (see
45 input/test/dpncnt.ly).
49 (define (step-nr pitch)
50 (let* ((pitch-nr (+ (* 7 (ly:pitch-octave pitch))
51 (ly:pitch-notename pitch)))
52 (root-nr (+ (* 7 (ly:pitch-octave (car pitches)))
53 (ly:pitch-notename (car pitches)))))
54 (+ 1 (- pitch-nr root-nr))))
56 (define (next-third pitch)
57 (ly:pitch-transpose pitch
58 (ly:make-pitch 0 2 (if (or (= (step-nr pitch) 3)
59 (= (step-nr pitch) 5))
62 (define (step-alteration pitch)
63 (let* ((diff (ly:pitch-diff (ly:make-pitch 0 0 0) (car pitches)))
64 (normalized-pitch (ly:pitch-transpose pitch diff))
65 (alteration (ly:pitch-alteration normalized-pitch)))
66 (if (= (step-nr pitch) 7) (+ alteration SEMI-TONE) alteration)))
68 (define (pitch-unalter pitch)
69 (let ((alteration (step-alteration pitch)))
72 (ly:make-pitch (ly:pitch-octave pitch) (ly:pitch-notename pitch)
73 (- (ly:pitch-alteration pitch) alteration)))))
75 (define (step-even-or-altered? pitch)
76 (let ((nr (step-nr pitch)))
77 (if (!= (modulo nr 2) 0)
78 (!= (step-alteration pitch) 0)
81 (define (step->markup-plusminus pitch)
84 (make-simple-markup (number->string (step-nr pitch)))
86 (case (step-alteration pitch)
91 ((DOUBLE-SHARP) "++"))))))
93 (define (step->markup-accidental pitch)
95 (list (accidental->markup (step-alteration pitch))
96 (make-simple-markup (number->string (step-nr pitch))))))
98 (define (step->markup-ignatzek pitch)
100 (if (and (= (step-nr pitch) 7)
101 (= (step-alteration pitch) 1))
102 (list (ly:context-property context 'majorSevenSymbol))
103 (list (accidental->markup (step-alteration pitch))
104 (make-simple-markup (number->string (step-nr pitch)))))))
107 (define (make-sub->markup step->markup)
109 (make-line-markup (list (make-simple-markup "no")
110 (step->markup pitch)))))
112 (define (step-based-sub->markup step->markup pitch)
113 (make-line-markup (list (make-simple-markup "no") (step->markup pitch))))
115 (define (get-full-list pitch)
116 (if (<= (step-nr pitch) (step-nr (last pitches)))
117 (cons pitch (get-full-list (next-third pitch)))
120 (define (get-consecutive nr pitches)
122 (let* ((pitch-nr (step-nr (car pitches)))
123 (next-nr (if (!= (modulo pitch-nr 2) 0) (+ pitch-nr 2) nr)))
125 (cons (car pitches) (get-consecutive next-nr (cdr pitches)))
129 (define (full-match exceptions)
130 (if (pair? exceptions)
131 (let* ((e (car exceptions))
133 (if (equal? e-pitches pitches)
135 (full-match (cdr exceptions))))
138 (define (partial-match exceptions)
139 (if (pair? exceptions)
140 (let* ((e (car exceptions))
142 (if (equal? e-pitches (take pitches (length e-pitches) ))
144 (partial-match (cdr exceptions))))
148 (write-me "pitches: " pitches)))
149 (let* ((full-exceptions
150 (ly:context-property context 'chordNameExceptionsFull))
151 (full-exception (full-match full-exceptions))
152 (full-markup (if full-exception (cadr full-exception) '()))
154 (ly:context-property context 'chordNameExceptionsPartial))
155 (partial-exception (partial-match partial-exceptions))
156 (partial-pitches (if partial-exception (car partial-exception) '()))
157 (partial-markup-prefix
158 (if partial-exception (markup-or-empty-markup
159 (cadr partial-exception)) empty-markup))
160 (partial-markup-suffix
161 (if (and partial-exception (pair? (cddr partial-exception)))
162 (markup-or-empty-markup (caddr partial-exception)) empty-markup))
164 (full (get-full-list root))
165 ;; kludge alert: replace partial matched lower part of all with
166 ;; 'normal' pitches from full
168 (all (append (take full (length partial-pitches) )
169 (drop pitches (length partial-pitches) )))
172 (missing (list-minus full (map pitch-unalter all)))
173 (consecutive (get-consecutive 1 all))
174 (rest (list-minus all consecutive))
175 (altered (filter step-even-or-altered? all))
176 (cons-alt (filter step-even-or-altered? consecutive))
177 (base (list-minus consecutive altered)))
181 (write-me "full:" full)
182 ;; (write-me "partial-pitches:" partial-pitches)
183 (write-me "full-markup:" full-markup)
184 (write-me "partial-markup-perfix:" partial-markup-prefix)
185 (write-me "partial-markup-suffix:" partial-markup-suffix)
186 (write-me "all:" all)
187 (write-me "altered:" altered)
188 (write-me "missing:" missing)
189 (write-me "consecutive:" consecutive)
190 (write-me "rest:" rest)
191 (write-me "base:" base)))
196 ;; + steps:altered + (highest all -- if not altered)
199 (let* ((root->markup (assoc-get
200 'root->markup options note-name->markup))
201 (step->markup (assoc-get
202 'step->markup options step->markup-plusminus))
203 (sub->markup (assoc-get
206 (step-based-sub->markup step->markup x))))
208 'separator options (make-simple-markup "/"))))
212 (make-line-markup (list (root->markup root) full-markup))
217 partial-markup-prefix
218 (make-normal-size-super-markup
223 (if (and (> (step-nr highest) 5)
225 (step-even-or-altered? highest)))
226 (list highest) '())))
227 (list partial-markup-suffix)
228 (list (map sub->markup missing)))
234 ;; + steps:(highest base) + cons-alt
237 (let* ((root->markup (assoc-get
238 'root->markup options note-name->markup))
242 ;;'step->markup options step->markup-accidental))
243 'step->markup options step->markup-ignatzek))
245 'separator options (make-simple-markup " ")))
246 (add-prefix (assoc-get 'add-prefix options
247 (make-simple-markup " add"))))
251 (make-line-markup (list (root->markup root) full-markup))
256 partial-markup-prefix
257 (make-normal-size-super-markup
261 ;; kludge alert: omit <= 5
262 ;;(markup-join (map step->markup
263 ;; (cons (last base) cons-alt)) sep)
269 ;; c:6.9 C5 6add9 -> C6 add 9 (add?)
270 ;; ch = \chords { c c:2 c:3- c:6.9^7 }
271 (markup-join (map step->markup
272 (let ((tb (last base)))
273 (if (> (step-nr tb) 5)
280 (markup-join (map step->markup rest) sep)
281 partial-markup-suffix))))))))
283 (else empty-markup))))