Hi David,
On Sat, Sep 2, 2017 at 12:25 AM, David F. <[email protected]> wrote:
> I have a hymnal that prints the name of the key and the first note the song
> above the treble clef sign of the first staff. So, for example, if you have
> Amazing Grace in the key of G major, the first note of the soprano (melody)
> part is a D. That is printed as “G/D”.
>
> Can lilypond do that? I thought I had seen an example of that somewhere, but
> I can’t find it now.
>
I don't know where you saw this on the lists, but attached you'll find
a solution.
I wrote a markup command which takes a music expression and finds the
relevant information. In the example, I show two ways of using it, as
a top-level-markup and as a mark. (The mark will have better
alignment possibilities. It's not hard to get it over the treble
clef, for example.)
Hope this helps!
David N.
P. S. It's probably possible to write an engraver for this.
P. P. S. I avoided the function note-name->markup because I don't
like the gap it creates between note name and accidental. My code
could use some height adjustment for accidentals, though.
\version "2.18.2"
% Probably better as a vector lookup
#(define letter-names '("C" "D" "E" "F" "G" "A" "B"))
#(define alteration-symbols
`(
(-1/2 . ,(make-flat-markup))
(0 . ,(make-null-markup))
(1/2 . ,(make-sharp-markup))
))
#(define (format-key p)
(let* (;(p (ly:music-property ne 'pitch))
(nn (ly:pitch-notename p))
(alt (ly:pitch-alteration p))
(letter (list-ref letter-names nn))
(alteration (ly:assoc-get alt alteration-symbols)))
#{
\markup \concat {
#letter #alteration
}
#}))
#(define-markup-command (firstNoteAndKey layout props mus)
(ly:music?)
(let* ((keey (extract-named-music mus 'KeyChangeEvent))
(tonic (ly:music-property (car keey) 'tonic))
(notes (extract-named-music mus 'NoteEvent))
(first-ne (car notes))
(first-pitch (ly:music-property first-ne 'pitch)))
(interpret-markup layout props
(make-concat-markup
(list
(format-key first-pitch)
"/"
(format-key tonic))))))
amazingGrace = \relative c' {
\key g \major
\time 3/4
\partial 4 d4
g2 b8 g
b2 a4
g2 e4
d2
}
\markup \bold \firstNoteAndKey #amazingGrace
{
\amazingGrace
}
{
\override Score.RehearsalMark.break-align-symbols =
#'(clef staff-bar key-signature)
% CENTER doesn't center over clef?!
\once \override Score.RehearsalMark.self-alignment-X = #0.5
\mark \markup \firstNoteAndKey #amazingGrace
\amazingGrace
}
\paper {
indent = 0
}_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user