]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
release: 0.1.7
[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         b = (Bar*)n->item();
40         b->spanned_i_ ++;
41     }
42     
43     spanning_l_arr_.substitute( bold , b);
44 }
45
46
47 void
48 Span_bar::set(Vertical_align_element *a)
49 {
50     add_dependency( a );
51 }
52     
53
54 Interval
55 Span_bar::do_width() const
56 {
57     return paper()->lookup_l()->bar(type_str_, 40 PT).dim.x(); // ugh
58 }
59 void
60 Span_bar::do_pre_processing()
61 {
62     if ( spanning_l_arr_.size () < 1) {
63         transparent_b_ = true;
64         empty_b_ =true;
65     } else {
66         if (type_str_ == "")
67             type_str_ = spanning_l_arr_[0]->type_str_;
68         if (type_str_ =="") {
69             transparent_b_=true;
70             empty_b_ = true;
71         } else if ( type_str_ == "|:") {
72             type_str_ = ".|";
73         } else if ( type_str_ == ":|"){
74             type_str_ = "|.";
75         }
76     }
77 }
78
79 Symbol
80 Span_bar::get_bar_sym(Real dy) const
81 {
82     return paper()->lookup_l()->bar(type_str_, dy);
83 }
84
85
86 Molecule*
87 Span_bar::brew_molecule_p()const
88 {
89     Interval y_int;
90     for (int i=0; i < spanning_l_arr_.size(); i++) {
91         Axis_group_element *common = 
92             common_group(spanning_l_arr_[i], Y_AXIS);
93         
94         Real y = spanning_l_arr_[i]->relative_coordinate(common, Y_AXIS)  
95             -relative_coordinate(common,Y_AXIS);
96
97         y_int.unite( y + spanning_l_arr_[i]->height() );
98     }
99
100     Symbol s = get_bar_sym(y_int.length());
101     Molecule*output = new Molecule(Atom(s));
102     output->translate (  y_int[-1], Y_AXIS );
103     return output;
104 }
105
106
107 IMPLEMENT_IS_TYPE_B1(Span_bar,Bar);
108
109 Span_bar::Span_bar()
110 {
111     type_str_ = "";
112 }