lilypond-user
[Top][All Lists]
Advanced

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

Re: Break visibility for notes?


From: Thomas Morley
Subject: Re: Break visibility for notes?
Date: Fri, 1 May 2020 12:28:13 +0200

Am So., 26. Apr. 2020 um 20:25 Uhr schrieb Fr. Samuel Springuel
<address@hidden>:
>
> Okay, I’ve been applying this to my project and came across a problem with 
> the version I posted earlier: ledger lines are visible for the invisible 
> notes.  Now, I’ve tried applying the line-position function to 
> LedgerLineSpanner.transparent, but that doesn’t have any effect.  There is 
> NoteHead.no-ledgers which, when set to true, does make the ledger lines 
> disappear, but the line-position function complains about wrong argument type 
> (not a grob) when I try to apply it.  How can I adapt things so that the 
> ledger lines are invisible on the invisible notes?
>
> ✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝
> Fr. Samuel, OSB
> (R. Padraic Springuel)
> St. Anselm’s Abbey
> 4501 South Dakota Ave, NE
> Washington, DC, 20017
> 202-269-2300
> (c) 202-853-7036
>
> PAX ☧ ΧΡΙΣΤΟΣ

Hi,

sorry for coming back to this that late. Because of Corona the
workload for my regular job exploded ...

On topic.
Iiuc, the LedgerLineSpanner is initiated at start of the staff at
Staff-level. In other words before-line-breaking.
Though the line-position-procedure needs to read left/right-neighbors
after-line-breaking.

So we have different time-steps before/after-line-breaking and
different contexts Voce/Staff

Below a hackish and probably fragile method to get the desired output anyway.
Please test thoroughly before using it for serious work!

#(define (line-position grob)
"Returns position of @var[grob} in current system:
   @code{'start}, if at first time-step
   @code{'end}, if at last time-step
   @code{'middle} otherwise
"
  (let* ((col (ly:item-get-column grob))
         (ln (ly:grob-object col 'left-neighbor))
         (rn (ly:grob-object col 'right-neighbor))
         (col-to-check-left (if (ly:grob? ln) ln col))
         (col-to-check-right (if (ly:grob? rn) rn col))
         (break-dir-left
           (and
             (ly:grob-property col-to-check-left 'non-musical #f)
             (ly:item-break-dir col-to-check-left)))
         (break-dir-right
           (and
             (ly:grob-property col-to-check-right 'non-musical #f)
             (ly:item-break-dir col-to-check-right))))
        (cond ((eqv? 1 break-dir-left) 'start)
              ((eqv? -1 break-dir-right) 'end)
              (else 'middle))))

#(define (tranparent-at-line-position vctor)
  (lambda (grob)
  "Relying on @code{line-position} select the relevant enry from @var{vctor}.
Used to determine transparency,"
    (case (line-position grob)
      ((end) (not (vector-ref vctor 0)))
      ((middle) (not (vector-ref vctor 1)))
      ((start) (not (vector-ref vctor 2))))))

noteHeadBreakVisibility =
#(define-music-function (break-visibility)(vector?)
"Makes @code{NoteHead}s transparent relying on @var{break-visibility}"
#{
  \override NoteHead.transparent =
    #(tranparent-at-line-position break-visibility)
#})

#(define delete-ledgers-for-transparent-note-heads
  (lambda (grob)
    "Reads whether a @code{NoteHead} is transparent.
If so this @code{NoteHead} is removed from @code{'note-heads} from
@var{grob}, which is supposed to be @code{LedgerLineSpanner}.
As a result ledgers are not printed for this @code{NoteHead}"
    (let* ((nhds-array (ly:grob-object grob 'note-heads))
           (nhds-list
             (if (ly:grob-array? nhds-array)
                 (ly:grob-array->list nhds-array)
                 '()))
           ;; Relies on the transparent-property being done before
           ;; Staff.LedgerLineSpanner.after-line-breaking is executed.
           ;; This is fragile ...
           (to-keep
             (remove
               (lambda (nhd)
                 (ly:grob-property nhd 'transparent #f))
               nhds-list)))
      ;; TODO find a better method to iterate over grob-arrays, similiar
      ;; to filter/remove etc for lists
      ;; For now rebuilt from scratch
      (set! (ly:grob-object grob 'note-heads)  '())
      (for-each
        (lambda (nhd)
          (ly:pointer-group-interface::add-grob grob 'note-heads nhd))
        to-keep))))

\layout {
  \context {
      \Voice
      \noteHeadBreakVisibility #begin-of-line-invisible
  }
  \context {
      \Staff
      \override LedgerLineSpanner.after-line-breaking =
      #delete-ledgers-for-transparent-note-heads
  }
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Example
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

{
  %% This NoteHead would be made transparent (and without ledgers)
  %% to keep it use \once \noteHeadBreakVisibility with a suitable value
  %% p.e.:
  \once \noteHeadBreakVisibility #all-visible
  c'''1
  \break
  1
  1
}

HTH,
  Harm



reply via email to

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