]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
release: 1.1.24
[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--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "span-bar.hh"
10 #include "lookup.hh"
11 #include "dimensions.hh"
12 #include "atom.hh"
13 #include "paper-def.hh"
14 #include "molecule.hh"
15 #include "align-element.hh"
16
17 void
18 Span_bar::add_bar (Bar*b)
19 {
20   spanning_l_arr_.push (b);
21   add_dependency (b);
22 }
23
24 void
25 Span_bar::do_substitute_dependency (Score_element*o, Score_element*n)
26 {
27   spanning_l_arr_.unordered_substitute (o, n);
28 }
29
30 void
31 Span_bar::set_align (Align_element *a)
32 {
33   add_dependency (a);
34 }
35
36 Interval
37 Span_bar::do_width () const
38 {
39   Molecule m = lookup_l ()->bar (type_str_, 40 PT);
40   
41   return m.extent (X_AXIS);
42 }
43
44 void
45 Span_bar::do_pre_processing ()
46 {
47   Bar::do_pre_processing ();
48   
49   evaluate_empty ();
50 }
51
52 void
53 Span_bar::do_post_processing ()
54 {
55   Bar::do_post_processing ();
56 }
57
58 void
59 Span_bar::evaluate_empty ()
60
61   if (spanning_l_arr_.size () < 1) 
62     {
63       transparent_b_ = true;
64       set_empty (true);   
65     }
66   if (type_str_.empty_b ()) 
67     {
68       transparent_b_=true;
69       set_empty (true);
70     }
71   else if (type_str_ == "|:") 
72     {
73       type_str_ = ".|";
74     }
75   else if (type_str_ == ":|")
76     {
77       type_str_ = "|.";
78     }
79   else if (type_str_ == ":|:")
80     {
81       type_str_ = ".|.";
82     }
83 }
84
85 Molecule
86 Span_bar::get_bar_sym (Real dy) const
87 {
88   if (dy < paper ()->staffheight_f () / 2)
89     return Atom ();
90   
91   return lookup_l ()->bar (type_str_, dy);
92 }
93
94 Molecule*
95 Span_bar::do_brew_molecule_p () const
96 {
97   Interval y_int;
98   for (int i=0; i < spanning_l_arr_.size (); i++) 
99     {
100       Dimension_cache*common = 
101         common_group (spanning_l_arr_[i], Y_AXIS);
102         
103       Real y = spanning_l_arr_[i]->dim_cache_[Y_AXIS].relative_coordinate (common)  
104         -dim_cache_[Y_AXIS].relative_coordinate (common);
105
106       y_int.unite (y + spanning_l_arr_[i]->extent(Y_AXIS));
107     }
108
109   Molecule*output = new Molecule (get_bar_sym (y_int.length ()));
110   output->translate_axis (y_int.center (), Y_AXIS);
111   return output;
112 }
113
114
115
116 Span_bar::Span_bar ()
117 {
118   type_str_ = "";
119 }