2 staff-symbol-referencer.cc -- implement Staff_symbol_referencer
4 source file of the GNU LilyPond music typesetter
6 (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "staff-symbol-referencer.hh"
12 #include "staff-symbol.hh"
13 #include "paper-def.hh"
14 #include "dimension-cache.hh"
16 Staff_symbol_referencer_interface::Staff_symbol_referencer_interface (Score_element
const *sc
)
18 elt_l_
= (Score_element
*)sc
;
22 Staff_symbol_referencer_interface::set_interface ()
24 elt_l_
->set_elt_property ("staff-position", gh_double2scm (0.0));
25 elt_l_
->dim_cache_
[Y_AXIS
]->off_callbacks_
.push (callback
);
30 Staff_symbol_referencer_interface::has_interface_b ()
32 return unsmob_element (elt_l_
->get_elt_property ("staff-symbol"))
33 || gh_number_p (elt_l_
->get_elt_property ("staff-position"));
38 Staff_symbol_referencer_interface::lines_i () const
40 Staff_symbol
*st
= staff_symbol_l ();
41 return st
? st
->no_lines_i_
: 5;
45 Staff_symbol_referencer_interface::staff_symbol_l () const
47 SCM st
= elt_l_
->get_elt_property ("staff-symbol");
48 return dynamic_cast<Staff_symbol
* > (unsmob_element(st
));
52 Staff_symbol_referencer_interface::staff_line_leading_f () const
54 Staff_symbol
* st
= staff_symbol_l ();
56 return st
->staff_line_leading_f_
;
57 else if (elt_l_
->pscore_l_
&& elt_l_
->paper_l ())
58 elt_l_
->paper_l ()->get_var ("interline");
65 Staff_symbol_referencer_interface::position_f () const
68 Staff_symbol
* st
= staff_symbol_l ();
69 Score_element
* c
= st
? elt_l_
->common_refpoint (st
, Y_AXIS
) : 0;
72 Real y
= elt_l_
->relative_coordinate (c
, Y_AXIS
)
73 - st
->relative_coordinate (c
, Y_AXIS
);
75 p
+= 2.0 * y
/ st
->staff_line_leading_f ();
79 SCM pos
= elt_l_
->get_elt_property ("staff-position");
80 if (gh_number_p (pos
))
81 return gh_scm2double (pos
);
90 should use offset callback!
93 Staff_symbol_referencer_interface::callback (Dimension_cache
const * c
)
95 Score_element
* sc
= dynamic_cast<Score_element
*> (c
->element_l ());
98 SCM pos
= sc
->get_elt_property ("staff-position");
100 if (gh_number_p (pos
))
102 Real space
= staff_symbol_referencer_interface (sc
).staff_line_leading_f ();
103 off
= gh_scm2double (pos
) * space
/2.0;
105 sc
->set_elt_property ("staff-position", gh_double2scm (0.0));
112 Staff_symbol_referencer_interface::set_position (Real p
)
114 Staff_symbol
* st
= staff_symbol_l ();
115 if (st
&& elt_l_
->common_refpoint(st
, Y_AXIS
))
117 Real oldpos
= position_f ();
118 elt_l_
->set_elt_property ("staff-position", gh_double2scm (p
- oldpos
));
122 elt_l_
->set_elt_property ("staff-position",
127 Array
<Offset_cache_callback
> &callbacks (elt_l_
->dim_cache_
[Y_AXIS
]->off_callbacks_
);
128 for (int i
=0; i
< callbacks
.size ();i
++)
129 if (callbacks
[i
] == callback
)
132 callbacks
.push (callback
);
135 Staff_symbol_referencer_interface
136 staff_symbol_referencer_interface (Score_element
const*e
)
138 return e
; // gee, I'm so smart!
142 compare_position (Score_element
*const &a
, Score_element
* const &b
)
144 Staff_symbol_referencer_interface
s1(a
);
145 Staff_symbol_referencer_interface
s2(b
);
147 return sign(s1
.position_f () - s2
.position_f ());