Thanks a lot Valentin, that's simply perfect!

However, after reading a lot of the documentation I think I would have
never been able to find any solution close to yours. I am very confused
with a few things, and I can't find the answers in the documentation. Let
me ask you a few questions in hope that I will be able to solve problems on
my own next time.

   - How did you know you could pass a function that receives a grob to
   KeySignature.key?
   - If an overriden property expects a number, can it be defined as a
   function that receives a grob and returns a number?
   - How did you know alterations-alist is a property of that grob?
   - What is #:vcenter and how did you know of its existence?

Thank you again,
Robert

El lun, 2 oct 2023 a las 15:00, Valentin Petzel (<valen...@petzel.at>)
escribió:

> Hi Robert,
>
> you could do it like this:
>
> \version "2.23.6"
>
> \layout {
>   \context {
>     \Staff
>     \override KeySignature.text =
>     #(lambda (grob)
>        (let* ((alt (ly:grob-property grob 'alteration-alist))
>               (alts (map cdr alt))
>               (tot (* 2 (apply + alts)))
>               (acc (cond ((= tot 0) (markup #:musicglyph
> "accidentals.natural"))
>                          ((> tot 0) (markup #:musicglyph
> "accidentals.sharp"))
>                          (else (markup #:vcenter #:musicglyph
> "accidentals.flat")))))
>          (markup #:vcenter #:number (number->string (abs tot)) acc)))
>     \override KeySignature.stencil = #ly:text-interface::print
>     printKeyCancellation = ##f
>   }
> }
>
> expt = { \key c \major c d e f }
>
> {
>   \clef bass
>   \expt
>   \transpose c cis \expt
>   \transpose c des \expt
>   \transpose c d \expt
>   \transpose c dis \expt
>   \transpose c es \expt
>   \transpose c e \expt
>   \transpose c f \expt
>   \transpose c fis \expt
>   \transpose c ges \expt
>   \transpose c g \expt
>   \transpose c gis \expt
>   \transpose c as \expt
>   \transpose c a \expt
>   \transpose c ais \expt
>   \transpose c bes \expt
>   \transpose c b \expt
> }
>
> Cheers,
> Valentin
>
> Am Montag, 2. Oktober 2023, 14:21:37 CEST schrieb Robert Mengual:
> > Hi, I am trying to overwrite the key signature for my custom music
> notation
> > so that instead of displaying the sharp and flat icons, it shows a given
> > number and the alteration. So, for example, E Major would show 4# instead
> > of ####.
> >
> > I have been able to get the desired output by hardcodeing it using the
> > markup function. However, I am not finding a way to conditionally render
> > the number and alteration depending on the key. Could somebody help me?
> >
> > Here is my tiny hardcoded example, with a screenshot:
> >
> > [image: image.png]
> >
> > \version "2.23.6"
> >
> > \layout {
> > \context {
> > \Staff
> > \override KeySignature.stencil = #ly:text-interface::print
> > \override KeySignature.text = \markup {
> > \combine
> > \halign #-1 \lower #1 \musicglyph "four"
> > \halign #-5 \musicglyph "accidentals.sharp"
> > }
> > }
> > }
> >
> > \relative {
> > \clef bass
> > \key e \major
> > cis dis e
> > }
>
>

Reply via email to