Instrument names and smallest possible bounding box

2016-01-17 Thread Carl-Henrik Buschmann

1) Instrument names. 

The default placement of instrument names seems a bit messy compared to my 
default Sibelius output:



Lilypond:

They seem "off", not alligned properly. This is of course the fault of the 
author. Most likely there is a easy fix. Suggestions?

2) I need to export pngs for my latex documents and i would like the bounding 
box to be as small as possible. How do i do this?

Code:
> \version "2.19.35"
> 
> %---
> % Global variables
> %---
> global = {
>   \time 4/4
>   \key c \major
> }
> 
> 
> %---
> % Music
> %---
> NRT = \relative c' {
>   \global
>   \clef \treble
>   \hideNotes
>   c d e 
> }
> 
> high = \relative c' {
>   \global
>   \clef \treble
>   \hideNotes
>   c d e
> }
> 
> low = \relative c {
>   \global
>   \clef \bass
>   \hideNotes
>   c d e
> }
> 
> 
> 
> %---
> % Score
> %---
> \score {
> <<
> \new Staff { \NRT }
>   \set Staff.instrumentName = "Analysis"
>   
> \new GrandStaff <<
>   \set GrandStaff.instrumentName = "Woodwind" 
>   \new Staff { \high }
>   \new Staff { \low }
> >>
> 
> \new GrandStaff <<
>   \set GrandStaff.instrumentName = "Brass" 
>   \new Staff { \high }
>   \new Staff { \low }
> >>
> 
> \new GrandStaff <<
>   \set GrandStaff.instrumentName = "Strings" 
>   \new Staff { \high }
>   \new Staff { \low }
> >>
> 
> \new GrandStaff <<
>   \set GrandStaff.instrumentName = \markup \right-column {
> "Piano"
> "Aux."
>   }
>   \new Staff { \high }
>   \new Staff { \low }
> >>
> 
> 
>   
> >>
> }
> 
> %---
> % Layout and stuff i dont understand yet
> %---
> \layout {
>   
>  \context {
>\Score
>timing = ##f
>  }
>  \context {
>\Staff
>\remove "Time_signature_engraver"
>  }
> }

Med vennlig hilsen,
Carl-Henrik Buschmann
Lektor

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


Re: Instrument names and smallest possible bounding box

2016-01-17 Thread Simon Albrecht

On 17.01.2016 12:10, Carl-Henrik Buschmann wrote:
The default placement of instrument names seems a bit messy compared 
to my default Sibelius output.
They seem "off", not alligned properly. This is of course the fault of 
the author. Most likely there is a easy fix. Suggestions?


Well, it’s not your fault: the instrument names are center-aligned by 
default. To right-align them, use


\layout {
  \context {
\StaffGroup % or Staff, or GrandStaff, or ChoirStaff…
\override InstrumentName.self-alignment-X = 1
  }
}

Yours, Simon

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


Re: Instrument names and smallest possible bounding box

2016-01-17 Thread Malte Meyn


Am 17.01.2016 um 12:10 schrieb Carl-Henrik Buschmann:
> 
> 1) Instrument names.
> 
> The default placement of instrument names seems a bit messy compared to my 
> default Sibelius output:
> 
> 
> Lilypond:
> They seem "off", not alligned properly. This is of course the fault of the 
> author. Most likely there is a easy fix. Suggestions?

LilyPond tries to center-align the instrument names. Long names which
don’t fit into the margin defined by indent (default 1.5cm (?)) are
right-aligned (“Woodwind” in your example). This “mixing” behaviour
looks odd, I agree. You can make the indent bigger so all names are
center-aligned or change the alignment of instrument names globally;
here are both solutions (they also can be combined):


\version "2.19.35"

\paper {
  %indent = 1.8\cm % short center-aligned (in this margin), long right
  %indent = 3.5\cm % both center-aligned
}

%{
\layout {
  \context {
\Staff
\override InstrumentName.self-alignment-X = #RIGHT
  }
}
%}

<<
  \new Staff \with {
instrumentName = "very long name"
  } { R1 \break R1 }
  \new Staff \with {
instrumentName = "short"
  } { R1 \break R1 }
>>


> 
> 2) I need to export pngs for my latex documents and i would like the bounding 
> box to be as small as possible. How do i do this?
> 

There is a lilypond option -dpreview which does this iirc. And apart
from that: Do you know lilypond-book?

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


Re: Instrument names and smallest possible bounding box

2016-01-17 Thread Carl-Henrik Buschmann

> 17. jan. 2016 kl. 12.24 skrev Malte Meyn :
>> 
>> 2) I need to export pngs for my latex documents and i would like the 
>> bounding 
>> box to be as small as possible. How do i do this?
>> 
> 
> There is a lilypond option -dpreview which does this iirc. And apart
> from that: Do you know lilypond-book?

No, i do not. 


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


Re: Instrument names and smallest possible bounding box

2016-01-17 Thread mskala
On Sun, 17 Jan 2016, Carl-Henrik Buschmann wrote:
> 2) I need to export pngs for my latex documents and i would like the
> bounding box to be as small as possible. How do i do this?

I don't know how well this fits into your workflow, but I'd be inclined to
trim the images after export using pnmcrop, automated by a Makefile
recipe.  Probably simpler than trying to get Lilypond to resize its "page"
to fit the material.  If you were exporting in a vector format, the
trimming operation might be harder, but trimming off white borders on
a PNG file is easy.

-- 
Matthew Skala
msk...@ansuz.sooke.bc.ca People before principles.
http://ansuz.sooke.bc.ca/

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


Re: Instrument names and smallest possible bounding box

2016-01-17 Thread Kieren MacMillan
Hi Carl-Henrik

> 1) Instrument names. 
> The default placement of instrument names seems a bit messy compared to my 
> default Sibelius output:

Actually, I much prefer the Lilypond output — it almost perfectly matches the 
convention of hand-engraved music.

> They seem "off", not alligned properly.

Do you want them right-aligned? If so, that’s dead simple:

   \override InstrumentName.self-alignment-X = #RIGHT

Hope this helps!
Kieren.


Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info


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


Re: Instrument names and smallest possible bounding box

2016-01-17 Thread Kieren MacMillan
Hi all,

On Jan 17, 2016, at 6:24 AM, Malte Meyn  wrote:

> LilyPond tries to center-align the instrument names. Long names which
> don’t fit into the margin defined by indent (default 1.5cm (?)) are
> right-aligned (“Woodwind” in your example). This “mixing” behaviour
> looks odd, I agree. You can make the indent bigger so all names are
> center-aligned or change the alignment of instrument names globally

You can also use David N’s great custom-align function — see snippet, below.

Hope this helps!
Kieren.

p.s. David N: Is this code ready to present as a patch? I think it’s not only a 
very useful function, it should be Lilypond’s default setting.

  SNIPPET BEGINS
\version "2.19.35"

#(define (align-to-interval victim target dir)
   "Align interval @var{victim} to interval @var{target} according
to the value of @var{dir}.  If @var{dir} is a number, use it to orient
both intervals.  If @var{dir} is a pair, use the @code{car} for the
victim and the @code{cdr} for the target."
   (let ((v-dir (if (number? dir) dir (car dir)))
 (t-dir (if (number? dir) dir (cdr dir
 (coord-translate
  victim
  (- (interval-index target t-dir)
(interval-index victim v-dir)

#(define (within-interval? point interval)
   "Does interval @var{interval} enclose number @var{num}?"
   (and
(interval-sane? interval)
(not (< point (car interval)))
(not (> point (cdr interval)

#(define (custom-align grob)
   (let* ((system (ly:grob-system grob))
  (elements (ly:grob-array->list
 (ly:grob-object system 'elements)))
  (elements (filter grob::is-live? elements))
  (text-grobs
   (filter
(lambda (e) (grob::has-interface e 'system-start-text-interface))
elements))

  ;; A delimiter is an initial barline, bracket, brace.
  (delims
   (filter
(lambda (elt)
  (grob::has-interface elt 'system-start-delimiter-interface))
elements))
  ;; To determine which delimiters affect our grob, we
  ;; unfortunately have to calculate its Y-position and
  ;; that of the delimiters!
  (text-grobs-delims-list
   (map (lambda (tg)
  (cons tg
(list
 (remove
  (lambda (d)
(not (within-interval?
  (ly:grob-property tg 'Y-offset)
  (ly:grob-extent d system Y
  delims
 text-grobs))
  (delim-extent-list
   (lambda (delim-list)
 (map
  (lambda (d) (ly:grob-extent d system X))
  delim-list)))
  ; Return a list of text grobs and their associated delimiter extents
  ; if we have no delimiters (as will happen with a single staff), use
  ; the left extent of the (unoffset) text grob itself as a basis.
  (text-grobs-delim-extents
   (map
(lambda (tgdl)
  (cons (car tgdl)
(if (null? (cadr tgdl))
(let ((me-ext (ly:grob-extent (car tgdl) system X)))
  (list (cons (car me-ext) (car me-ext
(delim-extent-list (cadr tgdl)
text-grobs-delims-list))
  ; combine extents
  (text-grobs-total-delim-extents
   (map (lambda (tgde)
  (cons (car tgde)
(reduce interval-union
  '()
  (cdr tgde
 text-grobs-delim-extents))
  ; assumption?
  (representative-delim-extent
   (cdar text-grobs-total-delim-extents))

  ; In order to calculate how much to move our name, we first need
  ; to construct a list of target positions for all grobs.
  (bar-line-width 0.1) ; Ugh.
  (target
   (map (lambda (tg)
  (let ((len (interval-length (ly:grob-extent tg system X
(cons tg
  (cons (- (cdr representative-delim-extent)
  bar-line-width)
(+ (- (cdr representative-delim-extent) bar-line-width)
  len)
 text-grobs))
  (target
   (map
(lambda (re)
  (cons (car re)
(coord-translate
 (cdr re)
 (ly:side-position-interface::x-aligned-side (car re)
target))
  (longest
   (car
(sort target
  (lambda (x y) (> (interval-length (cdr x))
   (interval-length (cdr y)))
  (target
   (map
(lambda (x)
  (cons (car x)
(align-to-interval ;align-interval-on-other
  (cdr x) (cdr longest)
  (ly:grob-property (car x) 'se

Re: Instrument names and smallest possible bounding box

2016-01-17 Thread David Nalesnik
Hi,

On Sun, Jan 17, 2016 at 8:53 AM, Kieren MacMillan <
kieren_macmil...@sympatico.ca> wrote:

> Hi all,
>
> On Jan 17, 2016, at 6:24 AM, Malte Meyn  wrote:
>
> > LilyPond tries to center-align the instrument names. Long names which
> > don’t fit into the margin defined by indent (default 1.5cm (?)) are
> > right-aligned (“Woodwind” in your example). This “mixing” behaviour
> > looks odd, I agree. You can make the indent bigger so all names are
> > center-aligned or change the alignment of instrument names globally
>
> You can also use David N’s great custom-align function — see snippet,
> below.
>
> Hope this helps!
> Kieren.
>
> p.s. David N: Is this code ready to present as a patch? I think it’s not
> only a very useful function, it should be Lilypond’s default setting.
>

Unfortunately, this code doesn't work with the example here:
https://sourceforge.net/p/testlilyissues/issues/4728/  and I haven't yet
pinpointed the reason.

The code also is badly in need of some caching to avoid repetition of
expensive calculations.  Not sure of the best way to do this.

So no patch yet...

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