]> git.donarmstrong.com Git - lilypond.git/commitdiff
Instrument names: horizontal aligment.
authorNicolas Sceaux <nicolas.sceaux@free.fr>
Fri, 15 Feb 2008 21:01:31 +0000 (22:01 +0100)
committerNicolas Sceaux <nicolas.sceaux@free.fr>
Fri, 15 Feb 2008 21:01:31 +0000 (22:01 +0100)
 - define a short-indent scaled layout variable;
 - using indent or short-indent, and the value of the self-alignment-X
grob property, horizontally align the instrument name;
 - by default, center instrument names.

Documentation/user/staff.itely
input/regression/instrument-name-x-align.ly [new file with mode: 0644]
lily/system-start-text.cc
scm/define-grobs.scm
scm/paper.scm

index b1d47765da5a93a44bc020566946c2f4b257938f..ee40671d525a568bc6dc16f2b91ab96c459b91b8 100644 (file)
@@ -439,20 +439,20 @@ c''1
 
 @cindex instrument names, centering
 
-If you wish to center the instrument names, you must center all of
-them individually:
+As instrument names are centered by default, multi line names
+are better entered using @code{\center-align}:
 
 @lilypond[quote,verbatim,ragged-right]
 { <<
 \new Staff {
-  \set Staff.instrumentName = \markup {
-    \center-align { "Clarinetti"
-      \line { "in B" \smaller \flat } } }
+  \set Staff.instrumentName = \markup \center-align {
+    Clarinetti
+    \line { "in B" \smaller \flat }
+  }
   c''1
 }
 \new Staff {
-  \set Staff.instrumentName =
-       \markup{ \center-align { Vibraphone }}
+  \set Staff.instrumentName = "Vibraphone"
   c''1
 }
 >>
@@ -462,23 +462,9 @@ them individually:
 For longer instrument names, it may be useful to increase the
 @code{indent} setting in the @code{\layout} block.
 
-To center instrument names while leaving extra space to the right,
-
-@lilypond[quote,verbatim,ragged-right]
-\new StaffGroup \relative
-<<
-  \new Staff {
-    \set Staff.instrumentName =
-        \markup { \hcenter-in #10 "blabla" }
-    c1 c1
-  }
-  \new Staff {
-    \set Staff.instrumentName =
-         \markup { \hcenter-in #10 "blo" }
-    c1 c1
-  }
->>
-@end lilypond
+Short instrument names, printed before the systems following the first
+one, are also centered by default, in a space which width is given by
+the @code{short-indent} variable of the @code{\layout} block.
 
 To add instrument names to other contexts (such as
 @code{GrandStaff}, @code{ChoirStaff}, or @code{StaffGroup}), the
diff --git a/input/regression/instrument-name-x-align.ly b/input/regression/instrument-name-x-align.ly
new file mode 100644 (file)
index 0000000..bfdd50f
--- /dev/null
@@ -0,0 +1,45 @@
+\header {
+
+  texidoc = "Instrument names horizontal alignment is tweaked by
+changing the @code{Staff.Instrument #'self-alignment-X} property.  The
+@code{\layout} variables @code{indent} and @code{short-indent} define
+the space where the instrument names are aligned before the first and
+the following systems, respectively."
+
+}
+
+\version "2.11.39"
+\paper { left-margin = 3\cm }
+\score {
+  \new StaffGroup <<
+    \new Staff {
+      \override Staff . InstrumentName #'self-alignment-X = #LEFT
+      \set Staff . instrumentName = \markup \column {
+       "Left aligned" "instrument name"
+      }
+      \set Staff . shortInstrumentName = "Left"
+      c''1 \break c''
+    }
+    \new Staff {
+      \override Staff . InstrumentName #'self-alignment-X = #CENTER
+      \set Staff . instrumentName = \markup \center-align {
+       "Centered" "instrument name"
+      }
+      \set Staff . shortInstrumentName = "Centered"
+      g'1 g'
+    }
+    \new Staff {
+      \override Staff . InstrumentName #'self-alignment-X = #RIGHT
+      \set Staff . instrumentName = \markup \column \right-align {
+       "Right aligned" "instrument name"
+      }
+      \set Staff . shortInstrumentName = "Right"
+      e' \break e'
+    }
+  >>
+  \layout {
+    ragged-right = ##t
+    indent = 4\cm
+    short-indent = 2\cm
+  }
+}
index 494ab149b883f8f024df6d37ca685dca8e171dbf..c99f150fed06fa75d476799244a671d9823f4bc3 100644 (file)
@@ -45,7 +45,23 @@ System_start_text::get_stencil (Grob *me_grob)
       SCM align_y  = me_grob->get_property ("self-alignment-Y");
       if (scm_is_number (align_y))
        p->align_to (Y_AXIS, robust_scm2double (align_y, 0.0));
-      return *p;
+
+      /* Horizontal alignment according to the self-alignment-X property
+       * and indent value. */
+      Output_def *layout = me_grob->layout ();
+      Real indent;
+      if (me->get_break_index () == 0)
+       indent = robust_scm2double (layout->c_variable ("indent"), 0);
+      else
+       indent = robust_scm2double (layout->c_variable ("short-indent"), 0);
+      Real align_x = robust_scm2double (me->get_property ("self-alignment-X"), 0);
+      Interval p_extent_x = p->extent (X_AXIS);
+      Interval padding (0.0, max (0.0, indent - p_extent_x.length ()));
+      Real right_padding = padding.length () - padding.linear_combination (align_x);
+      Box box (Interval (p_extent_x[LEFT], p_extent_x[RIGHT] + right_padding),
+              p->extent (Y_AXIS));
+      Stencil *aligned_p = new Stencil (box, p->expr ());
+      return *aligned_p;
     }
   return Stencil ();
 }
@@ -101,4 +117,5 @@ ADD_INTERFACE (System_start_text,
               "text "
               "long-text "
               "self-alignment-Y "
+              "self-alignment-X "
               );
index c8b1c5f08595a76defafd7eb6d8ed83b5401bb0e..2ef83b3d30853237beb3c7e29a7d1b4e504e253f 100644 (file)
        (X-offset . ,ly:side-position-interface::x-aligned-side)
        (direction . ,LEFT)
        (self-alignment-Y . ,CENTER)
+       (self-alignment-X . ,CENTER)
        (meta . ((class . Spanner)
                 (interfaces . (system-start-text-interface
                                side-position-interface
index be15759f7a87abefe4f89a27a48198778a3b72ee..8c2b5dc71025a7e18fe5deef9dd5c866e8ff560a 100644 (file)
@@ -9,7 +9,7 @@
                  '(pt mm cm in staff-height staff-space
                       page-top-space
                       between-system-space between-system-padding
-                      line-width indent paper-width paper-height horizontal-shift
+                      line-width indent short-indent paper-width paper-height horizontal-shift
                       staff-space line-thickness ledgerline-thickness
                       blot-diameter left-margin right-margin)))
 
@@ -115,6 +115,7 @@ size. SZ is in points"
                                     (ly:modules-lookup (list m) 'right-margin (* 10 mm))))
 
     (module-define! m 'indent (/ w 14))
+    (module-define! m 'short-indent (* 5 mm))
 
     ;; page layout - what to do with (printer specific!) margin settings?