]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
patch::: 1.3.41.mwd1: Repeat bar questions and patches
[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--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "dimension-cache.hh"
9 #include "span-bar.hh"
10 #include "lookup.hh"
11 #include "dimensions.hh"
12 #include "paper-def.hh"
13 #include "molecule.hh"
14 #include "warn.hh"
15 #include "group-interface.hh"
16
17
18 void
19 Span_bar::add_bar (Score_element*b)
20 {
21   Group_interface gi (this);
22   gi.add_element (b);
23
24   add_dependency (b);
25 }
26
27
28 Interval
29 Span_bar::width_callback (Dimension_cache const * c)
30 {
31   Span_bar*  s= dynamic_cast<Span_bar*> (c->element_l ());  
32   String gl = ly_scm2string (s->get_elt_property ("glyph"));
33
34   /*urg.
35    */
36   Molecule m = s->compound_barline (gl, 40 PT);
37   
38   return m.extent (X_AXIS);
39 }
40
41 void
42 Span_bar::before_line_breaking ()
43 {
44   evaluate_empty ();
45   
46   Bar::before_line_breaking ();
47   
48   //  set_empty (false, Y_AXIS); // a hack to make mark scripts work.
49 }
50
51 void
52 Span_bar::after_line_breaking ()
53 {
54   Bar::after_line_breaking ();
55   SCM s = get_elt_property ("collapse-height");
56   if (gh_number_p (s)
57       && get_spanned_interval ().length () < gh_scm2double (s))
58     {
59       set_elt_property ("transparent", SCM_BOOL_T);
60       set_empty (X_AXIS);
61       set_empty (Y_AXIS);   
62     }
63
64   Interval i (get_spanned_interval ());
65   translate_axis (i.center (), Y_AXIS);
66 }
67
68 void
69 Span_bar::evaluate_empty ()
70
71   if (!gh_pair_p (get_elt_property ("elements")))
72   {
73     set_elt_property ("transparent", SCM_BOOL_T);
74     set_empty (X_AXIS);
75     set_empty (Y_AXIS);   
76   }
77   
78   SCM gl = get_elt_property ("glyph");
79   if (!gh_string_p (gl))
80     {
81       set_elt_property ("transparent", SCM_BOOL_T);
82       set_empty (X_AXIS);
83       set_empty (Y_AXIS);   
84     }
85   else {
86     String type_str = ly_scm2string (gl);
87     if (type_str == "|:") 
88     {
89       type_str= ".|";
90     }
91   else if (type_str== ":|")
92     {
93       type_str= "|.";
94     }
95   else if (type_str== ":|:")
96     {
97       type_str= ";|;";
98     }
99     set_elt_property ("glyph", ly_str02scm (type_str.ch_C ()));
100   }
101 }
102
103 Interval
104 Span_bar::get_spanned_interval () const
105 {
106   Interval y_int;
107
108   for (SCM s = get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
109     {
110       Score_element *bar = unsmob_element ( gh_car (s));
111
112       if (!bar)
113         continue;
114       
115       Score_element*common = common_refpoint (bar, Y_AXIS);
116
117       Interval iv (bar->extent(Y_AXIS));
118       if (!iv.empty_b ())
119         {
120           Real y = bar->relative_coordinate (common, Y_AXIS)  
121             - relative_coordinate (common, Y_AXIS);
122
123           y_int.unite (y + iv);
124         }
125     }
126   
127   return y_int;
128 }
129
130 Interval
131 Span_bar::height_callback (Dimension_cache const *c) 
132 {
133   Span_bar * s= dynamic_cast<Span_bar*> (c->element_l ()); 
134   return s->get_spanned_interval ();
135 }
136
137 Real
138 Span_bar::get_bar_size () const
139 {
140    Interval iv (get_spanned_interval ());
141    if (iv.empty_b ())
142      {
143        programming_error("Huh? My children deflated (FIXME)");
144        iv = Interval (0,0);
145      }
146    return iv.length ();
147 }
148
149 Span_bar::Span_bar ()
150 {
151   group (this).set_interface ();
152   dim_cache_[X_AXIS]->set_extent_callback (width_callback);
153   dim_cache_[Y_AXIS]->set_extent_callback (height_callback);  
154 }
155