]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
patch::: 1.3.18.jcn3
[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--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "dimension-cache.hh"
9 #include "span-bar.hh"
10 #include "lookup.hh"
11 #include "dimensions.hh"
12 #include "paper-def.hh"
13 #include "molecule.hh"
14 #include "align-element.hh"
15 #include "warn.hh"
16 #include "group-interface.hh"
17
18
19 void
20 Span_bar::add_bar (Score_element*b)
21 {
22   Group_interface gi (this);
23   gi.add_element (b);
24
25   add_dependency (b);
26 }
27
28
29 Interval
30 Span_bar::width_callback (Dimension_cache const * c)
31 {
32   Span_bar*  s= dynamic_cast<Span_bar*> (c->element_l ());  
33   String gl = ly_scm2string (s->get_elt_property ("glyph"));
34   
35   Molecule m = s->lookup_l ()->bar (gl, 40 PT, s->paper_l ());
36   
37   return m.extent (X_AXIS);
38 }
39
40 void
41 Span_bar::do_pre_processing ()
42 {
43   Bar::do_pre_processing ();
44   
45   evaluate_empty ();
46   
47   //  set_empty (false, Y_AXIS); // a hack to make mark scripts work.
48 }
49
50 void
51 Span_bar::do_post_processing ()
52 {
53   Bar::do_post_processing ();
54   Interval i(get_spanned_interval ());
55
56   translate_axis (i.center (), Y_AXIS);
57
58   /*
59     {[ stacking shift
60     ugh
61   */
62   SCM me = get_elt_property ("glyph");
63   if (gh_string_p (me) && ly_scm2string (me) == "bracket")
64     {
65       SCM e = get_elt_property ("other");
66       if (e != SCM_UNDEFINED)
67         {
68           assert (SMOB_IS_TYPE_B (Score_element, e));
69           Score_element* se = SMOB_TO_TYPE (Score_element, e);
70           SCM her = se->get_elt_property ("glyph");
71 #if 0
72           // urg x-extent broken?
73           if (gh_string_p (her) && ly_scm2string (her) == "brace")
74             se->translate_axis (-extent (X_AXIS).length (), X_AXIS);
75 #else
76           if (gh_string_p (her) && ly_scm2string (her) == "brace"
77               && !to_boolean (get_elt_property ("transparent")))
78             se->translate_axis (-paper_l ()->get_var ("interline"), X_AXIS);
79 #endif 
80         }
81     }
82 }
83
84 void
85 Span_bar::evaluate_empty ()
86
87   if (!gh_pair_p (get_elt_property ("elements"))) 
88     {
89       set_elt_property ("transparent", SCM_BOOL_T);
90       set_empty (X_AXIS);
91       set_empty (Y_AXIS);   
92     }
93
94   SCM gl = get_elt_property ("glyph");
95   if (!gh_string_p (gl))
96     {
97       set_elt_property ("transparent", SCM_BOOL_T);
98       set_empty (X_AXIS);
99       set_empty (Y_AXIS);   
100     }
101   else {
102     String type_str = ly_scm2string (gl);
103     if (type_str == "|:") 
104     {
105       type_str= ".|";
106     }
107   else if (type_str== ":|")
108     {
109       type_str= "|.";
110     }
111   else if (type_str== ":|:")
112     {
113       type_str= ".|.";
114     }
115   }
116 }
117
118 Interval
119 Span_bar::get_spanned_interval () const
120 {
121   Interval y_int;
122
123   for (SCM s = get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
124     {
125       Score_element *bar = unsmob_element ( gh_car (s));
126
127       if (!bar)
128         continue;
129       
130       Score_element*common = common_refpoint (bar, Y_AXIS);
131
132       Interval iv (bar->extent(Y_AXIS));
133       if (!iv.empty_b ())
134         {
135           Real y = bar->relative_coordinate (common, Y_AXIS)  
136             - relative_coordinate (common, Y_AXIS);
137
138           y_int.unite (y + iv);
139         }
140     }
141   return y_int;
142 }
143
144 Interval
145 Span_bar::height_callback (Dimension_cache const *c) 
146 {
147   Span_bar * s= dynamic_cast<Span_bar*> (c->element_l ()); 
148   return s->get_spanned_interval ();
149 }
150
151 Molecule*
152 Span_bar::do_brew_molecule_p () const
153 {
154   Interval iv (get_spanned_interval ());
155   Molecule*output = new Molecule;
156   SCM s = get_elt_property ("glyph");
157   if (gh_string_p (s) && !iv.empty_b())
158     {
159       output->add_molecule (lookup_l ()->bar (ly_scm2string (s),
160                                               iv.length (),
161                                               paper_l ()));
162     }
163   else
164     {
165       programming_error("Huh? My children deflated (FIXME)");
166     }
167   return output;
168 }
169
170
171
172 Span_bar::Span_bar ()
173 {
174   dim_cache_[X_AXIS]->set_callback (width_callback);
175   dim_cache_[Y_AXIS]->set_callback (height_callback);  
176 }
177