lilypond-1.4.4
[lilypond.git] / lily / span-bar.cc
blobfddeb470fe339f9d0f1cf980bfc3cf9273acd1e2
1 /*
2 span-bar.cc -- implement Span_bar
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "span-bar.hh"
10 #include "font-interface.hh"
11 #include "dimensions.hh"
12 #include "paper-def.hh"
13 #include "molecule.hh"
14 #include "warn.hh"
15 #include "axis-group-interface.hh"
16 #include "group-interface.hh"
17 #include "grob.hh"
18 #include "bar.hh"
20 void
21 Span_bar::add_bar (Grob*me, Grob*b)
23 Pointer_group_interface::add_element (me,"elements", b);
25 me->add_dependency (b);
28 MAKE_SCHEME_CALLBACK (Span_bar,width_callback,2);
29 SCM
30 Span_bar::width_callback (SCM element_smob, SCM scm_axis)
32 Grob *se = unsmob_grob (element_smob);
33 Axis a = (Axis) gh_scm2int (scm_axis);
34 assert (a == X_AXIS);
35 String gl = ly_scm2string (se->get_grob_property ("glyph"));
38 urg.
40 Molecule m = Bar::compound_barline (se, gl, 40 PT);
42 return ly_interval2scm (m.extent (X_AXIS));
45 MAKE_SCHEME_CALLBACK (Span_bar,before_line_breaking,1);
46 SCM
47 Span_bar::before_line_breaking (SCM smob)
49 evaluate_empty (unsmob_grob (smob));
50 evaluate_glyph (unsmob_grob (smob));
53 no need to call Bar::before_line_breaking (), because the info
54 in ELEMENTS already has been procced by Bar::before_line_breaking ().
56 return SCM_UNSPECIFIED;
59 MAKE_SCHEME_CALLBACK (Span_bar,center_on_spanned_callback,2);
61 SCM
62 Span_bar::center_on_spanned_callback (SCM element_smob, SCM axis)
64 Grob *me = unsmob_grob (element_smob);
65 Axis a = (Axis) gh_scm2int (axis);
66 assert (a == Y_AXIS);
67 Interval i (get_spanned_interval (me));
70 Bar::brew_molecule delivers a barline of y-extent (-h/2,h/2), so
71 we have to translate ourselves to be in the center of the
72 interval that we span. */
73 if (i.empty_b ())
75 me->suicide ();
76 return gh_double2scm (0.0);
79 return gh_double2scm (i.center ());
82 void
83 Span_bar::evaluate_empty (Grob*me)
86 TODO: filter all hara-kiried out of ELEMENS list, and then
87 optionally do suicide. Call this cleanage function from
88 center_on_spanned_callback () as well.
91 if (!gh_pair_p (me->get_grob_property ("elements")))
93 me->suicide ();
97 void
98 Span_bar::evaluate_glyph (Grob*me)
100 SCM elts = me->get_grob_property ("elements");
101 Grob * b = unsmob_grob (gh_car (elts));
102 SCM glsym =ly_symbol2scm ("glyph");
103 SCM gl =b ->get_grob_property (glsym);
104 if (!gh_string_p (gl))
106 me->suicide ();
107 return ;
110 String type = ly_scm2string (gl);
112 if (type == "|:")
114 type = ".|";
116 else if (type== ":|")
118 type = "|.";
120 else if (type== ":|:")
122 type = ".|.";
125 gl = ly_str02scm (type.ch_C ());
126 if (scm_equal_p (me->get_grob_property (glsym), gl) != SCM_BOOL_T)
127 me->set_grob_property (glsym, gl);
130 Interval
131 Span_bar::get_spanned_interval (Grob*me)
133 return ly_scm2interval (Axis_group_interface::group_extent_callback (me->self_scm (), gh_int2scm (Y_AXIS)));
137 MAKE_SCHEME_CALLBACK (Span_bar,get_bar_size,1);
139 Span_bar::get_bar_size (SCM smob)
141 Grob* me = unsmob_grob (smob);
142 Interval iv (get_spanned_interval (me));
143 if (iv.empty_b ())
146 This happens if the bars are hara-kiried from under us.
148 me->suicide ();
149 return gh_double2scm (-1);
151 return gh_double2scm (iv.length ());
154 void
155 Span_bar::set_interface (Grob *me)
157 Bar::set_interface (me);
159 me->set_interface (ly_symbol2scm ("span-bar-interface"));
160 me->set_extent_callback (SCM_EOL, Y_AXIS);
163 bool
164 Span_bar::has_interface (Grob*m)
166 return m && m->has_interface (ly_symbol2scm ("span-bar-interface"));