Hi David,
On Sun, Sep 3, 2017 at 12:51 AM, David F. <[email protected]> wrote:
> That is great! Just what I was looking for.
>
> Your patch isn’t extracting the tonic—it always returns ‘C’. But I always
> explicitly define the key, so your original code works like a charm.
Oops.
In any case, all you'd have to do is modify the function like so:
#(define-markup-command (firstNoteAndKey layout props mus)
(ly:music?)
(let* ((keey (extract-named-music mus 'KeyChangeEvent))
(tonic
(if (pair? keey)
[...snip...]
>
> Thanks!
>
> David
>
> On Sep 2, 2017, at 7:25 AM, David Nalesnik <[email protected]> wrote:
>
>> On Sat, Sep 2, 2017 at 8:09 AM, David Nalesnik <[email protected]>
>> wrote:
>>> 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.
>>>
>>
>> The original code will break if there's no explicit key set.
>>
>> Patch:
>>
>> #(define-markup-command (firstNoteAndKey layout props mus)
>> (ly:music?)
>> (let* ((keey (extract-named-music mus 'KeyChangeEvent))
>> (tonic
>> (if (ly:music? keey)
>> (ly:music-property (car keey) 'tonic)
>> (ly:make-pitch 0 0)))
>> (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))))))
>
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user