lilypond-1.3.69
[lilypond.git] / lily / span-bar.cc
blobeab329b9eaec5ed68b7ba7134462f14449e04807
1 /*
2 span-bar.cc -- implement Span_bar
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "span-bar.hh"
10 #include "lookup.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 "score-element.hh"
18 #include "bar.hh"
20 void
21 Span_bar::add_bar (Score_element*me, Score_element*b)
23 Pointer_group_interface gi (me);
24 gi.add_element (b);
26 me->add_dependency (b);
29 Interval
30 Span_bar::width_callback (Score_element *se, Axis )
32 String gl = ly_scm2string (se->get_elt_property ("glyph"));
35 urg.
37 Molecule m = Bar::compound_barline (se, gl, 40 PT);
39 return m.extent (X_AXIS);
42 MAKE_SCHEME_CALLBACK(Span_bar,before_line_breaking);
43 SCM
44 Span_bar::before_line_breaking (SCM smob)
46 Bar::before_line_breaking (smob);
48 evaluate_empty (unsmob_element (smob));
50 return SCM_UNDEFINED;
53 Real
54 Span_bar::center_on_spanned_callback (Score_element * me, Axis a)
56 assert (a == Y_AXIS);
57 Interval i (get_spanned_interval (me));
60 Bar::brew_molecule delivers a barline of y-extent (-h/2,h/2), so
61 we have to translate ourselves to be in the center of the
62 interval that we span. */
64 return i.center ();
67 void
68 Span_bar::evaluate_empty (Score_element*me)
70 if (!gh_pair_p (me->get_elt_property ("elements")))
72 me->suicide ();
75 SCM gl = me->get_elt_property ("glyph");
76 if (!gh_string_p (gl))
78 me->suicide ();
79 return ;
81 else {
82 String type_str = ly_scm2string (gl);
83 String orig = type_str;
84 if (type_str == "|:")
86 type_str= ".|";
88 else if (type_str== ":|")
90 type_str= "|.";
92 else if (type_str== ":|:")
94 type_str= ".|.";
96 if (orig != type_str)
97 me->set_elt_property ("glyph", ly_str02scm (type_str.ch_C()));
101 Interval
102 Span_bar::get_spanned_interval (Score_element*me)
104 return Axis_group_interface::group_extent_callback (me, Y_AXIS);
108 MAKE_SCHEME_CALLBACK(Span_bar,get_bar_size);
110 Span_bar::get_bar_size (SCM smob)
112 Score_element* me = unsmob_element (smob);
113 Interval iv (get_spanned_interval (me));
114 if (iv.empty_b ())
116 programming_error("Huh? My children deflated (FIXME)");
117 iv = Interval (0,0);
119 return gh_double2scm (iv.length ());
121 void
122 Span_bar::set_interface (Score_element *me)
124 Bar::set_interface (me);
126 Pointer_group_interface(me).set_interface ();
127 me->set_extent_callback (width_callback, X_AXIS);
128 me->add_offset_callback (center_on_spanned_callback, Y_AXIS);
129 me->set_interface (ly_symbol2scm ("span-bar-interface"));
130 me->set_extent_callback (0, Y_AXIS);
133 bool
134 Span_bar::has_interface (Score_element*m)
136 return m && m->has_interface (ly_symbol2scm ("span-bar-interface"));