]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
release: 1.1.18
[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   return lookup_l ()->bar (type_str_, 40 PT).dim_.x (); // ugh
40 }
41
42 void
43 Span_bar::do_pre_processing ()
44 {
45   Bar::do_pre_processing ();
46   
47   evaluate_empty ();
48 }
49
50 void
51 Span_bar::do_post_processing ()
52 {
53   Bar::do_post_processing ();
54 }
55
56 void
57 Span_bar::evaluate_empty ()
58
59   if (spanning_l_arr_.size () < 1) 
60     {
61       transparent_b_ = true;
62       set_empty (true);   
63     }
64   if (type_str_.empty_b ()) 
65     {
66       transparent_b_=true;
67       set_empty (true);
68     }
69   else if (type_str_ == "|:") 
70     {
71       type_str_ = ".|";
72     }
73   else if (type_str_ == ":|")
74     {
75       type_str_ = "|.";
76     }
77   else if (type_str_ == ":|:")
78     {
79       type_str_ = ".|.";
80     }
81 }
82
83 Atom
84 Span_bar::get_bar_sym (Real dy) const
85 {
86   if (dy < paper ()->staffheight_f () / 2)
87     return Atom ();
88   
89   return lookup_l ()->bar (type_str_, dy);
90 }
91
92 Molecule*
93 Span_bar::do_brew_molecule_p () const
94 {
95   Interval y_int;
96   for (int i=0; i < spanning_l_arr_.size (); i++) 
97     {
98       Dimension_cache*common = 
99         common_group (spanning_l_arr_[i], Y_AXIS);
100         
101       Real y = spanning_l_arr_[i]->dim_cache_[Y_AXIS].relative_coordinate (common)  
102         -dim_cache_[Y_AXIS].relative_coordinate (common);
103
104       y_int.unite (y + spanning_l_arr_[i]->extent(Y_AXIS));
105     }
106
107   Atom s = get_bar_sym (y_int.length ());
108   Molecule*output = new Molecule (Atom (s));
109   output->translate_axis (y_int.center (), Y_AXIS);
110   return output;
111 }
112
113
114
115 Span_bar::Span_bar ()
116 {
117   type_str_ = "";
118 }