]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-line.cc
* lily/tie-column.cc (set_manual_tie_configuration): new function.
[lilypond.git] / lily / bar-line.cc
1 /*
2   bar-line.cc -- implement Bar_line
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "bar-line.hh"
10
11 #include <cmath>
12 using namespace std;
13
14 #include "all-font-metrics.hh"
15 #include "font-interface.hh"
16 #include "lookup.hh"
17 #include "output-def.hh"
18 #include "paper-column.hh"
19 #include "staff-symbol-referencer.hh"
20
21 MAKE_SCHEME_CALLBACK (Bar_line, print, 1);
22
23 SCM
24 Bar_line::print (SCM smob)
25 {
26   Grob *me = unsmob_grob (smob);
27
28   SCM s = me->get_property ("glyph");
29   SCM barsiz_proc = me->get_property ("bar-size-procedure");
30   if (scm_is_string (s) && ly_is_procedure (barsiz_proc))
31     {
32       String str = ly_scm2string (s);
33       SCM siz = scm_call_1 (barsiz_proc, me->self_scm ());
34       Real sz = robust_scm2double (siz, 0);
35       if (sz <= 0)
36         return SCM_EOL;
37
38       return compound_barline (me, str, sz, false).smobbed_copy ();
39     }
40   return SCM_EOL;
41 }
42
43 Stencil
44 Bar_line::compound_barline (Grob *me, String str, Real h,
45                             bool rounded)
46 {
47   Real kern = robust_scm2double (me->get_property ("kern"), 1);
48   Real thinkern = robust_scm2double (me->get_property ("thin-kern"), 1);
49   Real hair = robust_scm2double (me->get_property ("hair-thickness"), 1);
50   Real fatline = robust_scm2double (me->get_property ("thick-thickness"), 1);
51
52   Real staffline = me->get_layout ()->get_dimension (ly_symbol2scm ("linethickness"));
53   Real staff_space = Staff_symbol_referencer::staff_space (me);
54
55   kern *= staffline;
56   thinkern *= staffline;
57   hair *= staffline;
58   fatline *= staffline;
59
60   Stencil thin = simple_barline (me, hair, h, rounded);
61   Stencil thick = simple_barline (me, fatline, h, rounded);
62   Stencil dot = Font_interface::get_default_font (me)->find_by_name ("dots.dot");
63
64   int lines = Staff_symbol_referencer::line_count (me);
65   Real dist
66     = ((lines & 1 || lines == 0)
67        ? 1
68        : (staff_space < 2 ? 2 : .5)) * staff_space;
69   Stencil colon (dot);
70   colon.translate_axis (dist, Y_AXIS);
71   colon.add_stencil (dot);
72   colon.translate_axis (-dist / 2, Y_AXIS);
73
74   Stencil m;
75   if (str == "||:")
76     str = "|:";
77
78   if (str == "")
79     return Lookup::blank (Box (Interval (0, 0), Interval (-h / 2, h / 2)));
80   else if (str == "|")
81     return thin;
82   else if (str == "|." || (h == 0 && str == ":|"))
83     {
84       m.add_at_edge (X_AXIS, LEFT, thick, 0, 0);
85       m.add_at_edge (X_AXIS, LEFT, thin, kern, 0);
86     }
87   else if (str == ".|" || (h == 0 && str == "|:"))
88     {
89       m.add_at_edge (X_AXIS, RIGHT, thick, 0, 0);
90       m.add_at_edge (X_AXIS, RIGHT, thin, kern, 0);
91     }
92   else if (str == ":|")
93     {
94       m.add_at_edge (X_AXIS, LEFT, thick, 0, 0);
95       m.add_at_edge (X_AXIS, LEFT, thin, kern, 0);
96       m.add_at_edge (X_AXIS, LEFT, colon, kern, 0);
97     }
98   else if (str == "|:")
99     {
100       m.add_at_edge (X_AXIS, RIGHT, thick, 0, 0);
101       m.add_at_edge (X_AXIS, RIGHT, thin, kern, 0);
102       m.add_at_edge (X_AXIS, RIGHT, colon, kern, 0);
103     }
104   else if (str == ":|:")
105     {
106       m.add_at_edge (X_AXIS, LEFT, thick, thinkern, 0);
107       m.add_at_edge (X_AXIS, LEFT, colon, kern, 0);
108       m.add_at_edge (X_AXIS, RIGHT, thick, kern, 0);
109       m.add_at_edge (X_AXIS, RIGHT, colon, kern, 0);
110     }
111   else if (str == ".|.")
112     {
113       m.add_at_edge (X_AXIS, LEFT, thick, thinkern, 0);
114       m.add_at_edge (X_AXIS, RIGHT, thick, kern, 0);
115     }
116   else if (str == "||")
117     {
118       /*
119         should align to other side? this never appears
120         on the system-start?
121       */
122       m.add_at_edge (X_AXIS, RIGHT, thin, 0, 0);
123       m.add_at_edge (X_AXIS, RIGHT, thin, thinkern, 0);
124     }
125   else if (str == ":")
126     {
127       int c = (Staff_symbol_referencer::line_count (me));
128
129       for (int i = 0; i < c - 1; i++)
130         {
131           Real y = (- (c - 1.0) / 2 + 0.5 + i * staff_space);
132           Stencil d (dot);
133
134           d.translate_axis (y, Y_AXIS);
135           m.add_stencil (d);
136         }
137     }
138   return m;
139 }
140
141 Stencil
142 Bar_line::simple_barline (Grob *me,
143                           Real w,
144                           Real h,
145                           bool rounded)
146 {
147   Real blot
148     = rounded
149     ? me->get_layout ()->get_dimension (ly_symbol2scm ("blotdiameter"))
150     : 0.0;
151
152   return Lookup::round_filled_box (Box (Interval (0, w),
153                                         Interval (-h / 2, h / 2)), blot);
154 }
155
156 MAKE_SCHEME_CALLBACK (Bar_line, before_line_breaking, 1);
157
158 SCM
159 Bar_line::before_line_breaking (SCM smob)
160 {
161   Grob *me = unsmob_grob (smob);
162   Item *item = dynamic_cast<Item *> (me);
163
164   SCM g = me->get_property ("glyph");
165   SCM orig = g;
166   Direction bsd = item->break_status_dir ();
167   if (scm_is_string (g) && bsd)
168     {
169       SCM proc = me->get_property ("break-glyph-function");
170       g = scm_call_2 (proc, g, scm_from_int (bsd));
171     }
172
173   if (!scm_is_string (g))
174     {
175       me->set_property ("print-function", SCM_EOL);
176       me->set_extent (SCM_EOL, X_AXIS);
177       // leave y_extent for spanbar? 
178     }
179
180   if (! ly_is_equal (g, orig))
181     me->set_property ("glyph", g);
182
183   return SCM_UNSPECIFIED;
184 }
185
186 MAKE_SCHEME_CALLBACK (Bar_line, get_staff_bar_size, 1);
187 SCM
188 Bar_line::get_staff_bar_size (SCM smob)
189 {
190   Grob *me = unsmob_grob (smob);
191   Real ss = Staff_symbol_referencer::staff_space (me);
192   SCM size = me->get_property ("bar-size");
193   if (scm_is_number (size))
194     return scm_from_double (scm_to_double (size) * ss);
195   else if (Staff_symbol_referencer::get_staff_symbol (me))
196     {
197       /*
198         If there is no staff-symbol, we get -1 from the next
199         calculation. That's a nonsense value, which would collapse the
200         barline so we return 0.0 in the next alternative.
201       */
202       Real ysize = (Staff_symbol_referencer::line_count (me) -1);
203       ysize = ysize * ss + Staff_symbol_referencer::line_thickness (me);
204       return scm_from_double (ysize);
205     }
206   return scm_from_int (0);
207 }
208
209 ADD_INTERFACE (Bar_line, "bar-line-interface",
210                "Bar line.\n"
211                "\n"
212                "Print a special bar symbol. It replaces the \n"
213                "regular bar symbol with a special\n"
214                "symbol.  The argument @var{bartype} is a string which specifies the\n"
215                "kind of bar to print.  Options are @code{:|}, \n"
216                "@code{|:}, @code{:|:},\n"
217                "@code{||}, @code{|.},\n"
218                "@code{.|}, and @code{.|.}. \n"
219                "\n"
220                "These produce, respectively, a right repeat, a left repeat, a double\n"
221                "repeat, a double bar, a start bar, an end bar, and a thick double bar.\n"
222                "If @var{bartype} is set to @code{empty} then nothing is printed,\n"
223                "but a line break is allowed at that spot.\n",
224                "bar-size-procedure kern thin-kern hair-thickness thick-thickness glyph bar-size break-glyph-function");