Re: [frogs] [PATCH] chord names language

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


Hi Valentin.


On 12/7/10 9:42 AM, "Valentin Villenave" <v.villenave@xxxxxxxxx> wrote:

> 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:

Actually, we have it hardcoded in multiple lists.

We have note-name->german-markup, note-name->semi-german-markup, and
note-name->italian-markup as well.

I sketch out an architecture below that might allow us to do

pitch->markup

in the current language, and have it work out just that way.

> 
> 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)

This code won't work for German and Norwegian note names, where b is what
english calls b flat, and h is what english calls b.  There needs to be
something more general, and I'm not exactly sure what it is.

Perhaps the note name files should define both a pitch and a base name for
each of the pitches, and then we look up the base name from the pitch in the
given language, instead of trying to fake it with some other function.

I'm thinking that perhaps the lists in scm/define-note-names.scm would look
like

(nederlands . ((entry-names . (
                              (ceses . ,(ly:make-pitch -1 0 DOUBLE-FLAT))
                              ...
                              ))
               (display-names . (
                                ((0 DOUBLE-FLAT) . "C")
                                ((0 SEMI-FLAT) . "C")
                              ...
                                ))))

and then we'd need to modify the functions that get the pitch-name-alist to
get the entry-names key from the language alist.  The markup we'd get by
getting  display-names alist, and we'd do something like

(define (pitch->markup pitch)
  (let ((note-name (ly:pitch-notename pitch))
        (alteration (ly:pitch-alteration pitch)))
   (assoc-get (list note-name alteration) display-names-alist "")))



> +                (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!

This sounds great!

Carl



---
----
Join the Frogs!


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