lilypond-user
[Top][All Lists]
Advanced

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

Re: Do not display chord name after line break


From: Thomas Morley
Subject: Re: Do not display chord name after line break
Date: Tue, 14 Jul 2020 21:39:46 +0200

Am Di., 14. Juli 2020 um 18:47 Uhr schrieb Carl Sorensen
<carl.d.sorensen@gmail.com>:
>
> Ernie,
>
> I'll point it out below.
>
> On Tue, Jul 14, 2020 at 10:42 AM Ernie Braganza <ernie.braganza@gmail.com> 
> wrote:
>>
>> I am not sure where to place this new engraver code so I can use it. I tried 
>> researching this in the manual, but was still unclear. Where should it 
>> appear? Again, thanks for your help
>>
>> On Mon, Jul 13, 2020 at 8:15 PM Thomas Morley <thomasmorley65@gmail.com> 
>> wrote:
>>>
>>>
>>> Here an engraver which transforms the default stencil to an empty
>>> stencil under certain conditions (it's not a rewrite of
>>> Chord_name_engraver)
>>>
> Right here is a new ChordNames context that has everything you need.  Put the 
> whole context into your file, replacing the current  ChordNames context.
>>>
>>> \new ChordNames
>>>   \with {
>>>     chordChanges = ##t
>>>       \consists
>>>       #(lambda (ctx)
>>>         (let* ((chord #f)
>>>                (last-chord #f))
>>>
>>>        (define (at-line-beginning? grob)
>>>          (let* ((col (ly:item-get-column grob))
>>>                 (ln (ly:grob-object col 'left-neighbor))
>>>                 (col-to-check (if (ly:grob? ln) ln col)))
>>>            (and (eq? #t (ly:grob-property col-to-check 'non-musical))
>>>                 (= 1 (ly:item-break-dir col-to-check)))))
>>>
>>>          (make-engraver
>>>           (acknowledgers
>>>            ((chord-name-interface this-engraver grob source-engraver)
>>>
>>>              (if chord
>>>                  (begin
>>>                    (set! last-chord chord)
>>>                    (set! chord #f)))
>>>
>>>              (set! chord (ly:grob-property grob 'text))
>>>
>>>              ;; If two subsequent chords are equal and chordChanges is 
>>> enabled,
>>>              ;; set 'after-line-breaking to a procedure which sets the 
>>> stencil
>>>              ;; to an empty-stencil if the new chord is at line-start.
>>>              (if (and (equal? chord last-chord)
>>>                       (ly:context-property ctx 'chordChanges #f))
>>>                  (ly:grob-set-property! grob 'after-line-breaking
>>>                    (lambda (grob)
>>>                      (if (at-line-beginning? grob)
>>>                          (ly:grob-set-property! grob 'stencil 
>>> empty-stencil))
>>>                      ;; keep default
>>>                      (ly:chord-name::after-line-breaking grob))))))
>>>           ((finalize this-engraver)
>>>             ;; house keeping
>>>             (set! chord #f)
>>>             (set! last-chord #f)))))
>>>   }
>
> This is the end of the ChordNames context
>
>>>
>>>   \chordmode { d2 c~ \break c d }
>>>
> The chormode code is then placed in the ChordNames context.  You may wish to 
> surround it with{}, although it is not necessary here because the \chordmode 
> {} is a single music expresion.
>
> HTH,
>
> Carl

Addditionally, it may be less confusing if you name the engraver. Makes for:

My_chord_changes_engraver =
  #(lambda (ctx)
    (let* ((chord #f)
           (last-chord #f))

   (define (at-line-beginning? grob)
     (let* ((col (ly:item-get-column grob))
            (ln (ly:grob-object col 'left-neighbor))
            (col-to-check (if (ly:grob? ln) ln col)))
       (and (eq? #t (ly:grob-property col-to-check 'non-musical))
            (= 1 (ly:item-break-dir col-to-check)))))

     (make-engraver
      (acknowledgers
       ((chord-name-interface this-engraver grob source-engraver)

         (if chord
             (begin
               (set! last-chord chord)
               (set! chord #f)))

         (set! chord (ly:grob-property grob 'text))

         ;; If two subsequent chords are equal and chordChanges is enabled,
         ;; set 'after-line-breaking to a procedure which sets the stencil
         ;; to an empty-stencil if the new chord is at line-start.
         (if (and (equal? chord last-chord)
                  (ly:context-property ctx 'chordChanges #f))
             (ly:grob-set-property! grob 'after-line-breaking
               (lambda (grob)
                 (if (at-line-beginning? grob)
                     (ly:grob-set-property! grob 'stencil empty-stencil))
                 ;; keep default
                 (ly:chord-name::after-line-breaking grob))))))
      ((finalize this-engraver)
        ;; house keeping
        (set! chord #f)
        (set! last-chord #f)))))

\new ChordNames
  \with {
    chordChanges = ##t
    \consists \My_chord_changes_engraver
  }
  \chordmode { d2 c~ \break c d }

Cheers,
  Harm



reply via email to

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