release commit
[lilypond.git] / lily / bar-line.cc
blobe9dd56728bf3ad2309d5875cdf577dc6e96a2063
1 /*
2 bar.cc -- implement Bar
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include <math.h>
11 #include "lookup.hh"
12 #include "paper-column.hh"
13 #include "grob.hh"
14 #include "bar-line.hh"
15 #include "string.hh"
16 #include "molecule.hh"
17 #include "paper-def.hh"
18 #include "font-interface.hh"
20 #include "all-font-metrics.hh"
21 #include "item.hh"
22 #include "staff-symbol-referencer.hh"
24 MAKE_SCHEME_CALLBACK (Bar_line,brew_molecule,1);
26 SCM
27 Bar_line::brew_molecule (SCM smob)
29 Grob * me = unsmob_grob (smob);
31 SCM s = me->get_grob_property ("glyph");
32 SCM barsiz_proc = me->get_grob_property ("bar-size-procedure");
33 if (gh_string_p (s) && gh_procedure_p (barsiz_proc))
35 String str =ly_scm2string (s);
36 SCM siz = gh_call1 (barsiz_proc, me->self_scm ());
37 Real sz = gh_scm2double (siz);
38 if (sz < 0)
39 return SCM_EOL;
41 return compound_barline (me, str, sz).smobbed_copy ();
43 return SCM_EOL;
47 Molecule
48 Bar_line::compound_barline (Grob*me, String str, Real h)
50 Real kern = gh_scm2double (me->get_grob_property ("kern"));
51 Real thinkern = gh_scm2double (me->get_grob_property ("thin-kern"));
52 Real hair = gh_scm2double (me->get_grob_property ("hair-thickness"));
53 Real fatline = gh_scm2double (me->get_grob_property ("thick-thickness"));
55 Real staffline = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness"));
56 Real staff_space = Staff_symbol_referencer::staff_space (me);
58 kern *= staffline;
59 thinkern *= staffline;
60 hair *= staffline;
61 fatline *= staffline;
63 Molecule thin = simple_barline (me, hair, h);
64 Molecule thick = simple_barline (me, fatline, h);
65 Molecule colon;
66 Molecule dot = Font_interface::get_default_font (me)->find_by_name ("dots-dot");
67 Real dist = ( Staff_symbol_referencer::line_count (me) & 1 ? 1 :
68 (staff_space<2 ? 2 : .5) ) * staff_space;
69 dot.translate_axis(dist/2,Y_AXIS);
70 colon.add_molecule(dot);
71 dot.translate_axis(-dist,Y_AXIS);
72 colon.add_molecule(dot);
74 Molecule m;
76 if (str == "")
78 return Lookup::blank (Box (Interval (0, 0), Interval (-h/2, h/2)));
80 else if (str == "|")
82 return thin;
84 else if (str == "|." || (h == 0 && str == ":|"))
86 m.add_at_edge (X_AXIS, LEFT, thick, 0, 0);
87 m.add_at_edge (X_AXIS, LEFT, thin, kern,0 );
89 else if (str == ".|" || (h == 0 && str == "|:"))
91 m.add_at_edge (X_AXIS, RIGHT, thick, 0, 0);
92 m.add_at_edge (X_AXIS, RIGHT, thin, kern, 0);
94 else if (str == ":|")
96 m.add_at_edge (X_AXIS, LEFT, thick, 0, 0);
97 m.add_at_edge (X_AXIS, LEFT, thin, kern, 0);
98 m.add_at_edge (X_AXIS, LEFT, colon, kern, 0);
100 else if (str == "|:")
102 m.add_at_edge (X_AXIS, RIGHT, thick, 0, 0);
103 m.add_at_edge (X_AXIS, RIGHT, thin, kern, 0);
104 m.add_at_edge (X_AXIS, RIGHT, colon, kern, 0);
106 else if (str == ":|:")
108 m.add_at_edge (X_AXIS, LEFT, thick, thinkern, 0);
109 m.add_at_edge (X_AXIS, LEFT, colon, kern, 0);
110 m.add_at_edge (X_AXIS, RIGHT, thick, kern, 0);
111 m.add_at_edge (X_AXIS, RIGHT, colon, kern, 0);
113 else if (str == ".|.")
115 m.add_at_edge (X_AXIS, LEFT, thick, thinkern, 0);
116 m.add_at_edge (X_AXIS, RIGHT, thick, kern, 0);
118 else if (str == "||")
121 should align to other side? this never appears
122 on the system-start?
124 m.add_at_edge (X_AXIS, RIGHT, thin, 0, 0);
125 m.add_at_edge (X_AXIS, RIGHT, thin, thinkern, 0);
128 return m;
131 Molecule
132 Bar_line::simple_barline (Grob *me,Real w, Real h)
134 Real blot = me->get_paper ()->get_realvar (ly_symbol2scm ("blotdiameter"));
135 return Lookup::round_filled_box (Box (Interval (0,w), Interval (-h/2, h/2)), blot);
138 MAKE_SCHEME_CALLBACK (Bar_line,before_line_breaking ,1);
141 Bar_line::before_line_breaking (SCM smob)
143 Grob*me=unsmob_grob (smob);
144 Item * item = dynamic_cast<Item*> (me);
146 SCM g = me->get_grob_property ("glyph");
147 SCM orig = g;
148 Direction bsd = item->break_status_dir ();
149 if (gh_string_p (g) && bsd)
151 SCM proc = me->get_grob_property ("break-glyph-function");
152 g = gh_call2 (proc, g, scm_int2num (bsd));
155 if (!gh_string_p (g))
157 me->set_grob_property ("molecule-callback", SCM_EOL);
158 me->set_extent (SCM_EOL, X_AXIS);
159 // leave y_extent for spanbar?
162 if (! gh_equal_p (g, orig))
163 me->set_grob_property ("glyph", g);
165 return SCM_UNSPECIFIED;
171 MAKE_SCHEME_CALLBACK (Bar_line,get_staff_bar_size,1);
173 Bar_line::get_staff_bar_size (SCM smob)
175 Grob*me = unsmob_grob (smob);
176 Real ss = Staff_symbol_referencer::staff_space (me);
177 SCM size = me->get_grob_property ("bar-size");
178 if (gh_number_p (size))
179 return gh_double2scm (gh_scm2double (size)*ss);
180 else if (Staff_symbol_referencer::get_staff_symbol (me))
183 If there is no staff-symbol, we get -1 from the next
184 calculation. That's a nonsense value, which would collapse the
185 barline so we return 0.0 in the next alternative.
187 return gh_double2scm ((Staff_symbol_referencer::line_count (me) -1) * ss);
189 else
190 return scm_int2num (0);
195 ADD_INTERFACE (Bar_line, "bar-line-interface",
196 "Bar line.\n"
197 "\n"
198 "Print a special bar symbol. It replaces the \n"
199 "regular bar symbol with a special\n"
200 "symbol. The argument @var{bartype} is a string which specifies the\n"
201 "kind of bar to print. Options are @code{:|},\n"
202 "@code{|:}, @code{:|:},\n"
203 "@code{||}, @code{|.},\n"
204 "@code{.|}, and @code{.|.}. \n"
205 "\n"
206 "These produce, respectively, a right repeat, a left repeat, a double\n"
207 "repeat, a double bar, a start bar, an end bar, and a thick double bar.\n"
208 "If @var{bartype} is set to @code{empty} then nothing is printed,\n"
209 "but a line break is allowed at that spot.\n",
210 "bar-size-procedure kern thin-kern hair-thickness thick-thickness glyph bar-size break-glyph-function");