]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-symbol-referencer-scheme.cc
Web-ja: update introduction
[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--2015 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 current staff-line thickness in the staff"
56            " associated with @var{grob}, expressed as a multiple of the"
57            " current staff-space height.")
58 {
59   LY_ASSERT_SMOB (Grob, grob, 1);
60   Grob *g = unsmob<Grob> (grob);
61   Real thickness = Staff_symbol_referencer::line_thickness (g);
62   return scm_from_double (thickness);
63 }
64
65 LY_DEFINE (ly_staff_symbol_staff_space, "ly:staff-symbol-staff-space",
66            1, 0, 0, (SCM grob),
67            "Returns the current staff-space height in the staff"
68            " associated with @var{grob}, expressed as a multiple of the"
69            " default height of a staff-space in the traditional"
70            " five-line staff.")
71 {
72   LY_ASSERT_SMOB (Grob, grob, 1);
73   Grob *g = unsmob<Grob> (grob);
74   Real staff_space = Staff_symbol_referencer::staff_space (g);
75   return scm_from_double (staff_space);
76 }
77
78 LY_DEFINE (ly_staff_symbol_staff_radius, "ly:staff-symbol-staff-radius",
79            1, 0, 0, (SCM grob),
80            "Returns the radius of the staff associated with"
81            " @var{grob}.")
82 {
83   LY_ASSERT_SMOB (Grob, grob, 1);
84   Grob *g = unsmob<Grob> (grob);
85   Real staff_radius = Staff_symbol_referencer::staff_radius (g);
86   return scm_from_double (staff_radius);
87 }