Hi Urs,
On Mon, Feb 3, 2014 at 3:16 AM, Urs Liska <u...@openlilylib.org> wrote: > Hi, > > searching the docs and the lilypond-user archive I couldn't find any > relevant information. > > I am looking for a custom \accidentalStyle. Actually I think this is quite > commonly used, so it would also seem like a useful addition to LilyPond > proper. > > a) > Every note gets an explicit accidental (including a natural), > as in the 'dodecaphonic style, > _except_ when a note is repeated immediately in the same voice. > I've seen it too, and I think it would be good to include it. > > When looking into music-functions.scm and its set-accidental-style I see > > ((equal? style 'dodecaphonic) > (set-accidentals-properties #f > `(Staff ,(lambda (c p bn mp) '(#f . #t))) > '() > context)) > > > So it seems the way to go to make a copy of that definition (e.g. with > comparing against 'dodecaphonic-no-repeat) and modifying the definition. > Yes. That's what I do in the attached file. > > Unfortunately I don't have a clue how to proceed. Any trials are simply > anwered by errors, so I'd prefer not to _try_ but to do at least _informed > guesses_ ;-) > > I assume that the > `(Staff > expression returns the > context pitch barnumber measureposition > arguments for > set-accidental-properties > so this seems the place to define the right arguments. > > Unfortunately I haven't _fully_ understood lambda expressions and _barely_ > understood quoting and unquoting. > > So I'd be glad about hints/explanations/solutions to > > a) > create a differing but valid argument list at all and > b) > determining which '(#f . #t) combinations to use for my purpose. > > I confess that I find what goes on in the source a bit confusing, but I did come up with something that appears to work. I make no claims about having done this the right way :) First of all, I looked at clauses other than that for dodecaphonic for inspiration, since that one is only good for hit-it-with-a-hammer situations, and you need some refinement here. You definitely want the initial #f which prevents old-style cancellations--the extra natural when flat follows double-flat, but you need some variability in your setting of the cdr--that is, auto-accidentals. I used neo-modern as a starting point, and wrote a 'dodecaphonic-no-repeat-rule'. I had to copy other functions from scm/music-functions.scm since they're not define-public. The file includes the demonstration example from the NR. --David
\version "2.18.0" %% LOCAL FUNCTIONS FROM scm/music-functions.scm #(define (key-entry-notename entry) "Return the pitch of an @var{entry} in @code{localKeySignature}. The @samp{car} of the entry is either of the form @code{notename} or of the form @code{(octave . notename)}. The latter form is used for special key signatures or to indicate an explicit accidental. The @samp{cdr} of the entry is either a rational @code{alter} indicating a key signature alteration, or of the form @code{(alter . (barnum . measurepos))} indicating an alteration caused by an accidental in music." (if (pair? (car entry)) (cdar entry) (car entry))) #(define (key-entry-octave entry) "Return the octave of an entry in @code{localKeySignature} or @code{#f} if the entry does not have an octave. See @code{key-entry-notename} for details." (and (pair? (car entry)) (caar entry))) #(define (key-entry-bar-number entry) "Return the bar number of an entry in @code{localKeySignature} or @code {#f} if the entry does not have a bar number. See @code{key-entry-notename} for details." (and (pair? (cdr entry)) (caddr entry))) #(define (key-entry-measure-position entry) "Return the measure position of an entry in @code{localKeySignature} or @code {#f} if the entry does not have a measure position. See @code{key-entry-notename} for details." (and (pair? (cdr entry)) (cdddr entry))) %%%%%%%%%%%%%%% END COPIED STUFF %%%%%%%%%%%%%%%% %% BASED on 'neo-modern-accidental-rule' %% #(define-public (dodecaphonic-no-repeat-rule context pitch barnum measurepos) (let* ((keysig (ly:context-property context 'localKeySignature)) (entry (find-pitch-entry keysig pitch #t #t))) (if (not entry) (cons #f #t) (let* ((entrymp (key-entry-measure-position entry)) (entrybn (key-entry-bar-number entry))) (cons #f (not (and (equal? entrybn barnum) (equal? entrymp measurepos)))))))) %% FROM scm/music-functions.scm with another style added %% #(define-public (set-accidental-style style . rest) "Set accidental style to @var{style}. Optionally take a context argument, e.g. @code{'Staff} or @code{'Voice}. The context defaults to @code{Staff}, except for piano styles, which use @code{GrandStaff} as a context." (let ((context (if (pair? rest) (car rest) 'Staff)) (pcontext (if (pair? rest) (car rest) 'GrandStaff))) (cond ;; accidentals as they were common in the 18th century. ((equal? style 'default) (set-accidentals-properties #t `(Staff ,(make-accidental-rule 'same-octave 0)) '() context)) ;; accidentals from one voice do NOT get canceled in other voices ((equal? style 'voice) (set-accidentals-properties #t `(Voice ,(make-accidental-rule 'same-octave 0)) '() context)) ;; accidentals as suggested by Kurt Stone, Music Notation in the 20th century. ;; This includes all the default accidentals, but accidentals also needs canceling ;; in other octaves and in the next measure. ((equal? style 'modern) (set-accidentals-properties #f `(Staff ,(make-accidental-rule 'same-octave 0) ,(make-accidental-rule 'any-octave 0) ,(make-accidental-rule 'same-octave 1)) '() context)) ;; the accidentals that Stone adds to the old standard as cautionaries ((equal? style 'modern-cautionary) (set-accidentals-properties #f `(Staff ,(make-accidental-rule 'same-octave 0)) `(Staff ,(make-accidental-rule 'any-octave 0) ,(make-accidental-rule 'same-octave 1)) context)) ;; same as modern, but accidentals different from the key signature are always ;; typeset - unless they directly follow a note of the same pitch. ((equal? style 'neo-modern) (set-accidentals-properties #f `(Staff ,(make-accidental-rule 'same-octave 0) ,(make-accidental-rule 'any-octave 0) ,(make-accidental-rule 'same-octave 1) ,neo-modern-accidental-rule) '() context)) ((equal? style 'neo-modern-cautionary) (set-accidentals-properties #f `(Staff ,(make-accidental-rule 'same-octave 0)) `(Staff ,(make-accidental-rule 'any-octave 0) ,(make-accidental-rule 'same-octave 1) ,neo-modern-accidental-rule) context)) ((equal? style 'neo-modern-voice) (set-accidentals-properties #f `(Voice ,(make-accidental-rule 'same-octave 0) ,(make-accidental-rule 'any-octave 0) ,(make-accidental-rule 'same-octave 1) ,neo-modern-accidental-rule Staff ,(make-accidental-rule 'same-octave 0) ,(make-accidental-rule 'any-octave 0) ,(make-accidental-rule 'same-octave 1) ,neo-modern-accidental-rule) '() context)) ((equal? style 'neo-modern-voice-cautionary) (set-accidentals-properties #f `(Voice ,(make-accidental-rule 'same-octave 0)) `(Voice ,(make-accidental-rule 'any-octave 0) ,(make-accidental-rule 'same-octave 1) ,neo-modern-accidental-rule Staff ,(make-accidental-rule 'same-octave 0) ,(make-accidental-rule 'any-octave 0) ,(make-accidental-rule 'same-octave 1) ,neo-modern-accidental-rule) context)) ;; Accidentals as they were common in dodecaphonic music with no tonality. ;; Each note gets one accidental. ((equal? style 'dodecaphonic) (set-accidentals-properties #f `(Staff ,(lambda (c p bn mp) '(#f . #t))) '() context)) ;; Multivoice accidentals to be read both by musicians playing one voice ;; and musicians playing all voices. ;; Accidentals are typeset for each voice, but they ARE canceled across voices. ((equal? style 'modern-voice) (set-accidentals-properties #f `(Voice ,(make-accidental-rule 'same-octave 0) ,(make-accidental-rule 'any-octave 0) ,(make-accidental-rule 'same-octave 1) Staff ,(make-accidental-rule 'same-octave 0) ,(make-accidental-rule 'any-octave 0) ,(make-accidental-rule 'same-octave 1)) '() context)) ;; same as modernVoiceAccidental eccept that all special accidentals are typeset ;; as cautionaries ((equal? style 'modern-voice-cautionary) (set-accidentals-properties #f `(Voice ,(make-accidental-rule 'same-octave 0)) `(Voice ,(make-accidental-rule 'any-octave 0) ,(make-accidental-rule 'same-octave 1) Staff ,(make-accidental-rule 'same-octave 0) ,(make-accidental-rule 'any-octave 0) ,(make-accidental-rule 'same-octave 1)) context)) ;; stone's suggestions for accidentals on grand staff. ;; Accidentals are canceled across the staves in the same grand staff as well ((equal? style 'piano) (set-accidentals-properties #f `(Staff ,(make-accidental-rule 'same-octave 0) ,(make-accidental-rule 'any-octave 0) ,(make-accidental-rule 'same-octave 1) GrandStaff ,(make-accidental-rule 'any-octave 0) ,(make-accidental-rule 'same-octave 1)) '() pcontext)) ((equal? style 'piano-cautionary) (set-accidentals-properties #f `(Staff ,(make-accidental-rule 'same-octave 0)) `(Staff ,(make-accidental-rule 'any-octave 0) ,(make-accidental-rule 'same-octave 1) GrandStaff ,(make-accidental-rule 'any-octave 0) ,(make-accidental-rule 'same-octave 1)) pcontext)) ;; same as modern, but cautionary accidentals are printed for all sharp or flat ;; tones specified by the key signature. ((equal? style 'teaching) (set-accidentals-properties #f `(Staff ,(make-accidental-rule 'same-octave 0)) `(Staff ,(make-accidental-rule 'same-octave 1) ,teaching-accidental-rule) context)) ;; do not set localKeySignature when a note alterated differently from ;; localKeySignature is found. ;; Causes accidentals to be printed at every note instead of ;; remembered for the duration of a measure. ;; accidentals not being remembered, causing accidentals always to ;; be typeset relative to the time signature ((equal? style 'forget) (set-accidentals-properties '() `(Staff ,(make-accidental-rule 'same-octave -1)) '() context)) ;; Do not reset the key at the start of a measure. Accidentals will be ;; printed only once and are in effect until overridden, possibly many ;; measures later. ((equal? style 'no-reset) (set-accidentals-properties '() `(Staff ,(make-accidental-rule 'same-octave #t)) '() context)) ;; ADDITION ((equal? style 'dodecaphonic-no-repeat) (set-accidentals-properties #f `(Staff ,(make-accidental-rule 'same-octave 0) ,dodecaphonic-no-repeat-rule) '() context)) ;; END ADDITION (else (ly:warning (_ "unknown accidental style: ~S") style) (make-sequential-music '()))))) %%%%%%%%%%%%%%%%%%%%%%%%% EXAMPLES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% { \accidentalStyle dodecaphonic-no-repeat cis'8 fis' c' c' c' } musicA = { << \relative c' { cis'8 fis, bes4 <a cis>8 f bis4 | cis2. <c, g'>4 | } \\ \relative c' { ais'2 cis, | fis8 b a4 cis2 | } >> } musicB = { \clef bass \new Voice { \voiceTwo \relative c' { <fis, a cis>8[ <fis a cis> \change Staff = up cis' cis \change Staff = down <fis, a> <fis a>] \showStaffSwitch \change Staff = up dis'4 | \change Staff = down <fis, a cis>4 gis <f a d>2 | } } } %%{ \new PianoStaff { << \context Staff = "up" { \accidentalStyle dodecaphonic-no-repeat \musicA } \context Staff = "down" { \accidentalStyle dodecaphonic-no-repeat \musicB } >> } %}
_______________________________________________ bug-lilypond mailing list bug-lilypond@gnu.org https://lists.gnu.org/mailman/listinfo/bug-lilypond