Re: Overwrite key signature with numbers
Alright, thanks for your time. I really appreciate it. Robert El vie, 13 oct 2023 18:41, Jean Abou Samra escribió: > From what you say, I believe you are worried about chords, am I right? > > > > It's more fundamental than that: there is only *one* StaffSymbol per > staff, for the duration of the *entire* score. That StaffSymbol has a > ledger-extra property that applies to *all* ledger lines on that staff > anywhere in the score. There is no built-in way to have different > ledger-extra values for different moments of the score since all ledger > lines from the same staff use the same ledger-extra value. (Making > ledger-extra computed by a callback doesn't change anything to that, it's > still one value.) > > >
Re: Overwrite key signature with numbers
> From what you say, I believe you are worried about chords, am I right? It's more fundamental than that: there is only *one* StaffSymbol per staff, for the duration of the *entire* score. That StaffSymbol has a ledger-extra property that applies to *all* ledger lines on that staff anywhere in the score. There is no built-in way to have different ledger-extra values for different moments of the score since all ledger lines from the same staff use the same ledger-extra value. (Making ledger-extra computed by a callback doesn't change anything to that, it's still one value.) signature.asc Description: This is a digitally signed message part
Re: Overwrite key signature with numbers
Thanks for your response Jean, So, the music notation system I am writing has assimetrical staves with only 4 lines, which means there is a blank space wider than the other two white spaces. For notes that fall into the wider blank space, I want a ledger line value of 2, but for the note that falls into the narrower blank space (G) I want a ledger line value of 1. From what you say, I believe you are worried about chords, am I right? In that case it would depend on whether the highest note is a G if it is above the staff or if the lowest is a G if it is below the staff. Robert El vie, 13 oct 2023 a las 16:38, Jean Abou Samra () escribió: > Le vendredi 13 octobre 2023 à 15:36 +0200, Robert Mengual a écrit : > > In the example below, I am receiving the following error: Wrong type > argument in position 1 (expecting Stream_event): #f > > I think I am not receiving a grob in this case. > > > > You are, but this grob doesn't have an event cause. The event-cause > function returns either a stream event, or #f if the grob doesn't have a > stream event cause (the boolean false, #f, is traditionally used in Scheme > for missing values, where many other languages would use some value called > null, nil, None, undefined, ...). > > How could I move forward with this? The use case is very simple, if the > note is a G I want to return a 1 and if not I want to return a 2. > > > > I don't really understand what you're trying to do. A StaffSymbol spans > the whole score. What do you do if there are both G notes and other notes? > > Do you want to adjust ledger lines locally, for each note? This is rather > complicated to do, though there are hacks for that. >
Re: Overwrite key signature with numbers
Le vendredi 13 octobre 2023 à 15:36 +0200, Robert Mengual a écrit : > In the example below, I am receiving the following error: Wrong type argument > in position 1 (expecting Stream_event): #f > > I think I am not receiving a grob in this case. You are, but this grob doesn't have an event cause. The event-cause function returns either a stream event, or #f if the grob doesn't have a stream event cause (the boolean false, #f, is traditionally used in Scheme for missing values, where many other languages would use some value called null, nil, None, undefined, ...). > How could I move forward with this? The use case is very simple, if the note > is a G I want to return a 1 and if not I want to return a 2. I don't really understand what you're trying to do. A StaffSymbol spans the whole score. What do you do if there are both G notes and other notes? Do you want to adjust ledger lines locally, for each note? This is rather complicated to do, though there are hacks for that. signature.asc Description: This is a digitally signed message part
Re: Overwrite key signature with numbers
Thank you again Valentin, this is extremely helpful for me. In fact, I have been able to override other properties based on the solution you provided. I'm slowly making progress. However there is something I am stuck with, based on your response above: > If an overriden property expects a number, can it be defined as > a function that receives a grob and returns a number? Exactly. In the example below, I am receiving the following error: Wrong type argument in position 1 (expecting Stream_event): #f I think I am not receiving a grob in this case. How could I move forward with this? The use case is very simple, if the note is a G I want to return a 1 and if not I want to return a 2. \version "2.23.6" #(define my-desperate-test (lambda (grob) (let ((note (ly:event-property (event-cause grob) 'pitch))) 2 ))) \layout { \context { \Staff \override StaffSymbol.ledger-extra = #my-desperate-test } } El mar, 3 oct 2023 a las 14:11, Valentin Petzel () escribió: > Am Dienstag, 3. Oktober 2023, 12:55:21 CEST schrieb Robert Mengual: > > > 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. > > Hello Robert, > > I do understand that getting into details for a oftware like lilypond can > be a bit hard. Since it is a small open source project it is not perfectly > documented in each regard, especially once you start to go into extending > it. I’d recommend reading Jean’s introduction into extending lilypond: > > https://extending-lilypond.gitlab.io/ > > Once you’ve seen these things a few times it will become a lot easier (I > did take some time to get where I am now, and it would have been much less > if I had something like Jean’s guide). > > >- How did you know you could pass a function that receives a grob to > > >KeySignature.key? > > (Raw) grob properties can be either values or callbacks, which are > functions that take the grob itself as argument (these are automatically > evaluated when getting the property). You doing > > \override KeySignature.stencil = #ly:text-interface::print > > is assingning a function to the stencil property. > > >- If an overriden property expects a number, can it be defined as a > > >function that receives a grob and returns a number? > > Exactly. > > >- How did you know alterations-alist is a property of that grob? > > > https://lilypond.org/doc/v2.24/Documentation/internals/key_002dsignature_002dinterface > > >- What is #:vcenter and how did you know of its existence? > > markup command for vertically centering stuff (relative to itself), see > here: > > https://lilypond.org/doc/v2.24/Documentation/notation/align > > Using this the number will not extend from the middle line upward, but be > centered around the middle line. > > Cheers, > > Valentin >
Re: Overwrite key signature with numbers
Valentin Petzel writes: > Damn it, turns out the key engraver has an hardcoded path to always create > Key > Cancellations for keys with no alteration. > > So one would need to do > > \override KeyCancellation.stencil = ##f > > which is of course a bit wonky as compared to telling Lilypond to not create > Cancellations in the first place (not that it matters), which is why I went > extra mile to use > > printKeyCancellation = ##f > > Well, thank you for pointing it out! If you want to go the extra mile, you'd only print ♮ in key cancellation messages grobs and would precede them with the _previous_ number of sharps/flats. So switching from E major to B♭ major would print 4♮2♭. You would not get 0♮ however (not as a main signature, not as a cancellation signature). This may or may not be what the OP wants. But it would be one semi-consistent way of doing this. -- David Kastrup
Re: Overwrite key signature with numbers
Oh David's right, if the music ends with no alterations it is printing the key cancellation, even when it has been explicitely set to false.[image: image.png] What can I do in this case? I would like to keep the number+alteration but remove the 7 natural signs before that. Thank you, Robert El lun, 2 oct 2023 a las 15:41, David Kastrup () escribió: > Valentin Petzel writes: > > > 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 > > To pour some rain on your parade, end the music with a final \expt ... > My revenge for you beating me to the punch line. > > -- > David Kastrup >
Re: Overwrite key signature with numbers
Am Dienstag, 3. Oktober 2023, 12:55:21 CEST schrieb Robert Mengual: > 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. Hello Robert, I do understand that getting into details for a oftware like lilypond can be a bit hard. Since it is a small open source project it is not perfectly documented in each regard, especially once you start to go into extending it. I’d recommend reading Jean’s introduction into extending lilypond: https://extending-lilypond.gitlab.io/[1] Once you’ve seen these things a few times it will become a lot easier (I did take some time to get where I am now, and it would have been much less if I had something like Jean’s guide). >- How did you know you could pass a function that receives a grob to >KeySignature.key? (Raw) grob properties can be either values or callbacks, which are functions that take the grob itself as argument (these are automatically evaluated when getting the property). You doing \override KeySignature.stencil = #ly:text-interface::print is assingning a function to the stencil property. >- If an overriden property expects a number, can it be defined as a >function that receives a grob and returns a number? Exactly. >- How did you know alterations-alist is a property of that grob? https://lilypond.org/doc/v2.24/Documentation/internals/ key_002dsignature_002dinterface[2] >- What is #:vcenter and how did you know of its existence? markup command for vertically centering stuff (relative to itself), see here: https://lilypond.org/doc/v2.24/Documentation/notation/align[3] Using this the number will not extend from the middle line upward, but be centered around the middle line. Cheers, Valentin [1] https://extending-lilypond.gitlab.io/ [2] https://lilypond.org/doc/v2.24/Documentation/internals/ key_002dsignature_002dinterface [3] https://lilypond.org/doc/v2.24/Documentation/notation/align signature.asc Description: This is a digitally signed message part.
Re: Overwrite key signature with numbers
Damn it, turns out the key engraver has an hardcoded path to always create Key Cancellations for keys with no alteration. So one would need to do \override KeyCancellation.stencil = ##f which is of course a bit wonky as compared to telling Lilypond to not create Cancellations in the first place (not that it matters), which is why I went extra mile to use printKeyCancellation = ##f Well, thank you for pointing it out! Cheers, Valentin > To pour some rain on your parade, end the music with a final \expt ... > My revenge for you beating me to the punch line. signature.asc Description: This is a digitally signed message part.
Re: Overwrite key signature with numbers
Robert Mengual writes: > Oh David's right, if the music ends with no alterations it is printing the > key cancellation, even when it has been explicitely set to false.[image: > image.png] > What can I do in this case? I would like to keep the number+alteration but > remove the 7 natural signs before that. Just add \omit KeyCancellation into the context amendment for \Staff in the \layout block. -- David Kastrup
Re: Overwrite key signature with numbers
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 () 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 > > } > >
Re: Overwrite key signature with numbers
Valentin Petzel writes: > 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 To pour some rain on your parade, end the music with a final \expt ... My revenge for you beating me to the punch line. -- David Kastrup
Re: Overwrite key signature with numbers
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 > } signature.asc Description: This is a digitally signed message part.
Overwrite key signature with numbers
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 }