2 bar.cc -- implement Bar
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "paper-column.hh"
16 #include "molecule.hh"
17 #include "paper-def.hh"
18 #include "font-interface.hh"
20 #include "all-font-metrics.hh"
22 #include "staff-symbol-referencer.hh"
24 MAKE_SCHEME_CALLBACK(Bar,brew_molecule,1);
27 Bar::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 ("barsize-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);
41 return compound_barline (me, str, sz).smobbed_copy ();
48 Bar::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->paper_l ()->get_var ("stafflinethickness");
58 thinkern *= staffline;
62 Molecule thin = simple_barline (me, hair, h);
63 Molecule thick = simple_barline (me, fatline, h);
64 Molecule colon = Font_interface::get_default_font (me)->find_by_name ("dots-repeatcolon");
70 return Lookup::blank (Box (Interval(0, 0), Interval (-h/2, h/2)));
76 else if (str == "|." || (h == 0 && str == ":|"))
78 m.add_at_edge (X_AXIS, LEFT, thick, 0);
79 m.add_at_edge (X_AXIS, LEFT, thin, kern);
81 else if (str == ".|" || (h == 0 && str == "|:"))
83 m.add_at_edge (X_AXIS, RIGHT, thick, 0);
84 m.add_at_edge (X_AXIS, RIGHT, thin, kern);
88 m.add_at_edge (X_AXIS, LEFT, thick, 0);
89 m.add_at_edge (X_AXIS, LEFT, thin, kern);
90 m.add_at_edge (X_AXIS, LEFT, colon, kern);
94 m.add_at_edge (X_AXIS, RIGHT, thick, 0);
95 m.add_at_edge (X_AXIS, RIGHT, thin, kern);
96 m.add_at_edge (X_AXIS, RIGHT, colon, kern);
98 else if (str == ":|:")
100 m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
101 m.add_at_edge (X_AXIS, LEFT, colon, kern);
102 m.add_at_edge (X_AXIS, RIGHT, thick, kern);
103 m.add_at_edge (X_AXIS, RIGHT, colon, kern);
105 else if (str == ".|.")
107 m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
108 m.add_at_edge (X_AXIS, RIGHT, thick, kern);
110 else if (str == "||")
112 m.add_at_edge (X_AXIS, RIGHT, thin, 0);
113 m.add_at_edge (X_AXIS, RIGHT, thin, thinkern);
121 Bar::simple_barline (Grob*,Real w, Real h)
123 return Lookup::filledbox (Box (Interval(0,w), Interval(-h/2, h/2)));
126 MAKE_SCHEME_CALLBACK(Bar,before_line_breaking ,1);
129 Bar::before_line_breaking (SCM smob)
131 Grob*me=unsmob_grob (smob);
132 Item * item = dynamic_cast<Item*> (me);
134 SCM g = me->get_grob_property ("glyph");
136 Direction bsd = item->break_status_dir ();
137 if (gh_string_p (g) && bsd)
139 SCM proc = me->get_grob_property ("break-glyph-function");
140 g = gh_call2 (proc, g, gh_int2scm (bsd));
144 if (!gh_string_p (g))
146 me->set_grob_property ("molecule-callback", SCM_BOOL_T);
147 me->set_extent_callback (SCM_EOL, X_AXIS);
148 // leave y_extent for spanbar?
151 if (! gh_equal_p (g, orig))
152 me->set_grob_property ("glyph", g);
156 set a (pseudo) stem-direction, so we extra space is inserted
157 between stemup and barline.
159 TODO: should check if the barline is the leftmost object of the
165 Grob * col = item->column_l ();
166 SCM dirlist = col->get_grob_property ("dir-list");
167 SCM scmdir = gh_int2scm (-1);
168 if (scm_memq (scmdir, dirlist) == SCM_BOOL_F)
170 dirlist = gh_cons (scmdir, dirlist);
171 col->set_grob_property ("dir-list", dirlist);
175 return SCM_UNSPECIFIED;
179 Bar::set_interface (Grob*me)
181 me->set_interface (ly_symbol2scm ("bar-line-interface"));
185 Bar::has_interface (Grob*m)
187 return m && m->has_interface (ly_symbol2scm ("bar-line-interface"));
191 MAKE_SCHEME_CALLBACK(Bar,get_staff_bar_size,1);
193 Bar::get_staff_bar_size (SCM smob)
195 Grob*me = unsmob_grob (smob);
196 Real ss = Staff_symbol_referencer::staff_space (me);
197 SCM size = me->get_grob_property ("bar-size");
198 if (gh_number_p (size))
199 return gh_double2scm (gh_scm2double(size)*ss);
200 else if (Staff_symbol_referencer::staff_symbol_l (me))
203 If there is no staff-symbol, we get -1 from the next
204 calculation. That's a nonsense value, which would collapse the
205 barline so we return 0.0 in the next alternative.
207 return gh_double2scm ((Staff_symbol_referencer::line_count (me) -1) * ss);
210 return gh_int2scm (0);