]> git.donarmstrong.com Git - lilypond.git/blob - lily/figured-bass-continuation.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / figured-bass-continuation.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2014 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 "line-interface.hh"
22 #include "spanner.hh"
23 #include "output-def.hh"
24 #include "item.hh"
25 #include "stencil.hh"
26 #include "pointer-group-interface.hh"
27 #include "axis-group-interface.hh"
28
29 #include "horizontal-bracket.hh"
30
31 struct Figured_bass_continuation
32 {
33   DECLARE_GROB_INTERFACE ();
34
35 public:
36   DECLARE_SCHEME_CALLBACK (print, (SCM));
37   DECLARE_SCHEME_CALLBACK (center_on_figures, (SCM));
38 };
39
40 MAKE_SCHEME_CALLBACK (Figured_bass_continuation, center_on_figures, 1);
41 SCM
42 Figured_bass_continuation::center_on_figures (SCM grob)
43 {
44   Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (grob));
45   extract_grob_set (me, "figures", figures);
46   if (figures.empty ())
47     return scm_from_double (0.0);
48   Grob *common = common_refpoint_of_array (figures, me, Y_AXIS);
49
50   Interval ext = Axis_group_interface::relative_group_extent (figures, common, Y_AXIS);
51   if (ext.is_empty ())
52     return scm_from_double (0.0);
53   return scm_from_double (ext.center () - me->relative_coordinate (common, Y_AXIS));
54 }
55
56 MAKE_SCHEME_CALLBACK (Figured_bass_continuation, print, 1);
57 SCM
58 Figured_bass_continuation::print (SCM grob)
59 {
60   Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (grob));
61
62   Real thick
63     = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness"))
64       * robust_scm2double (me->get_property ("thickness"), 1);
65
66   Interval spanned;
67
68   Grob *common = me->get_bound (LEFT)->common_refpoint (me->get_bound (RIGHT),
69                                                         X_AXIS);
70   for (LEFT_and_RIGHT (d))
71     {
72       Item *bound = me->get_bound (d);
73       Direction extdir
74         = (d == LEFT && to_boolean (bound->get_property ("implicit")))
75           ? LEFT : RIGHT;
76
77       spanned[d]
78         = robust_relative_extent (bound, common, X_AXIS)[extdir]
79           - me->relative_coordinate (common, X_AXIS);
80     }
81   spanned.widen (- robust_scm2double (me->get_property ("padding"), 0.2));
82
83   Stencil extender;
84   if (!spanned.is_empty ())
85     extender = Line_interface::make_line (thick,
86                                           Offset (spanned[LEFT], 0),
87                                           Offset (spanned[RIGHT], 0));
88
89   return extender.smobbed_copy ();
90 }
91
92 ADD_INTERFACE (Figured_bass_continuation,
93                "Simple extender line between bounds.",
94
95                /* properties */
96                "thickness "
97                "padding "
98                "figures "
99               );
100