]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-symbol.cc
patch::: 1.3.99.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
20 MAKE_SCHEME_CALLBACK(Staff_symbol,brew_molecule,1);
21
22 SCM
23 Staff_symbol::brew_molecule (SCM smob)
24 {
25   Score_element *me = unsmob_element (smob);
26   Spanner* sp = dynamic_cast<Spanner*> (me);
27   Score_element * common
28     = sp->get_bound (LEFT)->common_refpoint (sp->get_bound (RIGHT), X_AXIS);
29   
30   Real width =
31     // right_shift     - left_shift
32     + sp->get_bound (RIGHT)->relative_coordinate (common , X_AXIS)
33     - sp->get_bound (LEFT)->relative_coordinate (common, X_AXIS)
34     ;
35
36   Real t = me->paper_l ()->get_var ("stafflinethickness");
37   int l = Staff_symbol::line_count (me);
38   
39   Real height = (l-1) * staff_space (me) /2;
40   Molecule m;
41   for (int i=0; i < l; i++)
42     {
43       Molecule a =
44         Lookup::filledbox (Box (Interval (0,width),
45                                          Interval (-t/2, t/2)));
46
47       a.translate_axis (height - i * staff_space (me), Y_AXIS);
48       m.add_molecule (a);
49     }
50
51   return m.create_scheme();
52 }
53
54 int
55 Staff_symbol::steps_i(Score_element*me) 
56 {
57   return line_count (me) * 2;
58 }
59
60 int
61 Staff_symbol::line_count (Score_element*me) 
62 {
63   SCM c = me->get_elt_property ("line-count");
64   if (gh_number_p (c))
65     return gh_scm2int (c);
66   else
67     return 0;
68 }
69
70 Real
71 Staff_symbol::staff_space (Score_element*me )
72 {
73   Real ss = me->paper_l ()->get_var ("staffspace");
74   
75   SCM s = me->get_elt_property ("staff-space");
76   if (gh_number_p (s))
77     ss *= gh_scm2double (s);
78   return ss;
79 }
80
81 bool
82 Staff_symbol::has_interface (Score_element*m)
83 {
84   return m && m->has_interface (ly_symbol2scm ("staff-symbol-interface"));
85 }