]> git.donarmstrong.com Git - lilypond.git/blob - src/script.cc
a6c3ee8039fa5b3d3678cbd89c512e8711a70afd
[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 NAME_METHOD(Script);
9
10 void
11 Script::set_stem(Stem*st_l)
12 {
13     stem_l_ = st_l;
14     dependencies.push(st_l);
15 }
16
17 void
18 Script::set_support(Item*i)
19 {
20     support.push(i);
21     dependencies.push(i);
22 }
23
24 Script::Script(Script_req* rq, int staflen)
25 {    
26     staffsize =staflen;
27     specs_l_ = rq->scriptdef;
28     stem_l_ = 0;
29     pos = 0;
30     symdir=1;
31     dir =rq->dir;
32 }
33
34 void
35 Script::set_symdir()
36 {
37     if (specs_l_->invertsym)
38         symdir = (dir < 0) ? -1:1;
39 }
40
41 void
42 Script::set_default_dir()
43 {
44     if (specs_l_->stemdir) {
45         if (!stem_l_)
46             dir = 1;
47         else
48             dir = stem_l_->dir * specs_l_->stemdir;
49     }
50 }
51
52 Interval
53 Script::support_height() const return r;
54 {
55     for (int i=0; i < support.size(); i++)
56         r.unite(support[i]->height());
57 }
58
59 void
60 Script::set_default_pos()
61 {
62     Real inter_f= paper()->internote();
63     Interval dy = symbol().dim.y;
64     
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         Real y  = (d > 0) ? staffsize + 2: -2; // ug
72         y *=inter_f;
73         Interval v= support_height();
74
75         if (d > 0) {
76             y = y >? v.max();
77         } else if (d < 0) {
78             y = y <? v.min();
79         }
80     }
81     if (stem_l_) {
82         Interval v= stem_l_->height();
83
84         if (d > 0 || (!d && dir > 0)) {
85             y = y >? v.max();
86         }else if (d < 0 || (!d && dir < 0)) {
87             y = y <? v.min();
88         }
89     }
90     
91     pos = int(rint(Real(y)/inter_f));
92 }
93
94 Interval
95 Script::width() const
96 {
97     return symbol().dim.x;
98 }
99
100 Symbol
101 Script::symbol()const
102 {
103     String preidx_str = (symdir < 0) ?"-" :"";
104     return paper()->lookup_p_->script(preidx_str + specs_l_->symidx);
105 }
106
107 void
108 Script::do_pre_processing()
109 {
110     set_default_dir();
111     set_symdir();
112 }
113
114 void
115 Script::do_post_processing()
116 {
117     set_default_pos();
118 }
119
120 Molecule*
121 Script::brew_molecule_p() const
122 {
123     Real dy = paper()->internote();
124     
125     Molecule*out = new Molecule(Atom(symbol()));
126     out->translate(Offset(0,dy * pos));
127     return out;
128 }