]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
91ab2a0ab291a43a9a41da542c970af3e5a4f682
[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 "axis-group-interface.hh"
16 #include "group-interface.hh"
17
18 void
19 Span_bar::add_bar (Score_element*b)
20 {
21   Pointer_group_interface gi (this);
22   gi.add_element (b);
23
24   add_dependency (b);
25 }
26
27
28 Interval
29 Span_bar::width_callback (Score_element const *se, Axis )
30 {
31   Span_bar*  s= dynamic_cast<Span_bar*> ((Score_element*)se);
32   String gl = ly_scm2string (s->get_elt_property ("glyph"));
33
34   /*
35     urg.
36    */
37   Molecule m = s->compound_barline (gl, 40 PT);
38   
39   return m.extent (X_AXIS);
40 }
41
42 GLUE_SCORE_ELEMENT(Span_bar,before_line_breaking);
43 SCM
44 Span_bar::member_before_line_breaking ()
45 {
46   Bar::member_before_line_breaking ();
47   
48   evaluate_empty ();
49
50   return SCM_UNDEFINED;
51 }
52
53 GLUE_SCORE_ELEMENT(Span_bar,after_line_breaking);
54 SCM
55 Span_bar::member_after_line_breaking ()
56 {
57   Interval i (get_spanned_interval ());
58
59   /*
60     Bar::brew_molecule delivers a barline of y-extent (-h/2,h/2), so
61     we have to translate ourselves to be in the center of the 
62     interval that we span.  */
63   translate_axis (i.center (), Y_AXIS);
64   return SCM_UNDEFINED;
65 }
66
67 void
68 Span_bar::evaluate_empty ()
69
70   if (!gh_pair_p (get_elt_pointer ("elements")))
71     {
72       suicide ();
73     }
74   
75   SCM gl = get_elt_property ("glyph");
76   if (!gh_string_p (gl))
77     {
78       suicide ();
79       return ; 
80     }
81   else {
82     String type_str = ly_scm2string (gl);
83     String orig = type_str;
84     if (type_str == "|:") 
85       {
86         type_str= ".|";
87       }
88     else if (type_str== ":|")
89       {
90         type_str= "|.";
91       }
92     else if (type_str== ":|:")
93       {
94         type_str= ".|.";
95       }
96     if (orig != type_str)
97       set_elt_property ("glyph", ly_str02scm (type_str.ch_C()));
98   }
99 }
100
101 Interval
102 Span_bar::get_spanned_interval () const
103 {
104   return Axis_group_interface::group_extent_callback (this, Y_AXIS);  
105 }
106
107
108 Real
109 Span_bar::get_bar_size () const
110 {
111   Interval iv (get_spanned_interval ());
112   if (iv.empty_b ())
113     {
114       programming_error("Huh? My children deflated (FIXME)");
115       iv = Interval (0,0);
116     }
117   return iv.length ();
118 }
119
120 Span_bar::Span_bar (SCM s)
121   : Bar (s)
122 {
123   Pointer_group_interface(this).set_interface ();
124   set_extent_callback (width_callback, X_AXIS);
125   
126   // dim_cache_[Y_AXIS]->set_extent_callback (Axis_group_interface::group_extent_callback);
127
128   set_extent_callback (0, Y_AXIS);
129 }
130