]> git.donarmstrong.com Git - lilypond.git/blob - lily/tuplet-number.cc
69e97afef04b6435e1494c28019405d580102c2f
[lilypond.git] / lily / tuplet-number.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "tuplet-bracket.hh"
22 #include "moment.hh"
23 #include "paper-column.hh"
24 #include "text-interface.hh"
25 #include "spanner.hh"
26 #include "lookup.hh"
27
28 struct Tuplet_number
29 {
30   DECLARE_SCHEME_CALLBACK (print, (SCM));
31   DECLARE_SCHEME_CALLBACK (calc_x_offset, (SCM));
32   DECLARE_SCHEME_CALLBACK (calc_y_offset, (SCM));
33   DECLARE_SCHEME_CALLBACK (calc_cross_staff, (SCM));
34   DECLARE_GROB_INTERFACE ();
35
36   static Real calc_offset (Spanner *me, Axis a);
37 };
38
39 MAKE_SCHEME_CALLBACK (Tuplet_number, print, 1);
40 SCM
41 Tuplet_number::print (SCM smob)
42 {
43   Spanner *me = unsmob_spanner (smob);
44   Spanner *tuplet = unsmob_spanner (me->get_object ("bracket"));
45
46   if (!tuplet || !tuplet->is_live ())
47     {
48       me->suicide ();
49       return SCM_EOL;
50     }
51
52   SCM stc_scm = Text_interface::print (smob);
53   Stencil *stc = unsmob_stencil (stc_scm);
54
55   stc->align_to (X_AXIS, CENTER);
56   stc->align_to (Y_AXIS, CENTER);
57
58   return stc->smobbed_copy ();
59 }
60
61 MAKE_SCHEME_CALLBACK (Tuplet_number, calc_x_offset, 1);
62 SCM
63 Tuplet_number::calc_x_offset (SCM smob)
64 {
65   Spanner *me = unsmob_spanner (smob);
66   Spanner *tuplet = unsmob_spanner (me->get_object ("bracket"));
67
68   Interval x_positions = robust_scm2interval (tuplet->get_property ("X-positions"), Interval (0.0, 0.0));
69
70   return scm_from_double (x_positions.center ());
71 }
72
73 MAKE_SCHEME_CALLBACK (Tuplet_number, calc_y_offset, 1);
74 SCM
75 Tuplet_number::calc_y_offset (SCM smob)
76 {
77
78   Spanner *me = unsmob_spanner (smob);
79   Spanner *tuplet = unsmob_spanner (me->get_object ("bracket"));
80
81   Drul_array<Real> positions = robust_scm2drul (tuplet->get_property ("positions"), Drul_array<Real> (0.0, 0.0));
82   return scm_from_double ((positions[LEFT] + positions[RIGHT]) / 2.0);
83 }
84
85 MAKE_SCHEME_CALLBACK (Tuplet_number, calc_cross_staff, 1)
86 SCM
87 Tuplet_number::calc_cross_staff (SCM smob)
88 {
89   Grob *me = unsmob_grob (smob);
90   return unsmob_grob (me->get_object ("bracket"))->get_property ("cross-staff");
91 }
92
93 ADD_INTERFACE (Tuplet_number,
94                "The number for a bracket.",
95
96                /* properties */
97                "avoid-slur "    // UGH.
98                "bracket "
99                "direction "
100               );
101