]> git.donarmstrong.com Git - lilypond.git/blob - lily/figured-bass-continuation.cc
389e4e96aca23fcc814d01f182b4967748337a29
[lilypond.git] / lily / figured-bass-continuation.cc
1 /*
2   figured-bass-continuation.cc -- implement Figured_bass_continuation
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8 */
9
10 #include "line-interface.hh"
11 #include "spanner.hh"
12 #include "output-def.hh"
13 #include "item.hh"
14 #include "stencil.hh"
15 #include "pointer-group-interface.hh"
16 #include "axis-group-interface.hh"
17
18
19 #include "horizontal-bracket.hh"
20
21 struct Figured_bass_continuation
22 {
23   DECLARE_GROB_INTERFACE ();
24   
25 public:
26   DECLARE_SCHEME_CALLBACK (print, (SCM));
27   DECLARE_SCHEME_CALLBACK (center_on_figures, (SCM));
28 };
29
30 MAKE_SCHEME_CALLBACK (Figured_bass_continuation, center_on_figures, 1);
31 SCM
32 Figured_bass_continuation::center_on_figures (SCM grob)
33 {
34   Spanner *me = dynamic_cast<Spanner*> (unsmob_grob (grob));
35   extract_grob_set (me, "figures", figures);
36   if (figures.empty ())
37     return scm_from_double (0.0);
38   Grob *common = common_refpoint_of_array (figures, me, Y_AXIS);
39
40   Interval ext = Axis_group_interface::relative_group_extent (figures, common, Y_AXIS);
41   if (ext.is_empty ())
42     return scm_from_double (0.0);
43   return scm_from_double (ext.center () - me->relative_coordinate (common, Y_AXIS));
44 }
45
46 MAKE_SCHEME_CALLBACK (Figured_bass_continuation, print, 1);
47 SCM
48 Figured_bass_continuation::print (SCM grob)
49 {
50   Spanner *me = dynamic_cast<Spanner*> (unsmob_grob (grob));
51
52   Real thick =
53     me->layout ()->get_dimension (ly_symbol2scm ("line-thickness"))
54     * robust_scm2double (me->get_property ("thickness"), 1);
55   
56   Interval spanned;
57   Direction d = LEFT;
58   Grob *common = me->get_bound (LEFT)->common_refpoint (me->get_bound (RIGHT),
59                                                         X_AXIS);
60   do
61     {
62       Item *bound = me->get_bound (d);
63       Direction extdir =
64         (d == LEFT && to_boolean (bound->get_property ("implicit")))
65         ? LEFT : RIGHT;
66
67       spanned[d] 
68         = robust_relative_extent (bound, common, X_AXIS)[extdir]
69         - me->relative_coordinate (common, X_AXIS);
70     }
71   while (flip (&d) !=  LEFT);
72   spanned.widen (- robust_scm2double (me->get_property ("padding"), 0.2));
73   
74   Stencil extender;
75   if (!spanned.is_empty ())
76     extender = Line_interface::make_line (thick,
77                                           Offset (spanned[LEFT], 0),
78                                           Offset (spanned[RIGHT], 0));
79   
80   return extender.smobbed_copy ();
81 }
82
83 ADD_INTERFACE (Figured_bass_continuation,
84               "Simple extender line between bounds.",
85               
86               /* properties */
87               "thickness "
88               "padding "
89               "figures "
90               );
91