]> git.donarmstrong.com Git - lilypond.git/blob - lily/script.cc
release: 1.1.28
[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_molecule (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_molecule (paper (), dir_).extent ().y ();
97 }
98
99
100 Molecule*
101 Script::do_brew_molecule_p () const
102 {
103   Real dx =0.;
104
105   Molecule*mol_p = new Molecule (specs_p_->get_molecule (paper (), dir_));
106   /*
107     ugh, staccato dots are not centred between stafflines (how?)?
108   */
109   Real correct =0.0;
110   if (axis_ == Y_AXIS){
111     dx =  paper ()->note_width ()/2;
112     correct = - (Real)dir_ * 2.0 * paper ()->rule_thickness ();
113     mol_p->translate_axis (dx, X_AXIS); // FIXME! ugh
114   }
115   
116   mol_p->translate_axis (coordinate_offset_f_ + correct, axis_);
117
118   return mol_p;
119 }
120
121
122
123
124 int
125 Script::compare (Script  *const&l1, Script *const&l2)
126 {
127   return l1->specs_p_->priority_i() - l2->specs_p_->priority_i ();
128 }
129
130 Script::~Script ()
131 {
132   delete specs_p_;
133 }
134  
135 Script::Script (Script const&s)
136   : Item (s), Staff_side(s)
137 {
138   specs_p_ = s.specs_p_ ? s.specs_p_->clone (): 0;
139   stem_l_ =s.stem_l_;
140   postbreak_only_b_ = s.postbreak_only_b_;
141 }
142