lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Generating pitches depending on key signature


From: Lukas-Fabian Moser
Subject: Generating pitches depending on key signature
Date: Sat, 28 Apr 2018 11:16:11 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

Folks,

Assume I want a function that adds a second note a fifth a bove a given pitch (of course this is but an abstraction from a more complicated project).

The difficulty is that this should behave accoding to the key signature in place. Hence, the fifth should not be always perfect but instead be whatever occurs in the active key four note steps above the given pitch. (Quite as in figured bass accompaniment.) Hence:

\version "2.19.80"

addFifth = #(define-music-function (pitch dur) (ly:pitch? ly:duration?)
              (let*
               ((delta (+ 4 (ly:pitch-steps pitch)))
                (new-pitch (ly:make-pitch 0 delta 0))
                (pitches (list pitch new-pitch) )
                (chordNotes (map (lambda (p) (make-music
                                              'NoteEvent
                                              'duration dur
                                              'pitch p))
                              pitches))
                )
               #{
                 #(make-music 'EventChord 'elements chordNotes)
               #}
               )
              )

{
  \addFifth c' 1  % should yield <c g> -> ok
  \addFifth cis' 1    % should yield <cis g> -> ok
  \key a \major
  \addFifth c' 1   % should yield <c gis> -> NOT OK
  \addFifth cis' 1  % should yield <cis gis> -> NOT OK
}

I expect that this amounts to taking the alteration of my new-pitch from the alteration-alist that is "active". But from what I can gather from old postings on -user, this information seems not to be available at the time a music function is called (correct?). What would be the way to go for this?


Best
Lukas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]