Re: Help notating a particular bar

2015-05-23 Thread Andrew Bernard
Hi Nick,

Centering notes was very common in past traditions, and indeed in various 
modernist traditions. Lilypond does not do it out of the box. I think it must 
be one of my personal top ten most wanted features. So, for people working 
outside the Common Practice Era, you need to use some functions to help you. 
There was discussion on the mailing list about this some time ago, from which I 
have extracted centering function code that works very well indeed.

Here’s the code. Note that it only works when there is one object in the bar. 
Works nicely for rests, by the way.

Andrew


% Thanks to David Nalesnik and Thomas Morley.

#(define (sort-by-X-coord sys grob-lst)
   Arranges a list of grobs in ascending order by their X-coordinates
   (let* ((X-coord (lambda (x) (ly:grob-relative-coordinate x sys X)))
          (comparator (lambda (p q) ( (X-coord p) (X-coord q)

     (sort grob-lst comparator)))

#(define (find-bounding-grobs note-column grob-lst)
   (let* ((sys (ly:grob-system note-column))
          (X-coord (lambda (n) (ly:grob-relative-coordinate n sys X)))
          (note-column-X (X-coord note-column)))

     (define (helper lst)
       (if (and ( (X-coord (car lst)) note-column-X)
                ( (X-coord (cadr lst)) note-column-X))
           (cons (car lst) (cadr lst))
           (if (null? (cddr lst))
               (cons note-column note-column)
               (helper (cdr lst)

     (helper grob-lst)))

#(define (read-out ls1 ls2 ls3 symbol)
   Filters all elements of ls1 from ls2 and appends it to ls3
   (set! ls3 (append ls3 (filter (lambda (x) (eq? (car ls1) (symbol x))) ls2)))
   (if (null? (cdr ls1))
       ls3
       (read-out (cdr ls1) ls2 ls3 symbol)))

#(define ((center-note-column x-offs) grob)
   (let* ((sys (ly:grob-system grob))
          (elements-lst (ly:grob-array-list (ly:grob-object sys 
'all-elements)))
          (grob-name (lambda (x) (assq-ref (ly:grob-property x 'meta) 'name)))
          (X-extent (lambda (q) (ly:grob-extent q sys X)))
          ;; NoteColumn
          (note-column-coord (ly:grob-relative-coordinate grob sys X))
          (grob-ext (X-extent grob))
          (grob-length (interval-length grob-ext))
          ;; NoteHeads
          (note-heads (ly:grob-object grob 'note-heads))
          (note-heads-grobs (if (not (null? note-heads))
                                (ly:grob-array-list note-heads)
                                '()))
          (one-note-head (if (not (null? note-heads-grobs))
                             (car note-heads-grobs)
                             '()))
          (one-note-head-length (if (not (null? one-note-head))
                                    (interval-length (X-extent one-note-head)) 
;; NB
                                    0))
          ;; Stem
          (stem (ly:grob-object grob 'stem))
          (stem-dir (ly:grob-property stem 'direction))
          (stem-length-x (interval-length (X-extent stem))) ;; NB
          ;; DotColumn
          (dot-column (ly:note-column-dot-column grob))
          ;; AccidentalPlacement
          (accidental-placement (ly:note-column-accidentals grob))
          ;; Arpeggio
          (arpeggio (ly:grob-object grob 'arpeggio))
          ;; Rest
          (rest (ly:grob-object grob 'rest))
          ;; Grobs to center between
          (args (list 'BarLine
                  'Clef
                  'KeySignature
                  'KeyCancellation
                  'TimeSignature))
          (grob-lst (read-out args elements-lst '() grob-name))
          (new-grob-lst (remove (lambda (x) (interval-empty? (X-extent x))) 
grob-lst))
          (sorted-grob-lst (sort-by-X-coord sys new-grob-lst))
          ;; Bounds
          (bounds (find-bounding-grobs grob sorted-grob-lst))
          (left (cdr (X-extent (car bounds
          (right (car (X-extent (cdr bounds

          ;;(bounds-coord (cons left right)) ;; delete

          (basic-offset
           (- (average left right)
             (interval-center (X-extent grob))
             (* -1 x-offs)))
          (dir-correction
           (if ( grob-length one-note-head-length)
               (* stem-dir (* -2 stem-length-x) grob-length)
               0))

          ) ;; End of Defs in let*

     ;; Calculation
     (begin
      ;;(display \n\tbounds: \t)(write bounds)
      (for-each
       (lambda (x)
         (cond ((ly:grob? x)
                (ly:grob-translate-axis!
                 x
                 (- basic-offset dir-correction)
                 X
       (list
        (cond ((not (null? note-heads)) grob))
        dot-column accidental-placement arpeggio rest))
      )))

centerNoteColumnOn = \override Staff.NoteColumn #'after-line-breaking = 
#(center-note-column 0)

centerNoteColumnOff = \revert Staff.NoteColumn #'after-line-breaking

onceCenterNoteColumn =
#(define-music-function (parser location x-offs)(number?)
   #{
     \once \override Staff.NoteColumn #'after-line-breaking = 

Re: Help notating a particular bar

2015-05-23 Thread Andrew Bernard
Hi Nick,

A snippet to show how to use the centering function.

\version 2.19.20

% substitute your library directory
\include /home/a/lib/lilypond/centre.ly


\paper {
  ragged-right = ##f
}

treble = \relative c'' {
  \clef treble
  \time 4/4
  \centerNoteColumnOn
  b1
  \centerNoteColumnOff
  r4 c c c
}

\score {
  \new Staff \treble
  \layout { }
}


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


Re: Help notating a particular bar

2015-05-23 Thread Pierre Perol-Schneider
Hi Nick,
Hi Andrew,

I'm afraid that 'center-note-column' will not help since the score includes
a dynamic spanner.
Personally, I'd do something less sophisticated.
How about:

\version 2.18.2

myDynamics =
{
  \set crescendoText = \markup\dynamic f
  \set crescendoSpanner = #'text
  \override DynamicTextSpanner.style = #'line
  s1
  s2.._\ s8\f
}

\score {
  \new StaffGroup 
\new Staff 
  \new Voice { s1 s1*1/3 \tweak X-offset #0.3 e'' s }
  \new Voice { s1 s1*1/3 \tweak X-offset #0.3 e' s }
  \new Dynamics \myDynamics

\new Staff 
  \new Voice { s1 s1*1/3 \tweak X-offset #0.3 a' s }
  \new Voice { s1 s1*1/3 \tweak X-offset #0.3 a s }
  \new Dynamics \myDynamics

\new Staff 
  \new Voice { s1 s1*1/3 \tweak X-offset #0.3 bis' s }
  \new Voice { s1 s1*1/3 \tweak X-offset #0.3 bis s }
  \new Dynamics \myDynamics

\new Staff 
  \new Voice { s1 s1*1/3 \tweak X-offset #0.3 f' s }
  \new Dynamics \myDynamics

  
  \layout {
\context {
  \Score
  proportionalNotationDuration = #(ly:make-moment 1/4)
  \override NoteColumn.force-hshift = #0
  \override NoteColumn.ignore-collision = ##t
  \omit Clef
  \omit TimeSignature
}
  }
}

Cheers,
Pierre

2015-05-23 13:00 GMT+02:00 Andrew Bernard andrew.bern...@gmail.com:

 Hi Nick,

 A snippet to show how to use the centering function.

 \version 2.19.20

 % substitute your library directory
 \include /home/a/lib/lilypond/centre.ly


 \paper {
   ragged-right = ##f
 }

 treble = \relative c'' {
   \clef treble
   \time 4/4
   \centerNoteColumnOn
   b1
   \centerNoteColumnOff
   r4 c c c
 }

 \score {
   \new Staff \treble
   \layout { }
 }



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


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


Re: Help notating a particular bar

2015-05-23 Thread Noeck
Hi Nick,

for the dynamics you could simply do something like this (is not
considered in midi output, though):

{
  a1_\markup { \halign #-0.3 \line { \dynamic  f — \dynamic f } }
}

Cheers,
Joram

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