]> git.donarmstrong.com Git - lilypond.git/blob - src/script.cc
eab30f9cbbf636557513da5968b727eb940abbf4
[lilypond.git] / src / script.cc
1 #include "request.hh"
2 #include "paper.hh"
3 #include "script.hh"
4 #include "stem.hh"
5 #include "molecule.hh"
6 #include "lookup.hh"
7
8 Script::Script(Script_req* rq, Item*i , int staflen, Stem*st_l)
9 {
10     dependencies.add(st_l);
11     dependencies.add(i);
12     
13     staffsize =staflen;
14     specs_l_ = rq->scriptdef;
15     support= i;
16     stem_l_ = st_l;
17     pos = 0;
18     symdir=1;
19     dir =rq->dir;
20 }
21
22 void
23 Script::set_symdir()
24 {
25     if (specs_l_->invertsym)
26         symdir = (dir < 0) ? -1:1;
27 }
28
29 void
30 Script::set_default_dir()
31 {
32     if (specs_l_->stemdir) {
33         if (!stem_l_)
34             dir = 1;
35         else
36             dir = stem_l_->dir * specs_l_->stemdir;
37     }
38 }
39
40 void
41 Script::set_default_pos()
42 {
43     Real inter_f= paper()->internote();
44     Interval dy = symbol().dim.y;
45     
46     int d = specs_l_->staffdir;
47     Real y  ;
48     if (!d) {
49         Interval v= support->height();
50         y = v[dir]  -dy[-dir] + 2*dir*inter_f;
51     } else {
52         Real y  = (d > 0) ? staffsize + 2: -2; // ug
53         y *=inter_f;
54         Interval v= support->height();
55
56         if (d > 0) {
57             y = y >? v.max();
58         } else if (d < 0) {
59             y = y <? v.min();
60         }
61     }
62     if (stem_l_) {
63         Interval v= stem_l_->height();
64
65         if (d > 0 || (!d && dir > 0)) {
66             y = y >? v.max();
67         }else if (d < 0 || (!d && dir < 0)) {
68             y = y <? v.min();
69         }
70     }
71     
72     pos = int(rint(Real(y)/inter_f));
73 }
74
75 Interval
76 Script::width() const
77 {
78     return symbol().dim.x;
79 }
80
81 Symbol
82 Script::symbol()const
83 {
84     String preidx_str = (symdir < 0) ?"-" :"";
85     return paper()->lookup_p_->script(preidx_str + specs_l_->symidx);
86 }
87
88 void
89 Script::do_pre_processing()
90 {
91     set_default_dir();
92     set_symdir();
93 }
94
95 void
96 Script::do_post_processing()
97 {
98     set_default_pos();
99 }
100
101 Molecule*
102 Script::brew_molecule_p() const
103 {
104     Real dy = paper()->internote();
105     
106     Molecule*out = new Molecule(Atom(symbol()));
107     out->translate(Offset(0,dy * pos));
108     return out;
109 }