lilypond-1.1.9
[lilypond.git] / lily / script.cc
blob26900c5c2e138c82a9a61378d554fe04e26ba62d
1 /*
2 script.cc -- implement Script
4 source file of the GNU LilyPond music typesetter
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"
16 void
17 Script::do_print () const
19 #ifndef NPRINT
20 specs_p_->print ();
21 #endif
24 void
25 Script::do_substitute_dependency (Score_element*o,Score_element*n)
27 Staff_side::do_substitute_dependency (o,n);
28 if (o == stem_l_)
30 stem_l_ = dynamic_cast<Stem *> (n);
34 void
35 Script::set_stem (Stem*st_l)
37 stem_l_ = st_l;
38 add_support (st_l);
42 Script::Script ()
44 axis_ = Y_AXIS;
45 specs_p_ = 0;
46 stem_l_ = 0;
47 postbreak_only_b_ = true;
48 dir_ = CENTER;
51 void
52 Script::set_default_dir ()
54 int s_i=specs_p_->rel_stem_dir ();
55 if (s_i)
57 if (stem_l_)
58 dir_ = Direction (stem_l_->dir_ * s_i);
59 else
61 specs_p_->warning (_ ("script needs stem direction"));
62 dir_ = DOWN;
65 else
67 dir_ =specs_p_->staff_dir ();
69 assert (dir_);
73 Interval
74 Script::do_width () const
76 return specs_p_->get_atom (paper (), dir_).extent ().x ();
79 void
80 Script::do_pre_processing ()
82 Staff_side::do_pre_processing ();
83 if (breakable_b_ && postbreak_only_b_ && (break_status_dir () != RIGHT))
85 transparent_b_ = true;
86 set_empty (true);
89 if (axis_ == Y_AXIS && !dir_)
90 set_default_dir ();
93 Interval
94 Script::symbol_height () const
96 return specs_p_->get_atom (paper (), dir_).extent ().y ();
99 Interval
100 Script::symbol_width () const
102 return specs_p_->width (paper ());
105 Molecule*
106 Script::brew_molecule_p () const
108 Real dx =0.;
110 Molecule*mol_p = new Molecule (specs_p_->get_atom (paper (), dir_));
112 ugh, staccato dots are not centred between stafflines (how?)?
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
121 mol_p->translate_axis (coordinate_offset_f_ + correct, axis_);
123 return mol_p;
130 Script::compare (Script *const&l1, Script *const&l2)
132 return l1->specs_p_->priority_i() - l2->specs_p_->priority_i ();
135 Script::~Script ()
137 delete specs_p_;
140 Script::Script (Script const&s)
141 : Item (s), Staff_side(s)
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_;