lilypond-user
[Top][All Lists]
Advanced

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

Re: getting a TextSpanner 'text


From: Carl Sorensen
Subject: Re: getting a TextSpanner 'text
Date: Thu, 14 Apr 2011 09:25:32 -0600



On 4/14/11 1:47 AM, "Graham Percival" <address@hidden> wrote:

> How do you get values from a context property?  I'm trying to access
> the left-bound text.  I know I can do it like this:
>   (cdr (car (cdr (car (cdr (car (car (ly:context-property context
> 'TextSpanner)))))))))))
> but that's kind-of ugly.

Yes, it is.  At the very least, you should use things like (caar x) which is
equal to (car (car x)).
> 
> This code:
> 
> #(define (format-textspan engraver event)
>    (let* ((context (ly:translator-context engraver))
>           (moment (ly:context-current-moment context)))
>      (display "\n")
>      (display
>           (ly:context-property context 'TextSpanner)
>      )
> ))
> 
> 
> produces the following (with linebreaks and indents added).  I'm
> really confused about the multiple "bound-details", the multiple
> "left/right" inside each bound-details, etc.  How can I make sure I
> get the bound-details that I want, without using plain old (car ...) ?
> 

The correct bound-details is the first one (overrides are prepended; the old
values are not removed).

The proper way to do it is something like

(let* ((spanner-props (ly:context-property context 'TextSpanner))
       (details (assoc-get 'bound-details spanner-props '()))
       (left-props (assoc-get 'left details left-props '()))
       (left-text (assoc-get 'text left-props '())))
    (display left-text))

We try never to use the structure to get things; we always try to use the
associated keys.

HTH,

Carl




reply via email to

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