Re: Add on-page-greater-than, -less-than (on-the-fly) (issue 74540044)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Add on-page-greater-than, -less-than (on-the-fly) (issue 74540044)

David Kastrup
Ok, I've taken another look at something that should help with this
amount of fine-grained definitions.  Do you think that the following
macro markup-when would be fine-grained enough to forego these kind of
definition?  I demonstrate it for implementing on-page-greater-than but
of course one may use it directly.  Its first argument is of the same
style as the #:properties keyword arg for define-markup-command .

#(define-macro (markup-when properties cond)
   `(lambda (layout props arg)
     (let ,(map (lambda (p)
                (if (pair? p)
                 `(,(car p) (chain-assoc-get ',(car p) props ,@(cdr p)))
                 `(,p (chain-assoc-get ',p props))))
           properties)
      (if ,cond (interpret-markup layout props arg)
       empty-stencil))))

#(define (on-page-greater-than nmbr)
   (markup-when ((page:page-number -1))
    (> page:page-number nmbr)))

\paper {
   #(set-paper-size "a7landscape")
   oddFooterMarkup = \markup \on-the-fly #(on-page-greater-than 3) "This
is long!"
}

\score {
   \repeat unfold 256 c'1
}


https://codereview.appspot.com/74540044/

_______________________________________________
lilypond-devel mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-devel
Reply | Threaded
Open this post in threaded view
|

Re: Add on-page-greater-than, -less-than (on-the-fly) (issue 74540044)

paulwmorris
On 2017/06/09 13:36:53, dak wrote:
> Ok, I've taken another look at something that should help with this
amount of
> fine-grained definitions.

LGTM. Although I'm still new to understanding scheme macros, I
think I understand the gist of what's going on.

> Do you think that the following macro markup-when
> would be fine-grained enough to forego these kind of definition?

You mean so the user would use this markup-when macro to define their
own
'on-page-greater-than' and/or 'on-page-less-than' (like you've shown),
rather than
adding them to LilyPond?

If so, that seems fine to me.  They seem like fairly rare use cases.
Would
make a good snippet for the LSR or docs, so it can be found and used
when needed.

> I demonstrate
> it for implementing on-page-greater-than but of course one may use it
directly.

Directly like this I assume? (Which works.)

\paper {
   #(set-paper-size "a7landscape")
   oddFooterMarkup = \markup \on-the-fly
   #(markup-when ((page:page-number -1))
      (> page:page-number 3))
   "This is long!"
}

> Its first argument is of the same style as the #:properties keyword
arg for
> define-markup-command .

That's a nice consistency.  I tried it out and the following works too:

#(define (onpage proc nmbr)
   (markup-when ((page:page-number -1))
    (proc page:page-number nmbr)))

\paper {
   #(set-paper-size "a7landscape")
   oddFooterMarkup = \markup \on-the-fly #(onpage > 3) "This is
long!"
}

-Paul



https://codereview.appspot.com/74540044/

_______________________________________________
lilypond-devel mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-devel
Reply | Threaded
Open this post in threaded view
|

Re: Add on-page-greater-than, -less-than (on-the-fly) (issue 74540044)

David Kastrup
In reply to this post by David Kastrup
On 2017/06/10 19:36:30, pwm wrote:

> That's a nice consistency.  I tried it out and the following works
too:

> #(define (onpage proc nmbr)
>    (markup-when ((page:page-number -1))
>     (proc page:page-number nmbr)))

> \paper {
>    #(set-paper-size "a7landscape")
>    oddFooterMarkup = \markup \on-the-fly #(onpage > 3) "This is
> long!"
> }

Come to think of it, the only application would seem in connection with
\on-the-fly, so it should be possible to wrap the \on-the-fly invocation
into the macro as well.

I've put up issue 5145 for basically replacing \on-the-fly with $ when
one really wants to write this as \markup $(onpage > 3) "This is long!".

This requires an amended definition of markup-when adding a markup
command signature:

#(define-macro (markup-when properties . cond)
    `(let ((markfun
           (lambda (layout props arg)
             (if
              (let ,(map (lambda (p)
                           (if (pair? p)
                               `(,(car p) (chain-assoc-get ',(car p) props ,@(cdr p)))
                               `(,p (chain-assoc-get ',p props))))
                         properties)
                ,@cond)
              (interpret-markup layout props arg)
              empty-stencil))))
       (set! (markup-command-signature markfun)
            (list markup?))
       markfun))

#(define (on-page-greater-than nmbr)
   (markup-when ((page:page-number -1))
    (> page:page-number nmbr)))

\paper {
   #(set-paper-size "a7landscape")
   oddFooterMarkup = \markup $(on-page-greater-than 3) "This is long!"
}

\score {
   \repeat unfold 256 c'1
}

I don't actually want to pursue this path as the preferred user
interface: it just seemed to me that it should work.

https://codereview.appspot.com/74540044/

_______________________________________________
lilypond-devel mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-devel