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