lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Programming Question


From: David Nalesnik
Subject: Re: Programming Question
Date: Thu, 18 Sep 2014 20:00:50 -0500

Hi Jay,

On Thu, Sep 18, 2014 at 6:28 PM, Jay Vara <address@hidden> wrote:
> I am not top-posting

David,

I defined a second variable nsiz which is 1, 2 or 3

Tried

(case duration-log
 ((nsiz) "a" )
  (else "")))

This condition was never succeeding although I printed out nsiz and
duration-log and they were the same.

Then I changed it into an if statement - that worked. This is to add a
suffix to note name for half notes in normal duration, quarter notes in
halved durations, and eighth notes when durations are further halved. It
should be obvious from the output that it has worked.

Then further, I wanted the suffix to be "i" if the note was d or b. I
tried various if statements and they are all failing for some reason.
default-name which is equal to "d" gives a #f when tested, for example.
Not sure what to do to make it work.

Perhaps it's your choice of comparison by eq?  I can't say what it does with strings, but it generally tests that an object is the same object as another, rather than simply equivalent.  (If you want more on these, you can read up on them in the Guile manual).

string=? seems to work.  Try the following--is it what you want?

 #(define (myNoteNames size nsiz)
   (lambda (grob)
     (let* (
             ;; bindings
             (default-name (ly:grob-property grob 'text))
             (new-name (assoc-get default-name newnames))
             (cause (event-cause grob))
             (duration (ly:prob-property cause 'duration))
             (duration-log (ly:duration-log duration))
             (suffix
              (case duration-log
                ((1) (if (= nsiz 1)
                         (if (or (eqv? new-name "R")
                                 (eqv? default-name "b"))
                             "i"
                             "a")
                         "")) ;; half note
                ((2) (if (= nsiz 2) "a" "")) ;; quarter note
                ((3) (if (= nsiz 3) "a" "")) ;; eighth note
                (else "")))
             (suffix2
              (if
               (or (string=? default-name "b")
                   (string=? default-name "d"))
               "i"
               ""))
             (text (string-append new-name suffix suffix2))
             )
       (display default-name)
       (display (eq? default-name "d"))
       (display duration-log) (display size) (display nsiz) (display text)
       (newline);; body
       (ly:grob-set-property! grob 'text (markup #:fontsize size text))
       (ly:text-interface::print grob)
       )
     ))

%%%%%%%%%
Best,
David


reply via email to

[Prev in Thread] Current Thread [Next in Thread]