]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-symbol-referencer-scheme.cc
1fe886ec0a5a76ee169f2869600419614a58db68
[lilypond.git] / lily / staff-symbol-referencer-scheme.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1999--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "grob.hh"
21 #include "libc-extension.hh"
22 #include "staff-symbol.hh"
23 #include "staff-symbol-referencer.hh"
24
25 LY_DEFINE (ly_grob_staff_position, "ly:grob-staff-position",
26            1, 0, 0, (SCM sg),
27            "Return the Y-position of @var{sg} relative to the staff.")
28 {
29   LY_ASSERT_SMOB (Grob, sg, 1);
30   Grob *g = unsmob_grob (sg);
31   Real pos = Staff_symbol_referencer::get_position (g);
32
33   if (fabs (rint (pos) - pos) < 1e-6) // ugh.
34     return scm_from_int ((int) my_round (pos));
35   else
36     return scm_from_double (pos);
37 }
38
39 LY_DEFINE (ly_position_on_line_p, "ly:position-on-line?",
40            2, 0, 0, (SCM sg, SCM spos),
41            "Return whether @var{spos} is on a line of the staff associated"
42            " with the grob @var{sg} (even on an extender line).")
43 {
44   LY_ASSERT_SMOB (Grob, sg, 1);
45   LY_ASSERT_TYPE (scm_is_number, spos, 2);
46   Grob *g = unsmob_grob (sg);
47   Grob *st = Staff_symbol_referencer::get_staff_symbol (g);
48   int pos = scm_to_int (spos);
49   bool on_line = st ? Staff_symbol::on_line (g, pos) : false;
50   return scm_from_bool (on_line);
51 }
52
53 LY_DEFINE (ly_staff_symbol_line_thickness, "ly:staff-symbol-line-thickness",
54            1, 0, 0, (SCM grob),
55            "Returns the @code{line-thickness} of the staff associated"
56            " with @var{grob}.")
57 {
58   LY_ASSERT_SMOB (Grob, grob, 1);
59   Grob *g = unsmob_grob (grob);
60   Real thickness = Staff_symbol_referencer::line_thickness (g);
61   return scm_from_double (thickness);
62 }
63
64 LY_DEFINE (ly_staff_symbol_staff_space, "ly:staff-symbol-staff-space",
65            1, 0, 0, (SCM grob),
66            "Returns the @code{staff-space} of the staff associated"
67            " with @var{grob}.")
68 {
69   LY_ASSERT_SMOB (Grob, grob, 1);
70   Grob *g = unsmob_grob (grob);
71   Real staff_space = Staff_symbol_referencer::staff_space (g);
72   return scm_from_double (staff_space);
73 }
74
75 LY_DEFINE (ly_staff_symbol_staff_radius, "ly:staff-symbol-staff-radius",
76            1, 0, 0, (SCM grob),
77            "Returns the radius of the staff associated with"
78            " @var{grob}.")
79 {
80   LY_ASSERT_SMOB (Grob, grob, 1);
81   Grob *g = unsmob_grob (grob);
82   Real staff_radius = Staff_symbol_referencer::staff_radius (g);
83   return scm_from_double (staff_radius);
84 }