]> git.donarmstrong.com Git - lilypond.git/blob - scm/chord-name.scm
2dc7926fbc5c98dd1e6c41e87703b0e64b01532a
[lilypond.git] / scm / chord-name.scm
1 ;;;
2 ;;; chord-name.scm --  chord name utility functions
3 ;;;
4 ;;; source file of the GNU LilyPond music typesetter
5 ;;; 
6 ;;; (c)  2000--2003 Jan Nieuwenhuizen <janneke@gnu.org>
7 ;;;
8 ;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
9
10 (define (natural-chord-alteration p)
11   "Return the natural alteration for step P."
12   (if (= (ly:pitch-steps p) 6)
13       -1
14       0))
15
16
17 ;; 
18 ;; TODO: make into markup.
19 ;; 
20 (define-public (alteration->text-accidental-markup alteration)
21   (make-smaller-markup
22    (make-raise-markup
23     (if (= alteration -1)
24         0.3
25         0.6)
26     (make-musicglyph-markup
27      (string-append "accidentals-" (number->string alteration))))))
28   
29 (define (accidental->markup alteration)
30   "Return accidental markup for ALTERATION."
31   (if (= alteration 0)
32       (make-line-markup (list empty-markup))
33       (conditional-kern-before
34        (alteration->text-accidental-markup alteration)
35        (= alteration -1) 0.2
36        )))
37
38
39 (define-public (note-name->markup pitch)
40   "Return pitch markup for PITCH."
41   (make-line-markup
42    (list
43     (make-simple-markup
44      (vector-ref #("C" "D" "E" "F" "G" "A" "B") (ly:pitch-notename pitch)))
45      (accidental->markup (ly:pitch-alteration pitch)))))
46
47
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)
52 "
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))
57                  (cons name alt))))
58     (make-line-markup
59      (list
60       (make-simple-markup
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)))))))
64
65
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)))
70                   (cons 7 (+ 1 alt))
71                   (cons name alt))))
72     (make-line-markup
73      (list
74       (string-append
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)))))))))
79
80 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
81 ;;
82
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.
89 "
90
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))
95                          (filter
96                           (lambda (y) (memq 'note-event
97                                             (ly:get-mus-property y 'types)))
98                           elts)))
99            (sorted (sort pitches ly:pitch<?))
100            (root (car sorted))
101            
102            ;; ugh?
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))
110                        (filter
111                         (lambda (y) (memq 'text-script-event
112                                           (ly:get-mus-property y 'types)))
113                         elts)))
114
115            (text (if (null? texts) #f (if omit-root (car texts) texts))))
116       (cons (if omit-root (cdr normalized) normalized) text)))
117
118   (define (is-req-chord? m)
119     (and
120      (memq 'event-chord (ly:get-mus-property m 'types))
121      (not (equal? (ly:make-moment 0 1) (ly:get-music-length m)))))
122
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)))
126