]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
release: 1.3.110
[lilypond.git] / lily / span-bar.cc
1 /*
2   span-bar.cc -- implement Span_bar
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
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"
19
20 void
21 Span_bar::add_bar (Grob*me, Grob*b)
22 {
23   Pointer_group_interface::add_element (me,"elements", b);
24
25   me->add_dependency (b);
26 }
27
28 MAKE_SCHEME_CALLBACK(Span_bar,width_callback,2);
29 SCM
30 Span_bar::width_callback (SCM element_smob, SCM scm_axis)
31 {
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"));
36
37   /*
38     urg.
39    */
40   Molecule m = Bar::compound_barline (se, gl, 40 PT);
41   
42   return ly_interval2scm ( m.extent (X_AXIS));
43 }
44
45 MAKE_SCHEME_CALLBACK(Span_bar,before_line_breaking,1);
46 SCM
47 Span_bar::before_line_breaking (SCM smob)
48 {
49   evaluate_empty (unsmob_grob (smob));
50   evaluate_glyph (unsmob_grob (smob));
51
52   /*
53     no need to call   Bar::before_line_breaking (), because the info
54     in ELEMENTS already has been procced by Bar::before_line_breaking().
55    */
56   return SCM_UNSPECIFIED;
57 }
58
59 MAKE_SCHEME_CALLBACK(Span_bar,center_on_spanned_callback,2);
60 SCM
61 Span_bar::center_on_spanned_callback (SCM element_smob, SCM axis)
62 {
63   Grob *me = unsmob_grob (element_smob);
64   Axis a = (Axis) gh_scm2int (axis);
65   assert (a == Y_AXIS);
66   Interval i (get_spanned_interval (me));
67
68   /*
69     Bar::brew_molecule delivers a barline of y-extent (-h/2,h/2), so
70     we have to translate ourselves to be in the center of the 
71     interval that we span.  */
72
73   return gh_double2scm (i.center ());
74 }
75
76 void
77 Span_bar::evaluate_empty (Grob*me)
78 {
79   /*
80     TODO: filter all hara-kiried out of ELEMENS list, and then
81     optionally do suicide. Call this cleanage function from
82     center_on_spanned_callback() as well.
83     
84    */
85   if (!gh_pair_p (me->get_grob_property ("elements")))
86     {
87       me->suicide ();
88     }
89 }
90
91 void
92 Span_bar::evaluate_glyph (Grob*me)
93 {
94   SCM elts = me->get_grob_property ("elements");
95   Grob * b = unsmob_grob (gh_car (elts));
96   SCM glsym =ly_symbol2scm ("glyph");
97   SCM gl =b ->get_grob_property (glsym);
98   if (!gh_string_p (gl))
99     {
100       me->suicide ();
101       return ; 
102     }
103
104   String type = ly_scm2string (gl);
105   
106   if (type == "|:") 
107     {
108       type = ".|";
109     }
110   else if (type== ":|")
111     {
112       type = "|.";
113     }
114   else if (type== ":|:")
115     {
116       type = ".|.";
117     }
118
119   gl = ly_str02scm (type.ch_C());
120   if (scm_equal_p (me->get_grob_property (glsym), gl) != SCM_BOOL_T)
121     me->set_grob_property (glsym, gl);
122 }
123
124 Interval
125 Span_bar::get_spanned_interval (Grob*me) 
126 {
127   return ly_scm2interval (Axis_group_interface::group_extent_callback (me->self_scm(), gh_int2scm (Y_AXIS))); 
128 }
129
130
131 MAKE_SCHEME_CALLBACK(Span_bar,get_bar_size,1);
132 SCM
133 Span_bar::get_bar_size (SCM smob)
134 {
135   Grob* me =  unsmob_grob (smob);
136   Interval iv (get_spanned_interval (me));
137   if (iv.empty_b ())
138     {
139       /*
140         This happens if the bars are hara-kiried from under us.
141        */
142       me->suicide ();
143       return gh_double2scm (-1);
144     }
145   return gh_double2scm (iv.length ());
146 }
147
148 void
149 Span_bar::set_interface (Grob *me)
150 {
151   Bar::set_interface (me);
152   
153   me->set_interface (ly_symbol2scm ("span-bar-interface"));
154   me->set_extent_callback (SCM_EOL, Y_AXIS);
155 }
156
157 bool
158 Span_bar::has_interface (Grob*m)
159 {
160   return m && m->has_interface (ly_symbol2scm ("span-bar-interface"));
161 }