]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-symbol.cc
a8ef6c0d1bf2413a0a275a17d50769726db373b8
[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--2004 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 "warn.hh"
14 #include "item.hh"
15 #include "staff-symbol.hh"
16 #include "staff-symbol-referencer.hh"
17 #include "spanner.hh"
18
19
20
21 MAKE_SCHEME_CALLBACK (Staff_symbol,print,1);
22
23 SCM
24 Staff_symbol::print (SCM smob)
25 {
26   Grob *me = unsmob_grob (smob);
27   Spanner* sp = dynamic_cast<Spanner*> (me);
28   Grob * common
29     = sp->get_bound (LEFT)->common_refpoint (sp->get_bound (RIGHT), X_AXIS);
30   
31   Real width  = 0.0;
32
33   /*
34     For raggedright without ragged staffs, simply set width to the linewidth.
35
36     (ok -- lousy UI, since width is in staff spaces)
37
38     --hwn.
39    */
40   SCM width_scm = me->get_grob_property ("width");
41   if (gh_number_p (width_scm))
42     {
43
44       /*
45         don't multiply by Staff_symbol_referencer::staff_space (me),
46         since that would make aligning staff symbols of different sizes to
47         one right margin hell.
48       */      
49       width = gh_scm2double (width_scm);
50     }
51   else
52     {
53       width = sp->get_bound (RIGHT)->relative_coordinate (common , X_AXIS);
54     }
55
56   // respect indentation, if any
57   width -= sp->get_bound (LEFT)->relative_coordinate (common, X_AXIS);
58
59   if (width < 0)
60     {
61       warning (_f ("staff symbol: indentation yields beyond end of line"));
62       width = 0;
63     }
64
65   Real t = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness"));
66   t *= robust_scm2double ( me->get_grob_property("thickness"), 1.0);
67   
68   int l = Staff_symbol::line_count (me);
69   
70   Real height = (l-1) * staff_space (me) /2;
71   Molecule m;
72   for (int i=0; i < l; i++)
73     {
74       Molecule a =
75         Lookup::horizontal_line (Interval (0,width), t);
76
77       a.translate_axis (height - i * staff_space (me), Y_AXIS);
78       m.add_molecule (a);
79     }
80
81   return m.smobbed_copy ();
82 }
83
84 int
85 Staff_symbol::get_steps (Grob*me) 
86 {
87   return line_count (me) * 2;
88 }
89
90 int
91 Staff_symbol::line_count (Grob*me) 
92 {
93   SCM c = me->get_grob_property ("line-count");
94   if (gh_number_p (c))
95     return gh_scm2int (c);
96   else
97     return 0;
98 }
99
100 Real
101 Staff_symbol::staff_space (Grob*me)
102 {
103   return robust_scm2double ( me->get_grob_property ("staff-space"), 1.0);
104 }
105
106 Real
107 Staff_symbol::get_line_thickness (Grob* me)
108 {
109   Real lt =  me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness"));
110
111   return robust_scm2double (me->get_grob_property ("thickness"), 1.0) * lt;
112 }
113
114 Real
115 Staff_symbol::get_ledger_line_thickness (Grob * me)
116 {
117   SCM lt_pair = me->get_grob_property ("ledger-line-thickness");
118   Offset z = robust_scm2offset (lt_pair, Offset (1.0, 0.1));
119   
120   return z[X_AXIS] * get_line_thickness(me) + z[Y_AXIS]* staff_space (me);
121 }
122
123
124 ADD_INTERFACE (Staff_symbol,"staff-symbol-interface",
125   "This spanner draws the lines of a staff.  The center (i.e. middle line "
126 "or space) is position 0. The length of the symbol may be set by hand "
127 "through the @code{width} property. ",
128                
129   "ledger-line-thickness width staff-space thickness line-count");