]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
0ee3142afdb8076c6cc1ae18b750fab693c10a6f
[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 #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 void
60 Span_bar::evaluate_empty ()
61
62   if (!gh_pair_p (get_elt_property ("elements"))) 
63     {
64       set_elt_property ("transparent", SCM_BOOL_T);
65       set_empty (X_AXIS);
66       set_empty (Y_AXIS);   
67     }
68
69   SCM gl = get_elt_property ("glyph");
70   if (!gh_string_p (gl))
71     {
72       set_elt_property ("transparent", SCM_BOOL_T);
73       set_empty (X_AXIS);
74       set_empty (Y_AXIS);   
75     }
76   else {
77     String type_str = ly_scm2string (gl);
78     if (type_str == "|:") 
79     {
80       type_str= ".|";
81     }
82   else if (type_str== ":|")
83     {
84       type_str= "|.";
85     }
86   else if (type_str== ":|:")
87     {
88       type_str= ".|.";
89     }
90   }
91 }
92
93 Interval
94 Span_bar::get_spanned_interval () const
95 {
96   Interval y_int;
97
98   for (SCM s = get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
99     {
100       Score_element *bar = unsmob_element ( gh_car (s));
101
102       if (!bar)
103         continue;
104       
105       Score_element*common = common_refpoint (bar, Y_AXIS);
106
107       Interval iv (bar->extent(Y_AXIS));
108       if (!iv.empty_b ())
109         {
110           Real y = bar->relative_coordinate (common, Y_AXIS)  
111             - relative_coordinate (common, Y_AXIS);
112
113           y_int.unite (y + iv);
114         }
115     }
116   return y_int;
117 }
118
119 Interval
120 Span_bar::height_callback (Dimension_cache const *c) 
121 {
122   Span_bar * s= dynamic_cast<Span_bar*> (c->element_l ()); 
123   return s->get_spanned_interval ();
124 }
125
126 Molecule 
127 Span_bar::do_brew_molecule () const
128 {
129   Interval iv (get_spanned_interval ());
130   Molecule output;
131   SCM s = get_elt_property ("glyph");
132   if (gh_string_p (s) && !iv.empty_b())
133     {
134       output.add_molecule (lookup_l ()->bar (ly_scm2string (s),
135                                               iv.length (),
136                                               paper_l ()));
137     }
138   else
139     {
140       programming_error("Huh? My children deflated (FIXME)");
141     }
142   return output;
143 }
144
145
146
147 Span_bar::Span_bar ()
148 {
149   dim_cache_[X_AXIS]->set_callback (width_callback);
150   dim_cache_[Y_AXIS]->set_callback (height_callback);  
151 }
152