[frogs] [PATCH] chord names language |
[ Thread Index |
Date Index
| More lilynet.net/frogs Archives
]
- To: frogs@xxxxxxxxxxx
- Subject: [frogs] [PATCH] chord names language
- From: Valentin Villenave <v.villenave@xxxxxxxxx>
- Date: Tue, 7 Dec 2010 17:42:32 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=W04dEoAjBgSekBeG9I/uTVfSOStJ2IAelNpo+xI1tbw=; b=X6pcPrNW7S84i3AZSUsaDD8bv6fi7OP5/J3dseswv/bC7NLCyCLR9+4Gzj8NZsMMhn Rx00yERG6QpordZoI3M25X4g2rtYeLTpwin+UwoM9lnF3PlLEGkaoLqoLPgjMs8vmem0 EtfOL2PamP0Ilks5ZxmlcFAlNueOXHNU+SIwM=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=bPoSjTEwP479nz/RbBR6xyjl6aXpSszb6YdWf+E3sy1t00UMCpnSJ8rurVAvi67LRR XD4AmZZ5Qidenrbt8Fh3wHX64AcVw/avAfPaFYHnX9j412CpYG9GMnIWRwB4LKjM/xbq p+VSzxL9aPFs1AIvXTjydy69u04NeIbzoHk8I=
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!