]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
65b57f96205dd310f23fd64c48c0c1a2f6e641a0
[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
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
17 void
18 Span_bar::add_bar (Score_element*b)
19 {
20   spanning_l_arr_.push (b);
21   add_dependency (b);
22 }
23
24 void
25 Span_bar::do_substitute_element_pointer (Score_element*o, Score_element*n)
26 {
27   spanning_l_arr_.unordered_substitute (o, n);
28 }
29
30
31 Interval
32 Span_bar::do_width () const
33 {
34   Molecule m = lookup_l ()->bar (type_str_, 40 PT, paper_l ());
35   
36   return m.extent (X_AXIS);
37 }
38
39 void
40 Span_bar::do_pre_processing ()
41 {
42   Bar::do_pre_processing ();
43   
44   evaluate_empty ();
45   
46   dim_cache_[Y_AXIS]->set_empty (false); // a hack to make mark scripts work.
47 }
48
49 void
50 Span_bar::do_post_processing ()
51 {
52   Bar::do_post_processing ();
53 }
54
55 void
56 Span_bar::evaluate_empty ()
57
58   if (spanning_l_arr_.size () < 1) 
59     {
60       set_elt_property (transparent_scm_sym, SCM_BOOL_T);
61       set_empty (true);   
62     }
63   if (type_str_.empty_b ()) 
64     {
65       set_elt_property (transparent_scm_sym, SCM_BOOL_T);
66       set_empty (true);
67     }
68   else if (type_str_ == "|:") 
69     {
70       type_str_ = ".|";
71     }
72   else if (type_str_ == ":|")
73     {
74       type_str_ = "|.";
75     }
76   else if (type_str_ == ":|:")
77     {
78       type_str_ = ".|.";
79     }
80 }
81
82 Interval
83 Span_bar::get_spanned_interval () const
84 {
85   Interval y_int;
86   for (int i=0; i < spanning_l_arr_.size (); i++) 
87     {
88       Dimension_cache*common = 
89         common_group (spanning_l_arr_[i], Y_AXIS);
90         
91       Real y = spanning_l_arr_[i]->dim_cache_[Y_AXIS]->relative_coordinate (common)  
92         -dim_cache_[Y_AXIS]->relative_coordinate (common);
93
94       y_int.unite (y + spanning_l_arr_[i]->extent(Y_AXIS));
95     }
96   return y_int;
97 }
98
99 Interval
100 Span_bar::do_height () const
101 {
102   return get_spanned_interval ();
103 }
104
105 Molecule*
106 Span_bar::do_brew_molecule_p () const
107 {
108   Interval iv (get_spanned_interval ());
109   Molecule*output = new Molecule;
110   if (!iv.empty_b())
111     {
112       output->add_molecule (lookup_l ()->bar (type_str_, iv.length (), paper_l ()));
113       output->translate_axis (iv.center (), Y_AXIS);
114     }
115   else
116     {
117       programming_error("Huh? My children deflated (FIXME)");
118     }
119   return output;
120 }
121
122
123
124 Span_bar::Span_bar ()
125 {
126   type_str_ = "";
127 }