]> git.donarmstrong.com Git - lilypond.git/blob - scm/chord-name.scm
(set-chord-name-style): remove
[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 (define-public (alteration->text-accidental-markup alteration)
18   (make-smaller-markup
19    (make-raise-markup
20     (if (= alteration -1)
21         0.3
22         0.6)
23     (make-musicglyph-markup
24      (string-append "accidentals-" (number->string alteration))))))
25   
26 (define (accidental->markup alteration)
27   "Return accidental markup for ALTERATION."
28   (if (= alteration 0)
29       (make-line-markup (list empty-markup))
30       (conditional-kern-before
31        (alteration->text-accidental-markup alteration)
32        (= alteration -1) 0.2
33        )))
34
35
36 (define-public (note-name->markup pitch)
37   "Return pitch markup for PITCH."
38   (make-line-markup
39    (list
40     (make-simple-markup
41      (vector-ref #("C" "D" "E" "F" "G" "A" "B") (ly:pitch-notename pitch)))
42     (make-normal-size-super-markup
43      (accidental->markup (ly:pitch-alteration pitch))))))
44
45
46 (define-public ((chord-name->german-markup B-instead-of-Bb) pitch)
47   "Return pitch markup for PITCH, using german note names.
48    If B-instead-of-Bb is set to #t real german names are returned.
49    Otherwise semi-german names (with Bb and below keeping the british names)
50 "
51   (let* ((name (ly:pitch-notename pitch))
52          (alt (ly:pitch-alteration pitch))
53          (n-a (if (member (cons name alt) '((6 . -1) (6 . -2)))
54                  (cons 7 (+ (if B-instead-of-Bb 1 0) alt))
55                  (cons name alt))))
56     (make-line-markup
57      (list
58       (make-simple-markup
59        (vector-ref #("C" "D" "E" "F" "G" "A" "H" "B") (car n-a)))
60       (make-normal-size-super-markup
61        (accidental->markup (cdr n-a)))))))
62
63
64 (define-public (note-name->german-markup  pitch)
65   (let* ((name (ly:pitch-notename pitch))
66          (alt (ly:pitch-alteration pitch))
67          (n-a (if (member (cons name alt) '((6 . -1) (6 . -2)))
68                   (cons 7 (+ 1 alt))
69                   (cons name alt))))
70     (make-line-markup
71      (list
72       (string-append
73        (list-ref '("c" "d" "e" "f" "g" "a" "h" "b") (car n-a))
74        (if (or (equal? (car n-a) 2) (equal? (car n-a) 5))
75            (list-ref '( "ses"  "s" "" "is" "isis") (+ 2 (cdr n-a)))
76            (list-ref '("eses" "es" "" "is" "isis") (+ 2 (cdr n-a)))))))))
77
78 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
79 ;;
80
81 ;; fixme we should standardize on omit-root (or the other one.)
82 ;; perhaps the  default should also be reversed --hwn
83 (define-public (sequential-music-to-chord-exceptions seq . rest)
84   "Transform sequential music SEQ of type <<c d e>>-\markup{ foobar }
85 to (cons CDE-PITCHES FOOBAR-MARKUP), or to (cons DE-PITCHES
86 FOOBAR-MARKUP) if OMIT-ROOT is given and non-false.
87 "
88
89   (define (chord-to-exception-entry m)
90     (let* ((elts (ly:get-mus-property m 'elements))
91            (omit-root (and (pair? rest) (car rest)))
92            (pitches (map (lambda (x) (ly:get-mus-property x 'pitch))
93                          (filter-list
94                           (lambda (y) (memq 'note-event
95                                             (ly:get-mus-property y 'types)))
96                           elts)))
97            (sorted (sort pitches ly:pitch<?))
98            (root (car sorted))
99            
100            ;; ugh?
101            ;;(diff (ly:pitch-diff root (ly:make-pitch -1 0 0)))
102            ;; FIXME.  This results in #<Pitch c> ...,
103            ;; but that is what we need because default octave for
104            ;; \chords has changed to c' too?
105            (diff (ly:pitch-diff root (ly:make-pitch 0 0 0)))
106            (normalized (map (lambda (x) (ly:pitch-diff x diff)) sorted))
107            (texts (map (lambda (x) (ly:get-mus-property x 'text))
108                        (filter-list
109                         (lambda (y) (memq 'text-script-event
110                                           (ly:get-mus-property y 'types)))
111                         elts)))
112
113            (text (if (null? texts) #f (if omit-root (car texts) texts))))
114       (cons (if omit-root (cdr normalized) normalized) text)))
115
116   (define (is-req-chord? m)
117     (and
118      (memq 'event-chord (ly:get-mus-property m 'types))
119      (not (equal? (ly:make-moment 0 1) (ly:get-music-length m)))))
120
121   (let* ((elts (filter-list is-req-chord? (ly:get-mus-property seq 'elements)))
122          (alist (map chord-to-exception-entry elts)))
123     (filter-list (lambda (x) (cdr x)) alist)))
124
125
126 (define-public (new-chord-name-brew-molecule grob)
127   (let*
128       (
129        (ws (ly:get-grob-property grob 'word-space))
130        (markup (ly:get-grob-property grob 'text))
131        (molecule (interpret-markup grob
132                                    (cons '((word-space . 0.0))
133                                          (Font_interface::get_property_alist_chain grob))
134                                    markup))
135        )
136
137     ;;
138     ;; chord names aren't in staffs, so WS is in global staff space.
139     (if (number? ws)
140         (ly:molecule-combine-at-edge
141          molecule
142          X RIGHT (ly:make-molecule "" (cons 0 ws) '(-1 . 1) )
143          0.0)
144         molecule)
145     ))
146