]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-staff-side.cc
1b6f7bc750097ce16920f2fce1490f296b163154
[lilypond.git] / lily / stem-staff-side.cc
1 /*   
2   g-stem-staff-side.cc --  implement Stem_staff_side
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "dimension-cache.hh"
11 #include "stem-staff-side.hh"
12 #include "stem.hh"
13 #include "staff-symbol.hh"
14 #include "paper-def.hh"
15
16 Stem_staff_side_item::Stem_staff_side_item ()
17 {
18   stem_l_ =0;
19   relative_dir_ = CENTER;
20 }
21
22 void
23 Stem_staff_side_item::do_substitute_element_pointer (Score_element*o,
24                                                        Score_element*n)
25 {
26   if (o == stem_l_)
27     {
28       stem_l_ = dynamic_cast<Stem*> (n);
29     }
30   Staff_side_item::do_substitute_element_pointer (o,n);
31 }
32
33 void
34 Stem_staff_side_item::set_stem (Stem*s)
35 {
36   stem_l_ =s;
37   add_dependency (s);
38 }
39
40
41 Direction
42 Stem_staff_side_item::get_default_direction () const
43 {
44   return (Direction)(relative_dir_ * stem_l_->dir_);
45 }
46
47 void
48 Stem_staff_side_item::do_pre_processing ()
49 {
50   SCM p = remove_elt_property (padding_scm_sym);
51   Real pad  = paper_l ()->get_var ("articulation_script_padding_default");
52   if (get_elt_property (no_staff_support_scm_sym) != SCM_BOOL_F)
53     pad =0.0; 
54   
55   Real il  = (stem_l_) ? stem_l_->staff_line_leading_f (): paper_l ()->get_var ("interline");
56   
57   if (p != SCM_BOOL_F)
58     {
59       pad =  gh_scm2double (p);
60     }
61   pad *=  il ;
62   set_elt_property (padding_scm_sym,
63                     gh_double2scm(pad));
64
65   Staff_side_item::do_pre_processing ();
66 }
67
68 void
69 Stem_staff_side_item::do_post_processing ()
70 {
71   Staff_side_item::do_post_processing ();
72
73  /*
74    Ugh: try to get staccato dots right. 
75
76    TODO:
77     
78     
79     should use general no_staff_line_collision elt property, and use
80     the same elt prop also for positioning slurs, ties and dots.
81   */
82   if (get_elt_property (no_staff_support_scm_sym) != SCM_BOOL_F)
83     {
84       Graphical_element * c =common_refpoint (staff_symbol_l (), Y_AXIS);
85       Real staff_coord = staff_symbol_l ()->relative_coordinate (c, Y_AXIS);
86       Real self_coord = relative_coordinate (c, Y_AXIS);
87       Real now_coord = self_coord - staff_coord;
88       
89       Real desired_coord = ceil (dir_ * 2.0 *  now_coord / staff_line_leading_f ());
90       if (! (int (desired_coord) % 2))
91         {
92           desired_coord ++;
93         }
94
95       translate_axis (desired_coord * dir_ *  staff_line_leading_f () / 2.0  - now_coord, Y_AXIS);
96     }
97 }