lilypond-user
[Top][All Lists]
Advanced

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

can InstrumentName padding centered according to the longest instrument


From: Kieren MacMillan
Subject: can InstrumentName padding centered according to the longest instrument name?
Date: Sun, 26 Apr 2015 13:45:22 -0400

Hello all,

In the snippet <http://lsr.di.unimi.it/LSR/Snippet?id=383>, the instrument 
names are centered [beautifully!] based on the total indent value.

How would one make the instruments be centered in a block only the width of the 
longest instrument name (plus maybe a little padding), with the block 
right-aligned to the beginning of the score? (I’ve included, below, a full 
example with two different indent values, for clarification and testing.) 
Ideally, one wouldn’t even have to use Nicolas’s \instrument function: Lilypond 
would simply Do The Right Thing™, taking into account all instrument names.

Thanks,
Kieren.

%%%%%%%%%%  BEGIN SNIPPET  %%%%%%%%%%
\version “2.19.18"

#(define-markup-command (hcenter-pad layout props width arg)
 (number? markup?)
 (let* ((arg-stencil (interpret-markup layout props arg))
        (w (interval-length (ly:stencil-extent arg-stencil X)))
        (pad-stencil (ly:make-stencil ""
                       (cons 0 (if (> w width)
                                0
                                (/ (- width w) 2.0)))
                       '(-0.1 . 0.1))))
  (stack-stencil-line 0
    (list pad-stencil arg-stencil pad-stencil))))

#(define-markup-command (instruments layout props texts) (markup-list?)
   (let ((indent (ly:output-def-lookup layout 'indent)))
     (interpret-markup layout props
      (make-column-markup
        (map (lambda (m) (markup #:hcenter-pad indent #:huge m))
        texts)))))

#(define-markup-command (instrument layout props text) (markup?)
 (interpret-markup layout props
  (markup #:instruments (text))))

\paper {
  left-margin = 0.5\in
}

\layout {
  system-count = 2
  \context {
    \Staff
    shortInstrumentName = "SI"
    \override InstrumentName.padding = #1
  }
}

\score {
  \new StaffGroup <<
    \new Staff \with { instrumentName = \markup \instrument "Long Instrument 
Name" }
      { c''1 c'' }
    \new Staff \with { instrumentName = \markup \instrument "Short" }
      { c''1 c'' }
  >>
  \layout {
    indent = 2\in
  }
}

\score {
  \new StaffGroup <<
    \new Staff \with { instrumentName = \markup \instrument "Long Instrument 
Name" }
      { c''1 c'' }
    \new Staff \with { instrumentName = \markup \instrument "Short" }
      { c''1 c'' }
  >>
  \layout {
    indent = 4\in
  }
}
%%%%%%%%%%  END SNIPPET  %%%%%%%%%%




reply via email to

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