Hi again,

On Mon, Mar 13, 2017 at 10:15 AM, David Kastrup <d...@gnu.org> wrote:
> David Nalesnik <david.nales...@gmail.com> writes:
>
>> Oh, there's some extra code.  I decided to use a flag to avoid
>> redundant calculations, but didn't follow through.  The music function
>> should read
>>
>> spaceStemsEvenly =
>> #(define-music-function (mus) (ly:music?)
>>    #{
>>      \override NoteColumn.X-offset = #space-by-stems
>>      #mus
>>      \revert NoteColumn.X-offset
>>    #})
>
> This looks like it should rather be \temporary \override in order not to
> interfere with preexisting settings in the context.
>
> --
> David Kastrup

I've attached a version which updates the music function based on
David Kastrup's suggestion above.

Also, since it's certainly more convenient for you to wrap large
chunks of music in the music function, the attached checks for
cross-staff beaming.

DN
\version "2.19.56"

%% Grob should be a NoteColumn object
#(define (space-by-stems grob)
   (let* ((stem (ly:grob-object grob 'stem))
          (beam (ly:grob-object stem 'beam)))
     (if (eq? #t (ly:grob-property beam 'cross-staff))
         (let* ((stems (ly:grob-array->list (ly:grob-object beam 'stems)))
                 (note-columns (map (lambda (s) (ly:grob-parent s X)) stems))
                 ;; which NoteColumn am I?
                 (me-nc (memq grob note-columns))
                 (nth (- (length note-columns) (length me-nc)))
                 (orig-stem-pos (map (lambda (s nc) (ly:grob-relative-coordinate s nc X))
                                  stems note-columns)))
           (* -1 (list-ref orig-stem-pos nth)))
         0.0)))

spaceStemsEvenly =
#(define-music-function (mus) (ly:music?)
   #{
     \temporary \override NoteColumn.X-offset = #space-by-stems
     #mus
     \revert NoteColumn.X-offset
   #})

%%%%%%%%%%%%%%%%%% EXAMPLE %%%%%%%%%%%%%%%%%

tsd = { \change Staff = treble \stemDown }
bsu = { \change Staff = bass \stemUp }

treble = {
  \clef treble
  aes''32[ \bsu cis'! \tsd disis'''! \bsu deses'! \tsd d''' \bsu ees'!]
}

bass = {
  \clef bass
  s8.
}

\score {

  \new PianoStaff
  <<
    \new Staff = "treble" { \treble \spaceStemsEvenly \treble \treble }
    \new Staff = "bass" { \bass \bass \bass }
  >>

  \layout {
    \context {
      \Score
      proportionalNotationDuration = #(ly:make-moment 1/32)
      \override SpacingSpanner.uniform-stretching = ##t
      \override Score.SpacingSpanner.strict-note-spacing = ##t
    }
  }
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to