lilypond-1.1.31
[lilypond.git] / src / script.cc
blob2a31133c331d121f75c33fc3c024eba0e1191ec5
1 #include "musicalrequest.hh"
2 #include "paper-def.hh"
3 #include "script.hh"
4 #include "stem.hh"
5 #include "molecule.hh"
6 #include "lookup.hh"
10 void
11 Script::set_stem(Stem*st_l)
13 stem_l_ = st_l;
14 add_dependency(st_l);
17 void
18 Script::set_support(Item*i)
20 support.push(i);
21 add_dependency(i);
24 Script::Script(Script_req* rq, int staflen)
26 staffsize =staflen;
27 specs_l_ = rq->scriptdef_p_;
28 stem_l_ = 0;
29 pos = 0;
30 symdir=1;
31 dir =rq->dir_i_;
34 void
35 Script::set_symdir()
37 if (specs_l_->invertsym)
38 symdir = (dir < 0) ? -1:1;
41 void
42 Script::set_default_dir()
44 if (specs_l_->stemdir) {
45 if (!stem_l_)
46 dir = 1;
47 else
48 dir = stem_l_->dir * specs_l_->stemdir;
52 Interval
53 Script::support_height() const return r;
55 for (int i=0; i < support.size(); i++)
56 r.unite(support[i]->height());
59 void
60 Script::set_default_index()
62 Real inter_f= paper()->internote();
63 Interval dy = symbol().dim.y;
65 int d = specs_l_->staffdir;
66 Real y ;
67 if (!d) {
68 Interval v= support_height();
69 y = v[dir] -dy[-dir] + 2*dir*inter_f;
70 } else {
71 y = (d > 0) ? staffsize + 2: -2; // ug
72 y *=inter_f;
73 Interval v= support_height();
75 if (d > 0) {
76 y = y >? v.max();
77 } else if (d < 0) {
78 y = y <? v.min();
82 if (stem_l_) {
83 Interval v= stem_l_->height();
85 if (d > 0 || (!d && dir > 0)) {
86 y = y >? v.max();
87 }else if (d < 0 || (!d && dir < 0)) {
88 y = y <? v.min();
92 pos = int(rint(Real(y)/inter_f));
95 Interval
96 Script::width() const
98 return symbol().dim.x;
101 Symbol
102 Script::symbol()const
104 String preidx_str = (symdir < 0) ?"-" :"";
105 return paper()->lookup_p_->script(preidx_str + specs_l_->symidx);
108 void
109 Script::do_pre_processing()
111 set_default_dir();
112 set_symdir();
115 void
116 Script::do_post_processing()
118 set_default_index();
121 Molecule*
122 Script::brew_molecule_p() const
124 Real dy = paper()->internote();
126 Molecule*out = new Molecule(Atom(symbol()));
127 out->translate(Offset(0,dy * pos));
128 return out;