Re: Define custom/new \accidentalStyles (dodecaphonic minus repeated notes)

2014-02-10 Thread Paul Morris
David Nalesnik-2 wrote
 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.  

Nice work!  It was interesting to see how you did this and how things work
internally on this.  It helped me improve some accidental tweaking code that
I use.  Thanks!

-Paul



--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/Define-custom-new-accidentalStyles-dodecaphonic-minus-repeated-notes-tp158770p159105.html
Sent from the User mailing list archive at Nabble.com.

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Define custom/new \accidentalStyles (dodecaphonic minus repeated notes)

2014-02-09 Thread David Nalesnik
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