X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Fchord-name.scm;h=718a3c9e3b35cc3cd99bbc1f9de4bf5116ab474f;hb=8574d4349026c4ac5a15a27c50e264bf548e29fb;hp=7ed0f184d45a2def72881b8407353c1bc0ea6d4c;hpb=9f8e04c4008b5f50ee2f771568d18df50764e0f5;p=lilypond.git diff --git a/scm/chord-name.scm b/scm/chord-name.scm index 7ed0f184d4..718a3c9e3b 100644 --- a/scm/chord-name.scm +++ b/scm/chord-name.scm @@ -1,27 +1,28 @@ -;;; -;;; chord-name.scm -- chord name utility functions -;;; -;;; source file of the GNU LilyPond music typesetter -;;; -;;; (c) 2000--2003 Jan Nieuwenhuizen -;;; -;;; Han-Wen Nienhuys +;;;; chord-name.scm -- chord name utility functions +;;;; +;;;; source file of the GNU LilyPond music typesetter +;;;; +;;;; (c) 2000--2009 Jan Nieuwenhuizen +;;;; Han-Wen Nienhuys (define (natural-chord-alteration p) "Return the natural alteration for step P." (if (= (ly:pitch-steps p) 6) - -1 + FLAT 0)) - +;; +;; TODO: make into markup. +;; (define-public (alteration->text-accidental-markup alteration) + (make-smaller-markup (make-raise-markup - (if (= alteration -1) + (if (= alteration FLAT) 0.3 0.6) (make-musicglyph-markup - (string-append "accidentals-" (number->string alteration)))))) + (assoc-get alteration standard-alteration-glyph-name-alist ""))))) (define (accidental->markup alteration) "Return accidental markup for ALTERATION." @@ -29,9 +30,18 @@ (make-line-markup (list empty-markup)) (conditional-kern-before (alteration->text-accidental-markup alteration) - (= alteration -1) 0.2 - ))) + (= alteration FLAT) 0.2))) +(define (accidental->markup-italian alteration) + "Return accidental markup for ALTERATION, for use after an italian chord root name." + (if (= alteration 0) + (make-hspace-markup 0.2) + (make-line-markup + (list + (make-hspace-markup (if (= alteration FLAT) 0.7 0.5)) + (make-raise-markup 0.7 (alteration->text-accidental-markup alteration)) + (make-hspace-markup (if (= alteration SHARP) 0.2 0.1)) + )))) (define-public (note-name->markup pitch) "Return pitch markup for PITCH." @@ -41,57 +51,72 @@ (vector-ref #("C" "D" "E" "F" "G" "A" "B") (ly:pitch-notename pitch))) (accidental->markup (ly:pitch-alteration pitch))))) +(define (pitch-alteration-semitones pitch) + (inexact->exact (round (* (ly:pitch-alteration pitch) 2)))) -(define-public ((chord-name->german-markup B-instead-of-Bb) pitch) +(define-safe-public ((chord-name->german-markup B-instead-of-Bb) pitch) "Return pitch markup for PITCH, using german note names. If B-instead-of-Bb is set to #t real german names are returned. Otherwise semi-german names (with Bb and below keeping the british names) " (let* ((name (ly:pitch-notename pitch)) - (alt (ly:pitch-alteration pitch)) - (n-a (if (member (cons name alt) '((6 . -1) (6 . -2))) - (cons 7 (+ (if B-instead-of-Bb 1 0) alt)) - (cons name alt)))) + (alt-semitones (pitch-alteration-semitones pitch)) + (n-a (if (member (cons name alt-semitones) `((6 . -1) (6 . -2))) + (cons 7 (+ (if B-instead-of-Bb 1 0) alt-semitones)) + (cons name alt-semitones)))) (make-line-markup (list (make-simple-markup (vector-ref #("C" "D" "E" "F" "G" "A" "H" "B") (car n-a))) (make-normal-size-super-markup - (accidental->markup (cdr n-a))))))) + (accidental->markup (/ (cdr n-a) 2))))))) - -(define-public (note-name->german-markup pitch) +(define-safe-public (note-name->german-markup pitch) (let* ((name (ly:pitch-notename pitch)) - (alt (ly:pitch-alteration pitch)) - (n-a (if (member (cons name alt) '((6 . -1) (6 . -2))) - (cons 7 (+ 1 alt)) - (cons name alt)))) + (alt-semitones (pitch-alteration-semitones pitch)) + (n-a (if (member (cons name alt-semitones) `((6 . -1) (6 . -2))) + (cons 7 (+ 1 alt-semitones)) + (cons name alt-semitones)))) (make-line-markup (list (string-append (list-ref '("c" "d" "e" "f" "g" "a" "h" "b") (car n-a)) (if (or (equal? (car n-a) 2) (equal? (car n-a) 5)) - (list-ref '( "ses" "s" "" "is" "isis") (+ 2 (cdr n-a))) + (list-ref '( "ses" "s" "" "is" "isis") (+ 2 (cdr n-a))) (list-ref '("eses" "es" "" "is" "isis") (+ 2 (cdr n-a))))))))) -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; +(define-public ((chord-name->italian-markup re-with-eacute) pitch) + "Return pitch markup for PITCH, using italian/french note names. + If re-with-eacute is set to #t, french 'ré' is returned for D instead of 're' +" + (let* ((name (ly:pitch-notename pitch)) + (alt (ly:pitch-alteration pitch))) + (make-line-markup + (list + (make-simple-markup + (vector-ref + (if re-with-eacute + #("Do" "Ré" "Mi" "Fa" "Sol" "La" "Si") + #("Do" "Re" "Mi" "Fa" "Sol" "La" "Si")) + name)) + (accidental->markup-italian alt) + )))) ;; fixme we should standardize on omit-root (or the other one.) -;; perhaps the default should also be reversed --hwn -(define-public (sequential-music-to-chord-exceptions seq . rest) - "Transform sequential music SEQ of type <>-\markup{ foobar } +;; perhaps the default should also be reversed --hwn +(define-safe-public (sequential-music-to-chord-exceptions seq . rest) + "Transform sequential music SEQ of type <>-\\markup{ foobar } to (cons CDE-PITCHES FOOBAR-MARKUP), or to (cons DE-PITCHES FOOBAR-MARKUP) if OMIT-ROOT is given and non-false. " (define (chord-to-exception-entry m) - (let* ((elts (ly:get-mus-property m 'elements)) + (let* ((elts (ly:music-property m 'elements)) (omit-root (and (pair? rest) (car rest))) - (pitches (map (lambda (x) (ly:get-mus-property x 'pitch)) + (pitches (map (lambda (x) (ly:music-property x 'pitch)) (filter (lambda (y) (memq 'note-event - (ly:get-mus-property y 'types))) + (ly:music-property y 'types))) elts))) (sorted (sort pitches ly:pitch