]> git.donarmstrong.com Git - lilypond.git/blob - scm/chord-name.scm
* lily/paper-outputter.cc (output_scope): Check if number before
[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       FLAT
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 FLAT)
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 FLAT) 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 . ,FLAT) (6 . ,DOUBLE-FLAT)))
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 . ,FLAT) (6 . ,DOUBLE-FLAT)))
70                   (cons 7 (+ SEMI-TONE 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) 2) ))
78            (list-ref '("eses" "es" "" "is" "isis") (+ 2 (/ (cdr n-a) 2) ))
79            ))))))
80
81 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
82 ;;
83
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.
90 "
91
92   (define (chord-to-exception-entry m)
93     (let* ((elts (ly:get-mus-property m 'elements))
94            (omit-root (and (pair? rest) (car rest)))
95            (pitches (map (lambda (x) (ly:get-mus-property x 'pitch))
96                          (filter
97                           (lambda (y) (memq 'note-event
98                                             (ly:get-mus-property y 'types)))
99                           elts)))
100            (sorted (sort pitches ly:pitch<?))
101            (root (car sorted))
102            
103            ;; ugh?
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:get-mus-property x 'text))
111                        (filter
112                         (lambda (y) (memq 'text-script-event
113                                           (ly:get-mus-property y 'types)))
114                         elts)))
115
116            (text (if (null? texts) #f (if omit-root (car texts) texts))))
117       (cons (if omit-root (cdr normalized) normalized) text)))
118
119   (define (is-req-chord? m)
120     (and
121      (memq 'event-chord (ly:get-mus-property m 'types))
122      (not (equal? ZERO-MOMENT (ly:music-length m)))))
123
124   (let* ((elts (filter is-req-chord? (ly:get-mus-property seq 'elements)))
125          (alist (map chord-to-exception-entry elts)))
126     (filter (lambda (x) (cdr x)) alist)))
127