[Top][All Lists]

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

Re: Syntax-question about nested functions/procedures

From: David Kastrup
Subject: Re: Syntax-question about nested functions/procedures
Date: Wed, 01 Aug 2012 05:06:01 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux)

Thomas Morley <address@hidden> writes:

> Hi,
> fiddling around with a new patch for issue 2646 I tried to integrate
> default-parenthesize into another function.
> The following returns an error when uncommenting \override
> Score.ParenthesesItem #'font-size = #0 and applying it to an
> articulation.
> \version "2.15.42"
> parenthesizeII =
> #(define-music-function (parser location mus) (ly:music?)
> (define (proc arg)
> ;; from
>     (if (memq 'event-chord (ly:music-property arg 'types))
      (if (music-is-of-type? arg 'event-chord)

is a bit more readable.
>        ;; 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)
> #{
>         %\override Score.ParenthesesItem #'font-size = #0
>         $(proc mus)
> #})

Without override, it is a single music expression.  With override, it is
sequential music containing an override as first element and the input
as second element, and sequential music can't be a post-event.

An override has permanent effect, and even \once\override affects
everything at a given timestep.  More likely than not, you want a tweak.

> \relative c' {
>       % works
>       \parenthesizeII a'4-1
>       % returns an error when uncommenting the
>       % font-size-override above
>         a4-\parenthesizeII-1
> }
> What's wrong and how to do it better?

Well, here is an only slightly tongue-in-cheek version which first lets
\parenthesize to the job and then tweaks everything it finds
parenthesized.  If you copy the core of \parenthesize, as you did above,
you would likely manipulate the 'tweak music property yourself,
prepending an appropriate tweak.

\version "2.15.42"

parenthesizeII =
#(define-music-function (parser location mus) (ly:music?)
    (lambda (m)
      (and (ly:music-property m 'parenthesize #f)
           #{ \tweak ParenthesesItem #'font-size #0 #m #}))
    #{ \parenthesize #mus #}))

\relative c' {
        % works
        \parenthesizeII a'4-1

David Kastrup

reply via email to

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