Release: update news.
[lilypond/patrick.git] / lily / staff-symbol-referencer-scheme.cc
blobe954dd37feffdd8164a1b8b3eba9a468e69e995c
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1999--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
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.
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.
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/>.
20 #include "grob.hh"
21 #include "libc-extension.hh"
22 #include "staff-symbol.hh"
23 #include "staff-symbol-referencer.hh"
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.")
29 LY_ASSERT_SMOB (Grob, sg, 1);
30 Grob *g = unsmob_grob (sg);
31 Real pos = Staff_symbol_referencer::get_position (g);
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);
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).")
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);
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}.")
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);
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}.")
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);