]> git.donarmstrong.com Git - lilypond.git/blob - lily/script.cc
release: 1.1.1
[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--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "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_dependency (Score_element*o,Score_element*n)
26 {
27   Staff_side::do_substitute_dependency (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   postbreak_only_b_ = true;
48   dir_ =  CENTER;
49 }
50
51 void
52 Script::set_default_dir ()
53 {
54   int s_i=specs_p_->rel_stem_dir ();
55   if (s_i)
56     {
57       if (stem_l_)
58         dir_ = Direction (stem_l_->dir_ * s_i);
59       else
60         {
61           specs_p_->warning (_ ("script needs stem direction"));
62           dir_ = DOWN;
63         }
64     }
65   else
66     {
67       dir_ =specs_p_->staff_dir ();
68     }
69   assert (dir_);
70 }
71
72
73 Interval
74 Script::do_width () const
75 {
76   return specs_p_->get_atom (paper (), dir_).extent ().x ();
77 }
78
79 void
80 Script::do_pre_processing ()
81 {
82   Staff_side::do_pre_processing ();
83   if (breakable_b_ && postbreak_only_b_ && (break_status_dir () != RIGHT))
84     {
85       transparent_b_ = true;
86       set_empty (true);
87     }
88   
89   if (axis_ == Y_AXIS && !dir_)
90     set_default_dir ();
91 }
92
93 Interval
94 Script::symbol_height () const
95 {
96   return specs_p_->get_atom (paper (), dir_).extent ().y ();
97 }
98
99 Interval
100 Script::symbol_width () const
101 {
102   return specs_p_->width (paper ());
103 }
104
105 Molecule*
106 Script::brew_molecule_p () const
107 {
108   Real dx =0.;
109
110   Molecule*mol_p = new Molecule (specs_p_->get_atom (paper (), dir_));
111   /*
112     ugh, staccato dots are not centred between stafflines (how?)?
113   */
114   Real correct =0.0;
115   if (axis_ == Y_AXIS){
116     dx =  paper ()->note_width ()/2;
117     correct = - (Real)dir_ * 2.0 * paper ()->rule_thickness ();
118     mol_p->translate_axis (dx, X_AXIS); // FIXME! ugh
119   }
120   
121   mol_p->translate_axis (coordinate_offset_f_ + correct, axis_);
122
123   return mol_p;
124 }
125
126
127 IMPLEMENT_IS_TYPE_B2 (Script,Item,Staff_side);
128
129 int
130 Script::compare (Script  *const&l1, Script *const&l2)
131 {
132   return l1->specs_p_->priority_i() - l2->specs_p_->priority_i ();
133 }
134
135 Script::~Script ()
136 {
137   delete specs_p_;
138 }
139  
140 Script::Script (Script const&s)
141   : Item (s), Staff_side(s)
142 {
143   specs_p_ = s.specs_p_ ? s.specs_p_->clone (): 0;
144   stem_l_ =s.stem_l_;
145   postbreak_only_b_ = s.postbreak_only_b_;
146 }
147