]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
patch::: 1.3.94.jcn1
[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
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 #include "score-element.hh"
18 #include "bar.hh"
19
20 void
21 Span_bar::add_bar (Score_element*me, Score_element*b)
22 {
23   Pointer_group_interface gi (me);
24   gi.add_element (b);
25
26   me->add_dependency (b);
27 }
28
29 MAKE_SCHEME_CALLBACK(Span_bar,width_callback,2);
30 SCM
31 Span_bar::width_callback (SCM element_smob, SCM scm_axis)
32 {
33   Score_element *se = unsmob_element (element_smob);
34   Axis a = (Axis) gh_scm2int (scm_axis);
35   assert (a == X_AXIS);
36   String gl = ly_scm2string (se->get_elt_property ("glyph"));
37
38   /*
39     urg.
40    */
41   Molecule m = Bar::compound_barline (se, gl, 40 PT);
42   
43   return ly_interval2scm ( m.extent (X_AXIS));
44 }
45
46 MAKE_SCHEME_CALLBACK(Span_bar,before_line_breaking,1);
47 SCM
48 Span_bar::before_line_breaking (SCM smob)
49 {
50   evaluate_empty (unsmob_element (smob));
51   evaluate_glyph (unsmob_element (smob));
52
53   /*
54     no need to call   Bar::before_line_breaking (), because the info
55     in ELEMENTS already has been procced by Bar::before_line_breaking().
56    */
57   return SCM_UNSPECIFIED;
58 }
59
60 MAKE_SCHEME_CALLBACK(Span_bar,center_on_spanned_callback,2);
61 SCM
62 Span_bar::center_on_spanned_callback (SCM element_smob, SCM axis)
63 {
64   Score_element *me = unsmob_element (element_smob);
65   Axis a = (Axis) gh_scm2int (axis);
66   assert (a == Y_AXIS);
67   Interval i (get_spanned_interval (me));
68
69   /*
70     Bar::brew_molecule delivers a barline of y-extent (-h/2,h/2), so
71     we have to translate ourselves to be in the center of the 
72     interval that we span.  */
73
74   return gh_double2scm (i.center ());
75 }
76
77 void
78 Span_bar::evaluate_empty (Score_element*me)
79 {
80   /*
81     TODO: filter all hara-kiried out of ELEMENS list, and then
82     optionally do suicide. Call this cleanage function from
83     center_on_spanned_callback() as well.
84     
85    */
86   if (!gh_pair_p (me->get_elt_property ("elements")))
87     {
88       me->suicide ();
89     }
90 }
91
92 void
93 Span_bar::evaluate_glyph (Score_element*me)
94 {
95   SCM elts = me->get_elt_property ("elements");
96   Score_element * b = unsmob_element (gh_car (elts));
97   SCM glsym =ly_symbol2scm ("glyph");
98   SCM gl =b ->get_elt_property (glsym);
99   if (!gh_string_p (gl))
100     {
101       me->suicide ();
102       return ; 
103     }
104
105   String type = ly_scm2string (gl);
106   
107   if (type == "|:") 
108     {
109       type = ".|";
110     }
111   else if (type== ":|")
112     {
113       type = "|.";
114     }
115   else if (type== ":|:")
116     {
117       type = ".|.";
118     }
119
120   gl = ly_str02scm (type.ch_C());
121   if (scm_equal_p (me->get_elt_property (glsym), gl) != SCM_BOOL_T)
122     me->set_elt_property (glsym, gl);
123 }
124
125 Interval
126 Span_bar::get_spanned_interval (Score_element*me) 
127 {
128   return ly_scm2interval (Axis_group_interface::group_extent_callback (me->self_scm(), gh_int2scm (Y_AXIS))); 
129 }
130
131
132 MAKE_SCHEME_CALLBACK(Span_bar,get_bar_size,1);
133 SCM
134 Span_bar::get_bar_size (SCM smob)
135 {
136   Score_element* me =  unsmob_element (smob);
137   Interval iv (get_spanned_interval (me));
138   if (iv.empty_b ())
139     {
140       /*
141         This happens if the bars are hara-kiried from under us.
142        */
143       me->suicide ();
144       return gh_double2scm (-1);
145     }
146   return gh_double2scm (iv.length ());
147 }
148
149 void
150 Span_bar::set_interface (Score_element *me)
151 {
152   Bar::set_interface (me);
153   
154   me->set_interface (ly_symbol2scm ("span-bar-interface"));
155   me->set_extent_callback (SCM_EOL, Y_AXIS);
156 }
157
158 bool
159 Span_bar::has_interface (Score_element*m)
160 {
161   return m && m->has_interface (ly_symbol2scm ("span-bar-interface"));
162 }