]> git.donarmstrong.com Git - lilypond.git/blob - lily/script.cc
4e57c3ddf5297f4df21dc9db07622e051edc4b35
[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 Han-Wen Nienhuys <hanwen@stack.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_l_->print();
21 #endif
22 }
23
24 void
25 Script::do_substitute_dependency (Score_elem*o,Score_elem*n)
26 {
27   Staff_side::do_substitute_dependency (o,n);
28   if (o == stem_l_)
29     {
30       stem_l_ = n ? (Stem*)n->item() : 0;
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   specs_l_ = 0;
45   stem_l_ = 0;
46   dir_ =  CENTER;
47 }
48
49 void
50 Script::set_default_dir()
51 {
52   int s_i=specs_l_->rel_stem_dir();
53   if (s_i)
54     {
55       if (stem_l_)
56         dir_ = Direction(stem_l_->dir_ * s_i);
57       else
58         {
59           specs_l_->warning (_("Script needs stem direction"));
60           dir_ = DOWN;
61         }
62     }
63   else
64     {
65       dir_ =specs_l_->staff_dir();
66     }
67   assert (dir_);
68 }
69
70
71 Interval
72 Script::do_width() const
73 {
74   return specs_l_->get_atom (paper(), dir_).extent ().x ();
75 }
76
77 void
78 Script::do_pre_processing()
79 {
80   if  (breakable_b_ && break_status_i() != 1)
81     {
82       transparent_b_ = true;
83       set_empty (true);
84     }
85
86   if (!dir_)
87     set_default_dir();
88 }
89
90 Interval
91 Script::symbol_height() const
92 {
93   return specs_l_->get_atom (paper(), dir_).extent ().y ();
94 }
95
96 Molecule*
97 Script::brew_molecule_p() const
98 {
99   Real dx = paper()->note_width()/2;
100
101   Molecule*out = new Molecule (specs_l_->get_atom (paper(), dir_));
102   out->translate_axis (y_, Y_AXIS);
103   out->translate_axis (dx, X_AXIS);     // FIXME! ugh
104   return out;
105 }
106
107
108 IMPLEMENT_IS_TYPE_B2(Script,Item,Staff_side);
109
110 int
111 Script::compare (Script  *const&l1, Script *const&l2)
112 {
113   return l1->specs_l_->priority_i() - l2->specs_l_->priority_i ();
114 }