]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
release: 1.3.152
[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--2001 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
61 SCM
62 Span_bar::center_on_spanned_callback (SCM element_smob, SCM axis)
63 {
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));
68
69   /*
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 ())
74     {
75       me->suicide ();
76       return gh_double2scm (0.0);
77     }
78   
79   return gh_double2scm (i.center ());
80 }
81
82 void
83 Span_bar::evaluate_empty (Grob*me)
84 {
85   /*
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.
89     
90    */
91   if (!gh_pair_p (me->get_grob_property ("elements")))
92     {
93       me->suicide ();
94     }
95 }
96
97 void
98 Span_bar::evaluate_glyph (Grob*me)
99 {
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))
105     {
106       me->suicide ();
107       return ; 
108     }
109
110   String type = ly_scm2string (gl);
111   
112   if (type == "|:") 
113     {
114       type = ".|";
115     }
116   else if (type== ":|")
117     {
118       type = "|.";
119     }
120   else if (type== ":|:")
121     {
122       type = ".|.";
123     }
124
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);
128 }
129
130 Interval
131 Span_bar::get_spanned_interval (Grob*me) 
132 {
133   return ly_scm2interval (Axis_group_interface::group_extent_callback (me->self_scm (), gh_int2scm (Y_AXIS))); 
134 }
135
136
137 MAKE_SCHEME_CALLBACK (Span_bar,get_bar_size,1);
138 SCM
139 Span_bar::get_bar_size (SCM smob)
140 {
141   Grob* me =  unsmob_grob (smob);
142   Interval iv (get_spanned_interval (me));
143   if (iv.empty_b ())
144     {
145       /*
146         This happens if the bars are hara-kiried from under us.
147        */
148       me->suicide ();
149       return gh_double2scm (-1);
150     }
151   return gh_double2scm (iv.length ());
152 }
153
154 void
155 Span_bar::set_interface (Grob *me)
156 {
157   Bar::set_interface (me);
158   
159   me->set_interface (ly_symbol2scm ("span-bar-interface"));
160   me->set_extent_callback (SCM_EOL, Y_AXIS);
161 }
162
163 bool
164 Span_bar::has_interface (Grob*m)
165 {
166   return m && m->has_interface (ly_symbol2scm ("span-bar-interface"));
167 }