[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Show Key name and first note of song?
From: |
David F. |
Subject: |
Re: Show Key name and first note of song? |
Date: |
Sat, 2 Sep 2017 23:51:01 -0600 |
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.
Thanks!
David
On Sep 2, 2017, at 7:25 AM, David Nalesnik <address@hidden> wrote:
> On Sat, Sep 2, 2017 at 8:09 AM, David Nalesnik <address@hidden> wrote:
>> Hi David,
>>
>> On Sat, Sep 2, 2017 at 12:25 AM, David F. <address@hidden> 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))))))