2 bar.cc -- implement Bar
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include "bar-line.hh"
14 #include "paper-column.hh"
15 #include "output-def.hh"
16 #include "font-interface.hh"
17 #include "all-font-metrics.hh"
18 #include "staff-symbol-referencer.hh"
20 MAKE_SCHEME_CALLBACK (Bar_line, print, 1);
23 Bar_line::print (SCM smob)
25 Grob * me = unsmob_grob (smob);
27 SCM s = me->get_property ("glyph");
28 SCM barsiz_proc = me->get_property ("bar-size-procedure");
29 if (scm_is_string (s) && ly_c_procedure_p (barsiz_proc))
31 String str = ly_scm2string (s);
32 SCM siz = scm_call_1 (barsiz_proc, me->self_scm ());
33 Real sz = robust_scm2double (siz, 0);
37 return compound_barline (me, str, sz).smobbed_copy ();
44 Bar_line::compound_barline (Grob*me, String str, Real h)
46 Real kern = robust_scm2double (me->get_property ("kern"), 1);
47 Real thinkern = robust_scm2double (me->get_property ("thin-kern"), 1);
48 Real hair = robust_scm2double (me->get_property ("hair-thickness"), 1);
49 Real fatline = robust_scm2double (me->get_property ("thick-thickness"), 1);
51 Real staffline = me->get_layout ()->get_dimension (ly_symbol2scm ("linethickness"));
52 Real staff_space = Staff_symbol_referencer::staff_space (me);
55 thinkern *= staffline;
59 Stencil thin = simple_barline (me, hair, h);
60 Stencil thick = simple_barline (me, fatline, h);
61 Stencil dot = Font_interface::get_default_font (me)->find_by_name ("dots.dot");
63 int lines = Staff_symbol_referencer::line_count (me);
65 = ((lines & 1 || lines == 0)
67 : (staff_space < 2 ? 2 : .5) ) * staff_space;
69 colon.translate_axis (dist, Y_AXIS);
70 colon.add_stencil (dot);
71 colon.translate_axis (-dist/2, Y_AXIS);
79 return Lookup::blank (Box (Interval (0, 0), Interval (-h/2, h/2)));
85 else if (str == "|." || (h == 0 && str == ":|"))
87 m.add_at_edge (X_AXIS, LEFT, thick, 0, 0);
88 m.add_at_edge (X_AXIS, LEFT, thin, kern, 0 );
90 else if (str == ".|" || (h == 0 && str == "|:"))
92 m.add_at_edge (X_AXIS, RIGHT, thick, 0, 0);
93 m.add_at_edge (X_AXIS, RIGHT, thin, kern, 0);
97 m.add_at_edge (X_AXIS, LEFT, thick, 0, 0);
98 m.add_at_edge (X_AXIS, LEFT, thin, kern, 0);
99 m.add_at_edge (X_AXIS, LEFT, colon, kern, 0);
101 else if (str == "|:")
103 m.add_at_edge (X_AXIS, RIGHT, thick, 0, 0);
104 m.add_at_edge (X_AXIS, RIGHT, thin, kern, 0);
105 m.add_at_edge (X_AXIS, RIGHT, colon, kern, 0);
107 else if (str == ":|:")
109 m.add_at_edge (X_AXIS, LEFT, thick, thinkern, 0);
110 m.add_at_edge (X_AXIS, LEFT, colon, kern, 0);
111 m.add_at_edge (X_AXIS, RIGHT, thick, kern, 0);
112 m.add_at_edge (X_AXIS, RIGHT, colon, kern, 0);
114 else if (str == ".|.")
116 m.add_at_edge (X_AXIS, LEFT, thick, thinkern, 0);
117 m.add_at_edge (X_AXIS, RIGHT, thick, kern, 0);
119 else if (str == "||")
122 should align to other side? this never appears
125 m.add_at_edge (X_AXIS, RIGHT, thin, 0, 0);
126 m.add_at_edge (X_AXIS, RIGHT, thin, thinkern, 0);
130 int c = (Staff_symbol_referencer::line_count (me));
132 for (int i = 0 ; i < c - 1; i++)
134 Real y = (- (c-1.0) / 2 + 0.5 + i * staff_space);
137 d. translate_axis (y, Y_AXIS);
145 Bar_line::simple_barline (Grob *me,
149 Real blot = me->get_layout ()->get_dimension (ly_symbol2scm ("blotdiameter"));
151 return Lookup::round_filled_box (Box (Interval (0, w), Interval (-h/2, h/2)), blot);
154 MAKE_SCHEME_CALLBACK (Bar_line, before_line_breaking , 1);
157 Bar_line::before_line_breaking (SCM smob)
159 Grob*me = unsmob_grob (smob);
160 Item * item = dynamic_cast<Item*> (me);
162 SCM g = me->get_property ("glyph");
164 Direction bsd = item->break_status_dir ();
165 if (scm_is_string (g) && bsd)
167 SCM proc = me->get_property ("break-glyph-function");
168 g = scm_call_2 (proc, g, scm_int2num (bsd));
171 if (!scm_is_string (g))
173 me->set_property ("print-function", SCM_EOL);
174 me->set_extent (SCM_EOL, X_AXIS);
175 // leave y_extent for spanbar?
178 if (! ly_c_equal_p (g, orig))
179 me->set_property ("glyph", g);
181 return SCM_UNSPECIFIED;
187 MAKE_SCHEME_CALLBACK (Bar_line, get_staff_bar_size, 1);
189 Bar_line::get_staff_bar_size (SCM smob)
191 Grob*me = unsmob_grob (smob);
192 Real ss = Staff_symbol_referencer::staff_space (me);
193 SCM size = me->get_property ("bar-size");
194 if (scm_is_number (size))
195 return scm_make_real (scm_to_double (size)*ss);
196 else if (Staff_symbol_referencer::get_staff_symbol (me))
199 If there is no staff-symbol, we get -1 from the next
200 calculation. That's a nonsense value, which would collapse the
201 barline so we return 0.0 in the next alternative.
203 Real ysize = (Staff_symbol_referencer::line_count (me) -1);
204 ysize = ysize * ss + Staff_symbol_referencer::line_thickness (me);
205 return scm_make_real (ysize);
208 return scm_int2num (0);
213 ADD_INTERFACE (Bar_line, "bar-line-interface",
216 "Print a special bar symbol. It replaces the \n"
217 "regular bar symbol with a special\n"
218 "symbol. The argument @var{bartype} is a string which specifies the\n"
219 "kind of bar to print. Options are @code{:|}, \n"
220 "@code{|:}, @code{:|:},\n"
221 "@code{||}, @code{|.},\n"
222 "@code{.|}, and @code{.|.}. \n"
224 "These produce, respectively, a right repeat, a left repeat, a double\n"
225 "repeat, a double bar, a start bar, an end bar, and a thick double bar.\n"
226 "If @var{bartype} is set to @code{empty} then nothing is printed,\n"
227 "but a line break is allowed at that spot.\n",
228 "bar-size-procedure kern thin-kern hair-thickness thick-thickness glyph bar-size break-glyph-function");