After a small bugfix in the accidental engraver (1.7 cvs), this hack
does more or less what you request.
The last measure shows an example where it goes wrong. Problem is that
the music is parsed "in input order" - so the 2nd e gets an accidental
because the 1st was not entered yet, whereas the first does not get an
accidental because it is defined right after the 2nd. But if you use
simple constructs then it should work... Hmmm... Otherwise then speak
up.

-Rune
\version "1.7.6"

#(define usep '())
#(define buildp '()) 
#(define ((schoenberg-accidentals clear) music)
  (let* ((es (ly:get-mus-property music 'elements))
         (e (ly:get-mus-property music 'element))
         (p  (ly:get-mus-property music 'pitch))
         (ts  (ly:get-mus-property music 'types)))

    (if (memq 'note-event ts) 
        (begin
          (set! buildp (cons p buildp))
          (if (not (member p usep))
              (ly:set-mus-property! music 'force-accidental #t))))

    (if (ly:music? e)
        (ly:set-mus-property!
         music 'element
         ((schoenberg-accidentals clear) e)))

    (if (pair? es)
        (ly:set-mus-property!
         music 'elements
         (map (schoenberg-accidentals (memq 'sequential-music ts)) es)))

    (if clear (begin (set! usep buildp) (set! buildp '())))

    music))

music = \notes \transpose c c' { c d d e <a c' e'> <a c' e'> <a c' d' f'> <a c' e'> < 
{ c c d d } { a a b a } > | < { c'2 e' } { e' g'} > }

\score {
  \apply #(schoenberg-accidentals #t)
  {
      \property Score.autoAccidentals = \turnOff
      \music
  }
  \paper { linewidth = -1. }
}

Reply via email to