[frogs] [PATCH] chord names language

[ Thread Index | Date Index | More lilynet.net/frogs Archives ]


It seems that this mail hasn't gone through (which is probably why I
didn't get any answers). Reposting with my gmail account.


---------- Forwarded message ----------
From: Valentin Villenave <valentin@xxxxxxxxxxxxx>
Date: Sun, Nov 21, 2010 at 11:06 AM
Subject: [PATCH] chord names language
To: frogs@xxxxxxxxxxx


Greetings everybody, hi Carl,

I'm having a look at chord names, and I think I have something to suggest.

Here's the current definition of note-name->markup:

(define-public (note-name->markup pitch lowercase?)
 "Return pitch markup for PITCH."
 (make-line-markup
  (list
   (make-simple-markup
    (conditional-string-downcase
     (vector-ref #("C" "D" "E" "F" "G" "A" "B") (ly:pitch-notename pitch))
     lowercase?))
   (accidental->markup (ly:pitch-alteration pitch)))))

As you can see, the note name vector is hardcoded; that's convenient
but not very elegant. How about retrieving note names from the
pitchnames alist instead? Not only would that be more elegant, but it
would also allow to (optionally) specify a different langauge, or take
into account the current input language:

diff --git a/scm/chord-name.scm b/scm/chord-name.scm
index 7f5909b..2853102 100644
--- a/scm/chord-name.scm
+++ b/scm/chord-name.scm
@@ -59,15 +59,38 @@
       (make-hspace-markup (if (= alteration SHARP) 0..2 0.1))
       ))))

+(define (note-names-vector alist)
+  "Extract note names from a pitchnames ALIST."
+  (let ((name-ls '()))
+    (map (lambda (x)
+          (let* ((pitch (cdr x))
+                 (alteration (ly:pitch-alteration pitch)))
+            (if (eq? alteration 0)
+                (set! name-ls (cons
+                               (string-capitalize (symbol->string (car x)))
+                               name-ls)))))
+         alist)
+    (list->vector (reverse name-ls))))
+
-(define-public (note-name->markup pitch lowercase?)
+(define-public (note-name->markup pitch lowercase? . input-language)
  "Return pitch markup for PITCH."
-  (make-line-markup
-   (list
-    (make-simple-markup
-     (conditional-string-downcase
-      (vector-ref #("C" "D" "E" "F" "G" "A" "B") (ly:pitch-notename pitch))
-      lowercase?))
-    (accidental->markup (ly:pitch-alteration pitch)))))
+  (let* ((get-pitchnames (lambda (x)
+                          (ly:assoc-get (string->symbol x)
+                                        language-pitch-names)))
+        (alist (get-pitchnames default-language)))
+    (if input-language
+       (cond ((string? input-language)
+              (set! alist (get-pitchnames input-language)))
+             ((boolean? input-language))
+             (set! alist pitchnames)))
+    (make-line-markup
+     (list
+      (make-simple-markup
+       (conditional-string-downcase
+       (vector-ref (note-names-vector alist)
+                   (ly:pitch-notename pitch))
+       lowercase?))
+      (accidental->markup (ly:pitch-alteration pitch))))))

To work, this also needs the pitchnames alist to be be declared much
earlier, which is why I suggested this other patch:
http://codereview.appspot.com/3247041/

You may wonder what the point is, well it's because I've been looking
at http://code.google.com/p/lilypond/issues/detail?id=1367 initially,
and there's a FIXME in pitch.cc that says
/* FIXME
  Merge with *pitch->text* funcs in chord-name.scm  */
so I wanted to have a look, and then I tried to move the
Note_name_engraver to a pure Scheme engraver, that would rely on the
note-name->markup function. More on that later!

Cheers,
Valentin.

---
----
Join the Frogs!


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/