Hello Harm,

This is fantastic, thank you for the help. I was working through how I
would do this with case statements, but there are clearly elegant utility
functions I haven't learned about yet.

The only change I made was to reverse the 0 and the 1 in your if statement:
 (if (even? (abs staff-pos)) 1 0)


Many thanks,
mattfong

On Mon, Mar 8, 2021 at 2:55 AM Thomas Morley <[email protected]>
wrote:

> Am Mo., 8. März 2021 um 02:26 Uhr schrieb Matthew Fong <[email protected]
> >:
> >
> > Hello everyone,
> >
> >
> > I'm writing a function that places a custos after the double bar to give
> singers an indication of the pitch of their next note. Usually, custos are
> are used within a piece, but in chant, I have verses that are part of new
> scores, and it is helpful to indicate the pitch of the first note.
> >
> >
> > I wanted to custos to be consistent with the intra-piece custos as I
> have set it up, that is,
> >
> >
> > 1/ Notes on the ledger line up until b' use custodes.vaticana.u1 (long
> stem up)
> >
> > 2/ Notes in between the ledger up until b' use custodes.vaticana.u0
> (short stem up)
> >
> > 3/ Notes on the ledger line from b' use ustodes.vaticana.d1 (long stem
> down)
> >
> > 4/ Notes in between the ledger from b' use custodes.vaticana.d0 (short
> stem down)
> >
> >
> > And this should work regardless of the key signature of the piece (since
> things might get transposed).
> >
> >
> > May I get some pointers of how the logic might be coded up?
> >
> >
> > Here is what I have so far, with help from this list, and taken from
> >
> >
> https://lilypond.org/doc/v2.20/Documentation/notation/substitution-function-examples
> >
> >
> > addCustos =
> >
> > #(define-music-function (noteList)
> >
> > (ly:music?)
> >
> > #{
> >
> > \tweak NoteHead.stencil #ly:text-interface::print
> >
> > \tweak NoteHead.font-size #3
> >
> > \tweak NoteHead.text \markup {
> >
> > \musicglyph "custodes.vaticana.u1"
> >
> > }
> >
> > \tweak Stem.stencil ##f
> >
> > $(first (music-pitches noteList)) 4
> >
> > #}
> >
> > )
> >
> >
> >
> > Many thanks,
> > mattfong
>
> Hi,
>
> not sure I correctly understood your conditions...
> Maybe below?
>
> addCustos =
> #(define-music-function (noteList) (ly:music?)
>   #{
>     \once \override NoteHead.stencil =
>       #(lambda (grob)
>          (let* ((style (ly:grob-property grob 'style 'vaticana))
>                 (staff-pos (ly:grob-property grob 'staff-position))
>                 (glyph
>                   (format #f "custodes.~a.~a~a"
>                     style
>                     (if (negative? staff-pos) "u" "d")
>                     (if (even? (abs staff-pos)) 0 1))))
>            (grob-interpret-markup grob
>              (make-musicglyph-markup glyph))))
>
>     \once \override Stem.stencil = ##f
>     \once \override Flag.stencil = ##f
>     \once \override Dots.stencil = ##f
>     $(first (music-pitches noteList)) 4
>   #})
>
>
> mus =
> \relative {
>   a4 b c d e f g a b c d e f g a b c
> }
>
> \new Staff
>   \with { instrumentName = "Test" }
>   $(make-sequential-music
>     (map addCustos (extract-named-music mus 'NoteEvent)))
>
> \relative {
>   a4 b c d e f \addCustos g g a b c d e f g a b c
> }
>
> Cheers,
>   Harm
>

Reply via email to