]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-symbol-referencer-scheme.cc
Merge commit 'origin/master'
[lilypond.git] / lily / staff-symbol-referencer-scheme.cc
1 /*
2   staff-symbol-referencer-scheme.cc -- implement Staff_symbol_referencer bindings
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1999--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "grob.hh"
10 #include "libc-extension.hh"
11 #include "staff-symbol.hh"
12 #include "staff-symbol-referencer.hh"
13
14 LY_DEFINE (ly_grob_staff_position, "ly:grob-staff-position",
15            1, 0, 0, (SCM sg),
16            "Return the Y-position of @var{sg} relative to the staff.")
17 {
18   LY_ASSERT_SMOB (Grob, sg, 1);
19   Grob *g = unsmob_grob (sg);
20   Real pos = Staff_symbol_referencer::get_position (g);
21
22   if (fabs (rint (pos) -pos) < 1e-6) // ugh.
23     return scm_from_int ((int) my_round (pos));
24   else
25     return scm_from_double (pos);
26 }
27
28 LY_DEFINE (ly_position_on_line_p, "ly:position-on-line?",
29            2, 0, 0, (SCM sg, SCM spos),
30            "Return whether @var{spos} is on a line of the staff associated"
31            " with the the grob @var{sg} (even on an extender line).")
32 {
33   LY_ASSERT_SMOB (Grob, sg, 1);
34   LY_ASSERT_TYPE (scm_is_number, spos, 2);
35   Grob *g = unsmob_grob (sg);
36   Grob *st = Staff_symbol_referencer::get_staff_symbol (g);
37   int pos = scm_to_int (spos);
38   bool on_line = st ? Staff_symbol::on_line (g, pos) : false;
39   return scm_from_bool (on_line);
40 }
41
42 LY_DEFINE (ly_staff_symbol_line_thickness, "ly:staff-symbol-line-thickness",
43            1, 0, 0, (SCM grob),
44            "Returns the @code{line-thickness} of the staff associated"
45            " with @var{grob}.")
46 {
47   LY_ASSERT_SMOB (Grob, grob, 1);
48   Grob *g = unsmob_grob (grob);
49   Real thickness = Staff_symbol_referencer::line_thickness (g);
50   return scm_from_double (thickness);
51 }
52
53 LY_DEFINE (ly_staff_symbol_staff_space, "ly:staff-symbol-staff-space",
54            1, 0, 0, (SCM grob),
55            "Returns the @code{staff-space} of the staff associated"
56            " with @var{grob}.")
57 {
58   LY_ASSERT_SMOB (Grob, grob, 1);
59   Grob *g = unsmob_grob (grob);
60   Real staff_space = Staff_symbol_referencer::staff_space (g);
61   return scm_from_double (staff_space);
62 }