lilypond-user
[Top][All Lists]
Advanced

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

Re: Notes in Key Sig


From: Nicolas Sceaux
Subject: Re: Notes in Key Sig
Date: Sun, 24 Apr 2005 15:59:24 +0200
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

Erik Sandberg <address@hidden> writes:

> Maybe this is something for LSR?

Unfortunately, I cannot, as it does not compile for 2.4.4.


Title:
Entering notes without the chromatic signs specified in the key
signature

Description:
This \autoAlteration music function makes it possible to avoid
entering alterations for notes which alteration is specified in the
key signature. For instance, in A major, c, f and g will be sharped
without having to write cis, fis or gis. To force a natural alteration
on such a note, use `!'. 

Note that this is certainly not a good idea, as it breaks a LilyPond
idiom. However, this snippet may have an educative value, as it
demonstrates how to apply a function on some music elements, using
`music-map'.

Snippet:
\version "2.5.20"

autoAlteration = #(def-music-function (parser location key music) (ly:music? 
ly:music?)
                    (let ((pitch-alist (ly:music-property (car 
(ly:music-property key 'elements))
                                                          'pitch-alist)))
                      (music-map (lambda (m)
                                   ;; If the music is a NoteEvent, we change 
its alteration,
                                   ;; unless its accidental is forced
                                   (let ((this-pitch (ly:music-property m 
'pitch)))
                                     (if (eqv? 'NoteEvent (ly:music-property m 
'name))
                                         (cond (;; if ! is found, we remove it 
and leave the alteration untouched
                                                (and (not (null? 
(ly:music-property m 'force-accidental)))
                                                     (ly:music-property m 
'force-accidental)
                                                     (= 0 (ly:pitch-alteration 
this-pitch)))
                                                (set! (ly:music-property m 
'force-accidental) #f))
                                               (;; if the alteration is 0, then 
we change it according to pitch-alist
                                                (zero? (ly:pitch-alteration 
this-pitch))
                                                (set! (ly:music-property m 
'pitch)
                                                      (ly:make-pitch 
(ly:pitch-octave this-pitch)
                                                                     
(ly:pitch-notename this-pitch)
                                                                     (cdr 
(assoc (ly:pitch-notename this-pitch) pitch-alist))))))))
                                   m)
                                 music)
                      music))

\autoAlteration \key a \major {
  a b c' d' e' f' g' a'
  a b c' d' ees' f' g'! a'
}




reply via email to

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