2 bar.cc -- implement Bar
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include "paper-column.hh"
15 #include "bar-line.hh"
17 #include "molecule.hh"
18 #include "paper-def.hh"
19 #include "font-interface.hh"
21 #include "all-font-metrics.hh"
23 #include "staff-symbol-referencer.hh"
25 MAKE_SCHEME_CALLBACK (Bar_line,brew_molecule,1);
28 Bar_line::brew_molecule (SCM smob)
30 Grob * me = unsmob_grob (smob);
32 SCM s = me->get_grob_property ("glyph");
33 SCM barsiz_proc = me->get_grob_property ("bar-size-procedure");
34 if (gh_string_p (s) && gh_procedure_p (barsiz_proc))
36 String str =ly_scm2string (s);
37 SCM siz = gh_call1 (barsiz_proc, me->self_scm ());
38 Real sz = gh_scm2double (siz);
42 return compound_barline (me, str, sz).smobbed_copy ();
49 Bar_line::compound_barline (Grob*me, String str, Real h)
51 Real kern = gh_scm2double (me->get_grob_property ("kern"));
52 Real thinkern = gh_scm2double (me->get_grob_property ("thin-kern"));
53 Real hair = gh_scm2double (me->get_grob_property ("hair-thickness"));
54 Real fatline = gh_scm2double (me->get_grob_property ("thick-thickness"));
56 Real staffline = me->paper_l ()->get_var ("linethickness");
57 Real staff_space = Staff_symbol_referencer::staff_space (me);
60 thinkern *= staffline;
64 Molecule thin = simple_barline (me, hair, h);
65 Molecule thick = simple_barline (me, fatline, h);
67 Molecule dot = Font_interface::get_default_font (me)->find_by_name ("dots-dot");
68 Real dist = ( Staff_symbol_referencer::line_count (me) & 1 ? 1 :
69 (staff_space<2 ? 2 : .5) ) * staff_space;
70 dot.translate_axis(dist/2,Y_AXIS);
71 colon.add_molecule(dot);
72 dot.translate_axis(-dist,Y_AXIS);
73 colon.add_molecule(dot);
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);
88 m.add_at_edge (X_AXIS, LEFT, thin, kern);
90 else if (str == ".|" || (h == 0 && str == "|:"))
92 m.add_at_edge (X_AXIS, RIGHT, thick, 0);
93 m.add_at_edge (X_AXIS, RIGHT, thin, kern);
97 m.add_at_edge (X_AXIS, LEFT, thick, 0);
98 m.add_at_edge (X_AXIS, LEFT, thin, kern);
99 m.add_at_edge (X_AXIS, LEFT, colon, kern);
101 else if (str == "|:")
103 m.add_at_edge (X_AXIS, RIGHT, thick, 0);
104 m.add_at_edge (X_AXIS, RIGHT, thin, kern);
105 m.add_at_edge (X_AXIS, RIGHT, colon, kern);
107 else if (str == ":|:")
109 m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
110 m.add_at_edge (X_AXIS, LEFT, colon, kern);
111 m.add_at_edge (X_AXIS, RIGHT, thick, kern);
112 m.add_at_edge (X_AXIS, RIGHT, colon, kern);
114 else if (str == ".|.")
116 m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
117 m.add_at_edge (X_AXIS, RIGHT, thick, kern);
119 else if (str == "||")
121 m.add_at_edge (X_AXIS, RIGHT, thin, 0);
122 m.add_at_edge (X_AXIS, RIGHT, thin, thinkern);
130 Bar_line::simple_barline (Grob*,Real w, Real h)
132 return Lookup::filledbox (Box (Interval (0,w), Interval (-h/2, h/2)));
135 MAKE_SCHEME_CALLBACK (Bar_line,before_line_breaking ,1);
138 Bar_line::before_line_breaking (SCM smob)
140 Grob*me=unsmob_grob (smob);
141 Item * item = dynamic_cast<Item*> (me);
143 SCM g = me->get_grob_property ("glyph");
145 Direction bsd = item->break_status_dir ();
146 if (gh_string_p (g) && bsd)
148 SCM proc = me->get_grob_property ("break-glyph-function");
149 g = gh_call2 (proc, g, gh_int2scm (bsd));
153 if (!gh_string_p (g))
155 me->set_grob_property ("molecule-callback", SCM_EOL);
156 me->set_extent (SCM_EOL, X_AXIS);
157 // leave y_extent for spanbar?
160 if (! gh_equal_p (g, orig))
161 me->set_grob_property ("glyph", g);
163 return SCM_UNSPECIFIED;
169 MAKE_SCHEME_CALLBACK (Bar_line,get_staff_bar_size,1);
171 Bar_line::get_staff_bar_size (SCM smob)
173 Grob*me = unsmob_grob (smob);
174 Real ss = Staff_symbol_referencer::staff_space (me);
175 SCM size = me->get_grob_property ("bar-size");
176 if (gh_number_p (size))
177 return gh_double2scm (gh_scm2double (size)*ss);
178 else if (Staff_symbol_referencer::staff_symbol_l (me))
181 If there is no staff-symbol, we get -1 from the next
182 calculation. That's a nonsense value, which would collapse the
183 barline so we return 0.0 in the next alternative.
185 return gh_double2scm ((Staff_symbol_referencer::line_count (me) -1) * ss);
188 return gh_int2scm (0);
193 ADD_INTERFACE (Bar_line, "bar-line-interface",
196 This is a request to print a special bar symbol. It replaces the
197 regular bar symbol with a special
198 symbol. The argument @var{bartype} is a string which specifies the
199 kind of bar to print. Options are @code{:|},
200 @code{|:}, @code{:|:},
201 @code{||}, @code{|.},
202 @code{.|}, and @code{.|.}.
204 These produce, respectively, a right repeat, a left repeat, a double
205 repeat, a double bar, a start bar, an end bar, and a thick double bar.
206 If @var{bartype} is set to @code{empty} then nothing is printed,
207 but a line break is allowed at that spot.
210 "bar-size-procedure kern thin-kern hair-thickness thick-thickness glyph bar-size break-glyph-function");