Remove all occurrencies of "0" fingerings

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Remove all occurrencies of "0" fingerings

Marc Hohl
Hello list!

I wanted to write a little callback to remove all occurrencies
of "0" fingerings. This is what I got so far:


\version "2.19.63"

music = {
   c'4-3 d'-0 e'-2 f'-3 | g'1-0
}

\score {
   \new Staff \with {
     \override Fingering.stencil =
       #(lambda (grob)
          (let* ((text (ly:grob-property grob 'text))
                 (stencil (if (equal? text "0")
                              empty-stencil
                              (ly:grob-property grob 'stencil))))
                stencil)) }
   { \music }
}


Compiling this nearly MWE, I get:

Warning: Fingering has empty extent and non-empty stencil.
Warning: Fingering has empty extent and non-empty stencil.

And *no* fingering at all is shown in the resulting score.
What am I doing wrong?

Regards,

Marc

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

Re: Remove all occurrencies of "0" fingerings

Malte Meyn-3


Am 08.08.2017 um 10:23 schrieb Marc Hohl:
>
> I wanted to write a little callback to remove all occurrencies
> of "0" fingerings.

This doesn’t empty the stencil but removes the Fingering grobs
completely (by suicide):

     \override Fingering.before-line-breaking =
     #(lambda (grob)
        (if (equal? (ly:grob-property grob 'text) "0")
            (ly:grob-suicide! grob)))

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

Re: Remove all occurrencies of "0" fingerings

Marc Hohl
Hi Malte,

Am 08.08.2017 um 10:30 schrieb Malte Meyn:
>
>
> Am 08.08.2017 um 10:23 schrieb Marc Hohl:
>>
>> I wanted to write a little callback to remove all occurrencies
>> of "0" fingerings.
>
> This doesn’t empty the stencil but removes the Fingering grobs
> completely (by suicide):

thanks for this solution!

In my real-life example, I got

lilypond: ../flower/include/drul-array.hh:35: T&
Drul_array<T>::at(Direction) [with T = scm_unused_struct*]: Zusicherung
 >>d == 1 || d == -1<< nicht erf?llt.
Aborted (core dumped)

but changing before-line-breaking to after-line-breaking did the trick.

I do not fully understand why, but it works.

Thanks,

Marc

>
>      \override Fingering.before-line-breaking =
>      #(lambda (grob)
>         (if (equal? (ly:grob-property grob 'text) "0")
>             (ly:grob-suicide! grob)))
>
> _______________________________________________
> lilypond-user mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/lilypond-user


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

Re: Remove all occurrencies of "0" fingerings

Thomas Morley-2
2017-08-08 11:46 GMT+02:00 Marc Hohl <[hidden email]>:

> Hi Malte,
>
> Am 08.08.2017 um 10:30 schrieb Malte Meyn:
>>
>>
>>
>> Am 08.08.2017 um 10:23 schrieb Marc Hohl:
>>>
>>>
>>> I wanted to write a little callback to remove all occurrencies
>>> of "0" fingerings.
>>
>>
>> This doesn’t empty the stencil but removes the Fingering grobs completely
>> (by suicide):
>
>
> thanks for this solution!
>
> In my real-life example, I got
>
> lilypond: ../flower/include/drul-array.hh:35: T&
> Drul_array<T>::at(Direction) [with T = scm_unused_struct*]: Zusicherung >>d
> == 1 || d == -1<< nicht erf?llt.music = {
  \set fingeringOrientations = #'(left)
  c'4-333333333333 d'-0 e'-2 <f'-333333333333> | g'1_0 a'^0
}

\score {
  \new Staff
  \with {
    \override Fingering.after-line-breaking =
    #(lambda (grob)
          (if (equal? (ly:grob-property grob 'text) "333333333333")
              (ly:grob-suicide! grob)))
  }
  { \music }
}

> Aborted (core dumped)
>
> but changing before-line-breaking to after-line-breaking did the trick.
>
> I do not fully understand why, but it works.
>
> Thanks,
>
> Marc
>
>>
>>      \override Fingering.before-line-breaking =
>>      #(lambda (grob)
>>         (if (equal? (ly:grob-property grob 'text) "0")
>>             (ly:grob-suicide! grob)))

Hi Marc,

your initial code had two problems, comments inline:

\override Fingering.stencil =
  #(lambda (grob)
     (let* ((text (ly:grob-property grob 'text))
            (stencil (if (equal? text "0")
                         ;; to avoid the warning go for point-stencil
                         ;; not empty-stencil
                         point-stencil
                         ;; return a stencil yourself, don't call the
                         ;; property which is created by the stencil-prop
                         ;; it's a cycle and I'm somewhat surprised it failed
                         ;; not more spectaculary
                         (ly:text-interface::print grob))))
           stencil))

In certain cases going for after-line-break will be too late and
leaves you with bad spacing:

music = {
  \set fingeringOrientations = #'(left)
  c'4-333333333333 d'-0 e'-2 <f'-333333333333> | g'1_0 a'^0
}

\score {
  \new Staff
  \with {
    \override Fingering.after-line-breaking =
    #(lambda (grob)
          (if (equal? (ly:grob-property grob 'text) "333333333333")
              (ly:grob-suicide! grob)))
  }
  { \music }
}

Ofcourse it's far less likely that a single-digit like will cause such badness.
Nevertheless I'd research why/where your real-life code gives that
assertion failure.


Cheers,
  Harm

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
dak
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Remove all occurrencies of "0" fingerings

dak
In reply to this post by Marc Hohl
Marc Hohl <[hidden email]> writes:

> I wanted to write a little callback to remove all occurrencies
> of "0" fingerings. This is what I got so far:
>
>
> \version "2.19.63"
>
> music = {
>   c'4-3 d'-0 e'-2 f'-3 | g'1-0
> }
>
> \score {
>   \new Staff \with {
>     \override Fingering.stencil =
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>       #(lambda (grob)
[...]
>                              (ly:grob-property grob 'stencil))))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> Compiling this nearly MWE, I get:
>
> Warning: Fingering has empty extent and non-empty stencil.
> Warning: Fingering has empty extent and non-empty stencil.
>
> And *no* fingering at all is shown in the resulting score.
> What am I doing wrong?

Recursion: see Recursion.

You can do this by using


\version "2.19.63"

music = {
  c'4-3 d'-0 e'-2 f'-3 | g'1-0
}

\score {
  \new Staff \with {
    \override Fingering.text =
    #(grob-transformer 'text
      (lambda (grob default)
       (if (string= "0" default)
        ""
        default)))
  { \music }
}


assuming that text is indeed just a string.  The warning actually still
occurs.  However, that is a rather glaring bug (the stencil _is_ empty
and the respective code checks for _existence_ of a stencil (which is
guaranteed at that code point) rather than its non-emptiness).  I'll be
providing a patch presently.

--
David Kastrup

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

Re: Remove all occurrencies of "0" fingerings

Thomas Morley-2
2017-08-08 12:47 GMT+02:00 David Kastrup <[hidden email]>:

>
> You can do this by using
[...]

Nice one. I always forget about 'grob-transformer'. Missing bracket, tho'

\score {
  \new Staff \with {
    \override Fingering.text =
    #(grob-transformer 'text
      (lambda (grob default)
       (if (string= "0" default)
""
default)))
} %% <--------------
  { \music }
}

Cheers,
  Harm

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
dak
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Remove all occurrencies of "0" fingerings

dak
Thomas Morley <[hidden email]> writes:

> 2017-08-08 12:47 GMT+02:00 David Kastrup <[hidden email]>:
>
>>
>> You can do this by using
> [...]
>
> Nice one. I always forget about 'grob-transformer'. Missing bracket, tho'

Edited out a debug printer before posting (which is why I figured the
warning to be bogus), obviously without trying the code again.  Sigh.

--
David Kastrup

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

Re: Remove all occurrencies of "0" fingerings

Marc Hohl
In reply to this post by dak
Am 08.08.2017 um 12:47 schrieb David Kastrup:

> Marc Hohl <[hidden email]> writes:
>
>> I wanted to write a little callback to remove all occurrencies
>> of "0" fingerings. This is what I got so far:
>>
>>
>> \version "2.19.63"
>>
>> music = {
>>    c'4-3 d'-0 e'-2 f'-3 | g'1-0
>> }
>>
>> \score {
>>    \new Staff \with {
>>      \override Fingering.stencil =
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>        #(lambda (grob)
> [...]
>>                               (ly:grob-property grob 'stencil))))
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
>> Compiling this nearly MWE, I get:
>>
>> Warning: Fingering has empty extent and non-empty stencil.
>> Warning: Fingering has empty extent and non-empty stencil.
>>
>> And *no* fingering at all is shown in the resulting score.
>> What am I doing wrong?
>
> Recursion: see Recursion.

Ah, yes!

I think I intermingled the idea to use Fingering.after-line-breaking
(where stencil is already defined) and Fingering.stencil (to remove the
stencil before any layout decisions are completed).

Thanks for clarification!

Marc

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

Re: Remove all occurrencies of "0" fingerings

Marc Hohl
In reply to this post by Thomas Morley-2
Am 08.08.2017 um 13:00 schrieb Thomas Morley:
> 2017-08-08 12:47 GMT+02:00 David Kastrup <[hidden email]>:
>
>>
>> You can do this by using
> [...]
>
> Nice one. I always forget about 'grob-transformer'. Missing bracket, tho'

I wasn't aware of grob-transformer at all. And I am still unsure about
what it does. I have read the doc string, though.

Thanks,

Marc

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
dak
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Remove all occurrencies of "0" fingerings

dak
Marc Hohl <[hidden email]> writes:

> Am 08.08.2017 um 13:00 schrieb Thomas Morley:
>> 2017-08-08 12:47 GMT+02:00 David Kastrup <[hidden email]>:
>>
>>>
>>> You can do this by using
>> [...]
>>
>> Nice one. I always forget about 'grob-transformer'. Missing bracket, tho'
>
> I wasn't aware of grob-transformer at all. And I am still unsure about
> what it does. I have read the doc string, though.

It gives your function both the grob and the value (callbacks and
unpure/pure containers already resolved) that _would_ get calculated
without your override in place.

That can be handy when your function just wants to modify the default,
or if the default is only used sometimes.  To use it, you don't need to
know whether the default is a constant, a function, or an unpure/pure
container.

--
David Kastrup

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

Re: Remove all occurrencies of "0" fingerings

Marc Hohl
Am 08.08.2017 um 18:44 schrieb David Kastrup:

> Marc Hohl <[hidden email]> writes:
>
>> Am 08.08.2017 um 13:00 schrieb Thomas Morley:
>>> 2017-08-08 12:47 GMT+02:00 David Kastrup <[hidden email]>:
>>>
>>>>
>>>> You can do this by using
>>> [...]
>>>
>>> Nice one. I always forget about 'grob-transformer'. Missing bracket, tho'
>>
>> I wasn't aware of grob-transformer at all. And I am still unsure about
>> what it does. I have read the doc string, though.
>
> It gives your function both the grob and the value (callbacks and
> unpure/pure containers already resolved) that _would_ get calculated
> without your override in place.
>
> That can be handy when your function just wants to modify the default,
> or if the default is only used sometimes.  To use it, you don't need to
> know whether the default is a constant, a function, or an unpure/pure
> container.

I see. Thanks for your explanation!

Marc

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

Re: Remove all occurrencies of "0" fingerings

Marc Hohl
In reply to this post by Thomas Morley-2
Am 08.08.2017 um 12:35 schrieb Thomas Morley:
> 2017-08-08 11:46 GMT+02:00 Marc Hohl <[hidden email]>:
[...]

> Hi Marc,
>
> your initial code had two problems, comments inline:
>
> \override Fingering.stencil =
>    #(lambda (grob)
>       (let* ((text (ly:grob-property grob 'text))
>              (stencil (if (equal? text "0")
>                           ;; to avoid the warning go for point-stencil
>                           ;; not empty-stencil
>                           point-stencil
>                           ;; return a stencil yourself, don't call the
>                           ;; property which is created by the stencil-prop
>                           ;; it's a cycle and I'm somewhat surprised it failed
>                           ;; not more spectaculary
>                           (ly:text-interface::print grob))))
>             stencil))


For the record: First, I used the solution with grob-transformer, but
then I found out that removing the grob completely yields to problems
with glissando lines between fingerings, so I switched to the solution
given above.

Thanks a lot!

Marc

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
dak
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Remove all occurrencies of "0" fingerings

dak
Marc Hohl <[hidden email]> writes:

> Am 08.08.2017 um 12:35 schrieb Thomas Morley:
>> 2017-08-08 11:46 GMT+02:00 Marc Hohl <[hidden email]>:
> [...]
>> Hi Marc,
>>
>> your initial code had two problems, comments inline:
>>
>> \override Fingering.stencil =
>>    #(lambda (grob)
>>       (let* ((text (ly:grob-property grob 'text))
>>              (stencil (if (equal? text "0")
>>                           ;; to avoid the warning go for point-stencil
>>                           ;; not empty-stencil
>>                           point-stencil
>>                           ;; return a stencil yourself, don't call the
>>                           ;; property which is created by the stencil-prop
>>                           ;; it's a cycle and I'm somewhat surprised it failed
>>                           ;; not more spectaculary
>>                           (ly:text-interface::print grob))))
>>             stencil))
>
>
> For the record: First, I used the solution with grob-transformer, but
> then I found out that removing the grob completely yields to problems
> with glissando lines between fingerings, so I switched to the solution
> given above.

Your description did not imply that you actually wanted to use that
point for positioning purposes.  However, I think glissandi are between
noteheads rather than fingerings.  It's conceivable that they try taking
fingerings into account in some manner: in that case, it would make
sense if they ignored empty stencils.

At any rate, it is sort of amusing that your choice between two complex
solutions hinges on whether they use point-stencil or empty-stencil
internally: interchanging those two is not all that hard.  At least
Thomas documented his solution better.

--
David Kastrup

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

Re: Remove all occurrencies of "0" fingerings

Marc Hohl
Am 15.08.2017 um 10:15 schrieb David Kastrup:

> Marc Hohl <[hidden email]> writes:
>[...]
>> For the record: First, I used the solution with grob-transformer, but
>> then I found out that removing the grob completely yields to problems
>> with glissando lines between fingerings, so I switched to the solution
>> given above.
>
> Your description did not imply that you actually wanted to use that
> point for positioning purposes.  However, I think glissandi are between
> noteheads rather than fingerings.  It's conceivable that they try taking
> fingerings into account in some manner: in that case, it would make
> sense if they ignored empty stencils.

Yes, of course. I wasn't aware of the implications either – putting
glissando lines between fingerings is quite straightforward, but I had
to use glissandoMap and some trickery to create a satisfactory result.

My current project includes a book with a violin and a guitar staff, and
an additional handout for guitar-only purposes with tablature added. My
focus was primarily on the first part, which has to be finished in terms
of the layout as soon as possible for the illustrator to start to draw
the pictures to be added later. Therefore I missed the glissando line
suddenly pointing to nowhere in the tablature part.

Interestingly, I didn't see the spurious line on screen, but in a
printoutthat I am currently using for practicing the guitar part that
will be
recorded in a couple of days. I don't know whether others have made
similar experiences, but on screen nearly everything seems to look
correct.

> At any rate, it is sort of amusing that your choice between two complex
> solutions hinges on whether they use point-stencil or empty-stencil
> internally: interchanging those two is not all that hard.  At least
> Thomas documented his solution better.

Well, IIRC you were the first who mentioned the recursion error (which I
should have found myself – silly me).  But I have to admit that Harm's
solution works with scheme functions I understood at first glance,
whereas the grob-transformer stuff was not that easy for me to cope
with.

Conclusion: the list is great, and the fact that there are multiple
solutions to a problem makes it easier to find the most suitable
workaround ;-)

Regards,

Marc
>


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