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 "dimensions.hh"
12 #include "score-element.hh"
15 #include "molecule.hh"
16 #include "paper-def.hh"
19 #include "all-font-metrics.hh"
21 #include "staff-symbol-referencer.hh"
23 MAKE_SCHEME_CALLBACK(Bar,brew_molecule);
26 Bar::brew_molecule (SCM smob)
28 Score_element * me = unsmob_element (smob);
30 SCM s = me->get_elt_property ("glyph");
31 SCM barsiz_proc = me->get_elt_property ("barsize-procedure");
32 if (gh_string_p (s) && gh_procedure_p (barsiz_proc))
34 String str =ly_scm2string (s);
35 SCM siz = gh_call1 (barsiz_proc, me->self_scm ());
36 Real sz = gh_scm2double (siz);
40 return compound_barline (me, str, sz).create_scheme ();
47 Bar::compound_barline (Score_element*me, String str, Real h)
49 Real kern = gh_scm2double (me->get_elt_property ("kern"));
50 Real thinkern = gh_scm2double (me->get_elt_property ("thin-kern"));
51 Real hair = gh_scm2double (me->get_elt_property ("hair-thickness"));
52 Real fatline = gh_scm2double (me->get_elt_property ("thick-thickness"));
54 Real staffline = me->paper_l ()->get_var ("stafflinethickness");
57 thinkern *= staffline;
61 Molecule thin = simple_barline (me, hair, h);
62 Molecule thick = simple_barline (me, fatline, h);
63 Molecule colon = me->lookup_l ()->afm_find ("dots-repeatcolon");
69 return me->lookup_l ()->blank (Box (Interval(0, 0), Interval (-h/2, h/2)));
71 if (str == "scorepostbreak")
73 return simple_barline (me, me->paper_l ()->get_var ("barthick_score"), h);
81 m.add_at_edge (X_AXIS, LEFT, thick, 0);
82 m.add_at_edge (X_AXIS, LEFT, thin, kern);
86 m.add_at_edge (X_AXIS, RIGHT, thick, 0);
87 m.add_at_edge (X_AXIS, RIGHT, thin, kern);
91 m.add_at_edge (X_AXIS, LEFT, thick, 0);
92 m.add_at_edge (X_AXIS, LEFT, thin, kern);
93 m.add_at_edge (X_AXIS, LEFT, colon, kern);
97 m.add_at_edge (X_AXIS, RIGHT, thick, 0);
98 m.add_at_edge (X_AXIS, RIGHT, thin, kern);
99 m.add_at_edge (X_AXIS, RIGHT, colon, kern);
101 else if (str == ":|:")
103 m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
104 m.add_at_edge (X_AXIS, LEFT, colon, kern);
105 m.add_at_edge (X_AXIS, RIGHT, thick, kern);
106 m.add_at_edge (X_AXIS, RIGHT, colon, kern);
108 else if (str == ".|.")
110 m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
111 m.add_at_edge (X_AXIS, RIGHT, thick, kern);
113 else if (str == "||")
115 m.add_at_edge (X_AXIS, RIGHT, thin, 0);
116 m.add_at_edge (X_AXIS, RIGHT, thin, thinkern);
124 Bar::simple_barline (Score_element*me,Real w, Real h)
126 return me->lookup_l ()->filledbox (Box (Interval(0,w), Interval(-h/2, h/2)));
129 MAKE_SCHEME_CALLBACK(Bar,before_line_breaking );
132 Bar::before_line_breaking (SCM smob)
134 Score_element*me=unsmob_element (smob);
135 Item * item = dynamic_cast<Item*> (me);
137 SCM g = me->get_elt_property ("glyph");
139 Direction bsd = item->break_status_dir ();
144 SCM breakdir = gh_int2scm (bsd);
145 g = scm_eval (gh_list (ly_symbol2scm ("break-barline"),
156 if (!gh_string_p (g))
158 me->set_elt_property ("molecule-callback", SCM_BOOL_T);
159 me->set_extent_callback (0, X_AXIS);
160 // leave y_extent for spanbar?
162 else if (! gh_equal_p (g, orig))
163 me->set_elt_property ("glyph", g);
166 return SCM_UNSPECIFIED;
170 Bar::set_interface (Score_element*me)
172 me->set_elt_property ("interfaces",
173 gh_cons (ly_symbol2scm ("bar-interface"), me->get_elt_property ("interfaces")));
177 Bar::has_interface (Score_element*m)
179 return m && m->has_interface (ly_symbol2scm ("bar-interface"));
183 MAKE_SCHEME_CALLBACK(Bar,get_staff_bar_size);
185 Bar::get_staff_bar_size (SCM smob)
187 Score_element*me = unsmob_element (smob);
188 Real ss = Staff_symbol_referencer::staff_space (me);
189 SCM size = me->get_elt_property ("bar-size");
190 if (gh_number_p (size))
191 return gh_double2scm (gh_scm2double(size)*ss);
194 return gh_double2scm ((Staff_symbol_referencer::line_count (me) -1) * ss);