]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
release: 0.1.11
[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 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "dimen.hh"
10 #include "span-bar.hh"
11 #include "lookup.hh"
12 #include "symbol.hh"
13 #include "paper-def.hh"
14 #include "molecule.hh"
15 #include "vertical-align-elem.hh"
16
17 void
18 Span_bar::add (Bar*b)
19 {
20   b->spanned_i_ ++;
21   spanning_l_arr_.push (b);
22   add_dependency (b);
23 }
24
25
26
27 void
28 Span_bar::do_substitute_dependency (Score_elem*o, Score_elem*n)
29 {
30   Bar * bold = 0;
31   if  (o->is_type_b (Bar::static_name())) 
32         bold = (Bar*)o->item();
33   else
34         return;
35
36   bold->spanned_i_ --;
37   Bar * b =0;
38   if (n && n->is_type_b (Bar::static_name())) 
39     {
40         b = (Bar*)n->item();
41         b->spanned_i_ ++;
42     }
43   
44   spanning_l_arr_.substitute (bold , b);
45 }
46
47
48 void
49 Span_bar::set (Vertical_align_element *a)
50 {
51   add_dependency (a);
52 }
53   
54
55 Interval
56 Span_bar::do_width() const
57 {
58   return paper()->lookup_l ()->bar (type_str_, 40 PT).dim.x (); // ugh
59 }
60 void
61 Span_bar::do_pre_processing()
62 {
63   if (spanning_l_arr_.size() < 1) 
64     {
65         transparent_b_ = true;
66         empty_b_ =true;
67     }
68   else 
69     {
70         if (type_str_ == "")
71             type_str_ = spanning_l_arr_[0]->type_str_;
72         if (type_str_ =="") 
73           {
74             transparent_b_=true;
75             empty_b_ = true;
76           }
77         else if (type_str_ == "|:") 
78           {
79             type_str_ = ".|";
80           }
81         else if (type_str_ == ":|")
82           {
83             type_str_ = "|.";
84           }
85     }
86 }
87
88 Symbol
89 Span_bar::get_bar_sym (Real dy) const
90 {
91   return paper()->lookup_l ()->bar (type_str_, dy);
92 }
93
94
95 Molecule*
96 Span_bar::brew_molecule_p() const
97 {
98   Interval y_int;
99   for (int i=0; i < spanning_l_arr_.size(); i++) 
100     {
101         Axis_group_element *common = 
102             common_group (spanning_l_arr_[i], Y_AXIS);
103         
104         Real y = spanning_l_arr_[i]->relative_coordinate (common, Y_AXIS)  
105             -relative_coordinate (common,Y_AXIS);
106
107         y_int.unite (y + spanning_l_arr_[i]->height());
108     }
109
110   Symbol s = get_bar_sym (y_int.length());
111   Molecule*output = new Molecule (Atom (s));
112   output->translate (y_int[-1], Y_AXIS);
113   return output;
114 }
115
116
117 IMPLEMENT_IS_TYPE_B1(Span_bar,Bar);
118
119 Span_bar::Span_bar()
120 {
121   type_str_ = "";
122 }