lilypond-user
[Top][All Lists]
Advanced

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

Re: instrument name or \markup question


From: Nicolas Sceaux
Subject: Re: instrument name or \markup question
Date: Sun, 25 Dec 2011 21:12:16 +0100

Le 24 déc. 2011 à 19:10, lily-user a écrit :

> 
> Thanks. That worked. However, is there an automatic way to align the content
> instead of specifying manual numbers? Like how you do in word or even latex.
> I would like to do something like the following
> 
> \set Staff.instrumentName = \markup {  \column {\null "Flute"} \column {1 2}
> } 
> 
> and make the first \column (i.e., Flute) left align and the second column
> (i.e., 1 2) right align, so that I don't have to change line width number,
> when I change paper size or other stuff. 
> 
> I tired the http://lsr.dsi.unimi.it/LSR/Search?q=align&s=20&m=10 in vain.
> Please help. Thanks. 

Hi,

Here is an automatic way to do what you want.
We override the `stencil' callback for InstrumentName, in order to
set the line-width property according to the line indent before
interpreting the instrument name markup, which is more usefull than
having the full line width.  This way, \fill-line will work as expected.
This should be the default, imho.

Nicolas


\version "2.15.24"

#(define-public (instrument-name::print grob)
   (let* ((left-bound (ly:spanner-bound grob LEFT))
          (left-mom (ly:grob-property left-bound 'when))
          (name (if (moment<=? left-mom ZERO-MOMENT)
                    (ly:grob-property grob 'long-text)
                    (ly:grob-property grob 'text))))
     (if (and (markup? name)
              (!= (ly:item-break-dir left-bound) CENTER))
         (let* ((layout (ly:grob-layout grob))
                (defs (ly:output-def-lookup layout 'text-font-defaults))
                (props (ly:grob-alist-chain grob defs))
                (indent (ly:output-def-lookup
                         layout
                         (if (moment<=? left-mom ZERO-MOMENT)
                             'indent
                             'short-indent)
                         0.0)))
           (interpret-markup
            layout
            (cons `((line-width . ,indent)) props)
            name))
         (ly:grob-suicide! grob))))

\layout {
  \context {
    \Staff
    \override InstrumentName #'self-alignment-X = #LEFT
    \override InstrumentName #'stencil = #instrument-name::print
  }
}

music=\new StaffGroup <<
  \new Staff \with {
    instrumentName = \markup\fill-line { "Flute" \vcenter\column { "1" "2" } } 
} {
    c''1
  }
  \new Staff \with { instrumentName = "Piccolo" } {
    g'1
  }
>>

\score {
  \music
  \layout { indent = 3\cm }
}

\score {
  \music
  \layout { indent = 4\cm }
}

\score {
  \music
  \layout { indent = 5\cm }
}




reply via email to

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