]> git.donarmstrong.com Git - lilypond.git/blob - lily/script.cc
patch::: 1.1.37.script1
[lilypond.git] / lily / script.cc
1 /*
2   script.cc -- implement Script
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "general-script-def.hh"
9 #include "musical-request.hh"
10 #include "paper-def.hh"
11 #include "script.hh"
12 #include "stem.hh"
13 #include "molecule.hh"
14 #include "lookup.hh"
15
16 void
17 Script::do_print () const
18 {
19 #ifndef NPRINT
20   specs_p_->print ();
21 #endif
22 }
23
24 void
25 Script::do_substitute_element_pointer (Score_element*o,Score_element*n)
26 {
27   Staff_side::do_substitute_element_pointer (o,n);
28   if (o == stem_l_)
29     {
30       stem_l_ = dynamic_cast<Stem *> (n);
31     }
32 }
33
34 void
35 Script::set_stem (Stem*st_l)
36 {
37   stem_l_ = st_l;
38   add_support (st_l);
39 }
40
41
42 Script::Script ()
43 {
44   axis_ = Y_AXIS;
45   specs_p_ = 0;
46   stem_l_ = 0;
47   dir_ =  CENTER;
48 }
49
50 void
51 Script::set_default_dir ()
52 {
53   int s_i=specs_p_->rel_stem_dir ();
54   if (s_i)
55     {
56       if (stem_l_)
57         dir_ = Direction (stem_l_->dir_ * s_i);
58       else
59         {
60           specs_p_->warning (_ ("script needs stem direction"));
61           dir_ = DOWN;
62         }
63     }
64   else
65     {
66       dir_ =specs_p_->staff_dir ();
67     }
68   assert (dir_);
69 }
70
71
72 Interval
73 Script::do_width () const
74 {
75   return specs_p_->get_molecule (paper_l (), dir_).extent ().x ();
76 }
77
78 void
79 Script::do_pre_processing ()
80 {
81   Staff_side::do_pre_processing ();
82   if (axis_ == Y_AXIS && !dir_)
83     set_default_dir ();
84 }
85
86 Interval
87 Script::symbol_height () const
88 {
89   return specs_p_->get_molecule (paper_l (), dir_).extent ().y ();
90 }
91
92
93 Molecule*
94 Script::do_brew_molecule_p () const
95 {
96   Real dx =0.;
97
98   Molecule*mol_p = new Molecule (specs_p_->get_molecule (paper_l (), dir_));
99   /*
100     ugh, staccato dots are not centred between stafflines (how?)?
101   */
102   Real correct =0.0;
103   if (axis_ == Y_AXIS){
104     dx =  paper_l ()->note_width ()/2;
105     correct = - (Real)dir_ * 2.0 * paper_l ()->rule_thickness ();
106     mol_p->translate_axis (dx, X_AXIS); // FIXME! ugh
107   }
108   
109   mol_p->translate_axis (coordinate_offset_f_ + correct, axis_);
110
111   return mol_p;
112 }
113
114
115
116
117 int
118 Script::compare (Script  *const&l1, Script *const&l2)
119 {
120   return l1->specs_p_->priority_i() - l2->specs_p_->priority_i ();
121 }
122
123 Script::~Script ()
124 {
125   delete specs_p_;
126 }
127  
128 Script::Script (Script const&s)
129   : Item (s), Staff_side(s)
130 {
131   specs_p_ = s.specs_p_ ? s.specs_p_->clone (): 0;
132   stem_l_ =s.stem_l_;
133 }
134