]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-symbol.cc
* lily/include/lily-guile.hh: many new ly_ functions. Thanks to
[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 "stencil.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   Interval span_points (0,0);
32   
33
34   /*
35     For raggedright without ragged staffs, simply set width to the linewidth.
36
37     (ok -- lousy UI, since width is in staff spaces)
38
39     --hwn.
40    */
41   Direction d = LEFT;
42   do
43     {
44       SCM width_scm = me->get_property ("width");
45       if (d == RIGHT && ly_number_p (width_scm))
46         {
47           /*
48             don't multiply by Staff_symbol_referencer::staff_space (me),
49             since that would make aligning staff symbols of different sizes to
50             one right margin hell.
51           */      
52           span_points[RIGHT] = ly_scm2double (width_scm);
53         }
54       else
55         {
56           Item * x = sp->get_bound (d);
57
58           span_points[d] = x->relative_coordinate (common , X_AXIS);
59           if (!x->break_status_dir ()
60               && !x->extent (x, X_AXIS).is_empty ())
61             span_points[d] += x->extent (x, X_AXIS)[d];
62         }
63     }
64   while (flip (&d) !=LEFT);
65
66
67   Real t = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness"));
68   t *= robust_scm2double (me->get_property ("thickness"), 1.0);
69   
70   int l = Staff_symbol::line_count (me);
71   
72   Real height = (l-1) * staff_space (me) /2;
73   Stencil a =
74     Lookup::horizontal_line (span_points
75                              -me->relative_coordinate (common, X_AXIS),
76                              t);
77
78   Stencil m;
79   for (int i=0; i < l; i++)
80     {
81       Stencil b(a);
82       b.translate_axis (height - i * staff_space (me), Y_AXIS);
83       m.add_stencil (b);
84     }
85   return m.smobbed_copy ();
86 }
87
88 int
89 Staff_symbol::get_steps (Grob*me) 
90 {
91   return line_count (me) * 2;
92 }
93
94 int
95 Staff_symbol::line_count (Grob*me) 
96 {
97   SCM c = me->get_property ("line-count");
98   if (ly_number_p (c))
99     return ly_scm2int (c);
100   else
101     return 0;
102 }
103
104 Real
105 Staff_symbol::staff_space (Grob*me)
106 {
107   return robust_scm2double ( me->get_property ("staff-space"), 1.0);
108 }
109
110 Real
111 Staff_symbol::get_line_thickness (Grob* me)
112 {
113   Real lt =  me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness"));
114
115   return robust_scm2double (me->get_property ("thickness"), 1.0) * lt;
116 }
117
118 Real
119 Staff_symbol::get_ledger_line_thickness (Grob * me)
120 {
121   SCM lt_pair = me->get_property ("ledger-line-thickness");
122   Offset z = robust_scm2offset (lt_pair, Offset (1.0, 0.1));
123   
124   return z[X_AXIS] * get_line_thickness (me) + z[Y_AXIS]* staff_space (me);
125 }
126
127
128 ADD_INTERFACE (Staff_symbol,"staff-symbol-interface",
129                "This spanner draws the lines of a staff. "
130                "A staff symbol definines a vertical unit, the staff space. "
131                "Quantities that go by a half staff space are called positions "
132                "The center (i.e. middle line "
133                "or space) is position 0. The length of the symbol may be set by hand "
134                "through the @code{width} property. ",
135                
136   "ledger-line-thickness width staff-space thickness line-count");