]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-symbol.cc
patch::: 1.3.93.jcn2
[lilypond.git] / lily / staff-symbol.cc
1 /*
2   staff-symbol.cc -- implement Staff_symbol
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "lookup.hh"
10 #include "dimensions.hh"
11 #include "paper-def.hh"
12 #include "molecule.hh"
13 #include "debug.hh"
14 #include "item.hh"
15 #include "staff-symbol.hh"
16 #include "spanner.hh"
17
18
19 MAKE_SCHEME_CALLBACK(Staff_symbol,brew_molecule,1);
20
21 SCM
22 Staff_symbol::brew_molecule (SCM smob)
23 {
24   Score_element *me = unsmob_element (smob);
25   Spanner* sp = dynamic_cast<Spanner*> (me);
26   Score_element * common
27     = sp->get_bound (LEFT)->common_refpoint (sp->get_bound (RIGHT), X_AXIS);
28   
29   Real width =
30     // right_shift     - left_shift
31     + sp->get_bound (RIGHT)->relative_coordinate (common , X_AXIS)
32     - sp->get_bound (LEFT)->relative_coordinate (common, X_AXIS)
33     ;
34
35   Real t = me->paper_l ()->get_var ("stafflinethickness");
36   int l = Staff_symbol::line_count (me);
37   
38   Real height = (l-1) * staff_space (me) /2;
39   Molecule m;
40   for (int i=0; i < l; i++)
41     {
42       Molecule a =
43         me->lookup_l ()->filledbox (Box (Interval (0,width),
44                                          Interval (-t/2, t/2)));
45
46       a.translate_axis (height - i * staff_space (me), Y_AXIS);
47       m.add_molecule (a);
48     }
49
50   return m.create_scheme();
51 }
52
53 int
54 Staff_symbol::steps_i(Score_element*me) 
55 {
56   return line_count (me) * 2;
57 }
58
59 int
60 Staff_symbol::line_count (Score_element*me) 
61 {
62   SCM c = me->get_elt_property ("line-count");
63   if (gh_number_p (c))
64     return gh_scm2int (c);
65   else
66     return 0;
67 }
68
69 Real
70 Staff_symbol::staff_space (Score_element*me )
71 {
72   Real ss = me->paper_l ()->get_var ("staffspace");
73   
74   SCM s = me->get_elt_property ("staff-space");
75   if (gh_number_p (s))
76     ss *= gh_scm2double (s);
77   return ss;
78 }
79
80 bool
81 Staff_symbol::has_interface (Score_element*m)
82 {
83   return m && m->has_interface (ly_symbol2scm ("staff-symbol-interface"));
84 }