]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
release: 0.1.16
[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 "atom.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
61 void
62 Span_bar::do_pre_processing()
63 {
64   if (spanning_l_arr_.size() < 1) 
65     {
66       transparent_b_ = true;
67       set_empty (true);   
68     }
69   else 
70     {
71       if (type_str_.empty_b ())
72         type_str_ = spanning_l_arr_[0]->type_str_;
73       if (type_str_.empty_b ()) 
74         {
75           transparent_b_=true;
76           set_empty (true);
77         }
78       else if (type_str_ == "|:") 
79         {
80           type_str_ = ".|";
81         }
82       else if (type_str_ == ":|")
83         {
84           type_str_ = "|.";
85         }
86     }
87 }
88
89 Atom
90 Span_bar::get_bar_sym (Real dy) const
91 {
92   return paper()->lookup_l ()->bar (type_str_, dy);
93 }
94
95
96 Molecule*
97 Span_bar::brew_molecule_p() const
98 {
99   Interval y_int;
100   for (int i=0; i < spanning_l_arr_.size(); i++) 
101     {
102       Axis_group_element *common = 
103         common_group (spanning_l_arr_[i], Y_AXIS);
104         
105       Real y = spanning_l_arr_[i]->relative_coordinate (common, Y_AXIS)  
106         -relative_coordinate (common,Y_AXIS);
107
108       y_int.unite (y + spanning_l_arr_[i]->height());
109     }
110
111   Atom s = get_bar_sym (y_int.length());
112   Molecule*output = new Molecule (Atom (s));
113   output->translate (y_int[-1], Y_AXIS);
114   return output;
115 }
116
117
118 IMPLEMENT_IS_TYPE_B1(Span_bar,Bar);
119
120 Span_bar::Span_bar()
121 {
122   type_str_ = "";
123 }