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