lilypond-user
[Top][All Lists]
Advanced

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

Re: "natural width" of a measure


From: Peter Crighton
Subject: Re: "natural width" of a measure
Date: Thu, 11 May 2017 22:42:04 +0200

2017-04-11 22:34 GMT+02:00 David Nalesnik <address@hidden>:
Here's how you can determine the widths of measures.  Note that I've
put everything on one line, so that the \once \override of the
NoteHead gives access to every column in the score.  You can adjust
what alignment objects are used to gauge width by changing the symbol
in ly:paper-column::break-align-width (available as of 2.19.59).
Right now, it's BreakAlignment objects to give you an extent
considering all prefatory materials.  staff-bar would give extents of
the bar lines.

\version "2.19.59"

\paper {
  page-breaking = #ly:one-line-breaking
}

#(define (display-measure-widths grob)
   (let* ((sys (ly:grob-system grob))
          (cols (ly:grob-array->list (ly:grob-object sys 'columns)))
          (nmpcs
           (filter
            (lambda (elt)
              (and (grob::has-interface elt 'paper-column-interface)
                   (eq? #t (ly:grob-property elt 'non-musical))))
            cols))
          (widths
           (map
            (lambda (c) (ly:paper-column::break-align-width c
'(break-alignment)))
            nmpcs))
          (widths (sort widths (lambda (x y) (< (car x) (car y)))))
          )
     (pretty-print widths)))
{

  \once \override NoteHead.after-line-breaking = #display-measure-widths
  \repeat unfold 4 { c''8. c''16}
  \repeat unfold 4 { c''4 }
  c''1
  c''2 c''2
  \repeat unfold 64 { c''64 }
}

\layout {
  \context {
    \Score
    \override SpacingSpanner.common-shortest-duration = #'()
  }
}

Hope this helps with something!

David

Hello David et al.,

it surely has the potential of helping me with my current project. My Scheme skills are still quite rudimentary, though, so I’m stuck for now.
Below you can find a stripped-down version of my chord chart template. I need to offset all the notes and chords, apart from the first in a bar, to the left; the exact offset values I want to calculate based on the length of a measure. In the end, the distances between the notes should be the same as the distance from the last note of a measure to the next bar line.
I think if I know the length of a measure and the position of each note, I can work out a formula for that.

So, my questions are:
How can I display the positions (or extents) of notes, similar to what you did with the extents of bar lines?
How can I access the x and y values of your function outside of that function?
Both seem to me not that difficult, but I couldn’t find the solution for now …


\version "2.19.47"

#(define (display-measure-widths grob)
   (let* ((sys (ly:grob-system grob))
          (cols (ly:grob-array->list (ly:grob-object sys 'columns)))
          (nmpcs
           (filter
            (lambda (elt)
              (and (grob::has-interface elt 'paper-column-interface)
                   (eq? #t (ly:grob-property elt 'non-musical))))
            cols))
          (widths
           (map
            (lambda (c) (ly:generic-bound-extent c sys))
            nmpcs))
          (widths (sort widths (lambda (x y) (< (car x) (car y)))))
          )
     (pretty-print widths)))

<<
  \new Voice {
    \once \override NoteHead.after-line-breaking = #display-measure-widths
    \repeat unfold 4 {
      4 4 4 4
    }
  }

  \new ChordNames \chordmode {
    \repeat unfold 4 {
      c2 c
    }
  }
>>

\layout {
  \context {
    \ChordNames
    \consists "Bar_engraver"
    \consists "Time_signature_engraver"
    \numericTimeSignature

    \override ChordName.Y-extent = ##f
    \override ChordName.Y-offset = #-0.9
    \override ChordName.X-offset = #1

    \override BarLine.bar-extent = #'(-2 . 2)
  }

  \context {
    \Staff
    \remove "Time_signature_engraver"

    \override Clef.stencil = #point-stencil
    \hide BarLine
    \override StaffSymbol.line-count = #0

    \override NoteColumn.X-offset = #1
  }

  \context {
    \Voice
    \consists "Pitch_squash_engraver"
    \improvisationOn
    \stemUp
    fontSize = #-4
  }

  \context {
    \Score
    \override BarNumber.stencil = #point-stencil

    \override Clef.space-alist.first-note = #'(fixed-space . 0)
    \override Clef.space-alist.time-signature = #'(extra-space . -2)

    proportionalNotationDuration = #(ly:make-moment 1/2)
    \override SpacingSpanner.uniform-stretching = ##t
    \override SpacingSpanner.strict-note-spacing = ##t

    \override NonMusicalPaperColumn.padding = #0
  }
}

\paper {
  indent = 0
  ragged-right = ##f
}


Thanks,
Peter

--
Peter Crighton | Musician & Music Engraver based in Mainz, Germany
http://www.petercrighton.de

reply via email to

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