[Top][All Lists]

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

Re: \parenthesize and optional arguments

From: David Kastrup
Subject: Re: \parenthesize and optional arguments
Date: Sat, 04 Jul 2015 09:17:15 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Marc Hohl <address@hidden> writes:

> my scheme-fu is a bit rusty, so I tried to get a new start
> by enhancing the parenthesize function defined in
> ly/ with the code to be found in
> Here is what I have so far:
> \version "2.19.20"
> parenthesize =
> #(define-music-function (dir arg) ((number? 0) ly:music?)
>    (_i "Tag @var{arg} to be parenthesized. @arg{dir} is optional and may be
>    set to @code{#LEFT} or @code{#RIGHT} for left/right parentheses only.")
>    (display dir)
>    (case dir
>          ((-1) #{ \once\override ParenthesesItem.stencils = #(lambda (grob)
>                                    (let ((par-list
> (parentheses-item::calc-parenthesis-stencils grob)))
>                                         (list (car par-list)
> point-stencil ))) #})
>          ((1) #{ \once \override ParenthesesItem.stencils = #(lambda (grob)
>                                    (let ((par-list
> (parentheses-item::calc-parenthesis-stencils grob)))
>                                         (list point-stencil (cadr
> par-list)))) #}) )

You are thinking of LilyPond/Scheme as a procedural language here.  What
happens here is that you calculate a suitable override and, well, throw
it away.  The return value of this function, calculated later as "arg",
does not care what you have calculated here.

It's probably better to switch this around with the below (imperative,
namely using side effects) calculation of arg and then write
#{ \once \override ... #arg #} in order to get the arg in after all.
Don't forget an "else" branch returning only the unchanged arg.

>    (if (memq 'event-chord (ly:music-property arg 'types))
>        ;; arg is an EventChord -> set the parenthesize property
>        ;; on all child notes and rests
>        (for-each
>         (lambda (ev)
>           (if (or (memq 'note-event (ly:music-property ev 'types))
>                   (memq 'rest-event (ly:music-property ev 'types)))
>               (set! (ly:music-property ev 'parenthesize) #t)))
>         (ly:music-property arg 'elements))
>        ;; No chord, simply set property for this expression:
>        (set! (ly:music-property arg 'parenthesize) #t))
>    arg)
> { \parenthesize c \parenthesize #LEFT d \parenthesize #RIGHT e}
> It seems as if the \override does not have any effect, though,
> but I don't understand why.

Because you don't put it in the result of the music function.

> Any pointers in the right direction are highly appreciated!

#UP (which is Lilypond-speak for +1).

David Kastrup

reply via email to

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