lilypond-user
[Top][All Lists]
Advanced

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

Re: Function or command to omit only certain accidentals of a chord?


From: Stefano Troncaro
Subject: Re: Function or command to omit only certain accidentals of a chord?
Date: Sat, 3 Feb 2018 11:44:29 -0300

Hi Thomas, thank you for your corrections!

If I may ask, where are functions like event-chord-pitches documented? I have only found a list of functions with their name starting with "ly:". I assumed those were named that way to differentiate Lilypond exclusive functions from Scheme's own, but it is evident that is not the case.

Now that I've touched on this subject I guess I'll take the opportunity to ask about the following. I have a lot of trouble understanding how things are related to each other by their naming. As an example, I find very confusing that ly:music? accepts chords and sequences of notes (or one-note chords and one-note sequences) but not single notes, even when examining the scheme representation of a single note with \displayMusic portrays it as "(make-music 'NoteEvent ... )". Searching through the (uncategorized) list of Scheme functions in the documentation for anything whose name ends with the character "?" I find ly:event? and, since I was trying to write a function that accepted both NoteEvent and EventChord, I try that one out. But it turns out it's for other things (I'm not even sure what). And fortunately I already had an example that showed that single notes go with ly:pitch? because I don't know how I would have found about that otherwise.

What can I read to learn about these things instead of having to waste time and energy like this? Because right now, to an uneducated reader like me, it feels like trying to find the piece that goes into the triangle-shaped socket by trial and error instead of by picking the triangle-shaped piece, only that the triangle shaped-piece in reality goes into the square-shaped socket for some unapparent reason.


Thank you again for all your help,
Stéfano

2018-02-03 8:52 GMT-03:00 Thomas Morley <address@hidden>:
2018-02-03 3:52 GMT+01:00 Stefano Troncaro <address@hidden>:

> After a lot of stumbling around I finally managed to expand Jan-Peters'
> function so that it can modify more than one note in a given chord. I
> attached it so its available for anyone interested in using it.

Hi Stefano,

I had a look at the function, some remarks.
(1)
We have `event-chord-pitches' to extract pitches from an event-chord.
It works for sequential-music as well.
If you go for ly:music? and extract pitches you can delete some definitions.
Ofcourse you can't go for a single target-pitch anymore. Instead you
would need to do <single-pitch> or { single-pitch }.
I don't see a problem with it, though
(2)
No point in using map and throwing the resulting list away.
Use for-each if you're only interested in the side-effect(s)

Leading to:

\version "2.19.65"

condGrobTweak =
#(define-music-function (use_octave target grob_proc)
   ((boolean? #f) ly:music? procedure?)
   (let ((pitches (event-chord-pitches target)))
     #{
       \override NoteHead.before-line-breaking =
       #(lambda (grob)
          (let* ((cause (ly:grob-property grob 'cause))
                 (pitch (ly:prob-property cause 'pitch))
                 (note (ly:pitch-notename pitch))
                 (alteration (ly:pitch-alteration pitch))
                 (octave (ly:pitch-octave pitch)))
            (for-each
              (lambda (this-pitch)
                (if (and (eqv? alteration (ly:pitch-alteration this-pitch))
                         (eqv? note (ly:pitch-notename this-pitch))
                         (or (not use_octave)
                             (eqv? octave (ly:pitch-octave this-pitch))))
                    (grob_proc grob)))
              pitches)))
     #}))

#(define (omit-accidental grob)
   (let ((accidental (ly:grob-object grob 'accidental-grob)))
     (if (ly:grob? accidental)
         (ly:grob-set-property! accidental 'stencil #f))))

{
    \once \condGrobTweak <cs> #omit-accidental
    <cs' es' gs' bs'>
}

Cheers,
  Harm


reply via email to

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