]> git.donarmstrong.com Git - lilypond.git/blob - src/script.cc
release: 0.0.32
[lilypond.git] / src / script.cc
1 #include "musicalrequest.hh"
2 #include "paperdef.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     add_depedency(st_l);
15 }
16
17 void
18 Script::set_support(Item*i)
19 {
20     support.push(i);
21     add_depedency(i);
22 }
23
24 Script::Script(Script_req* rq, int staflen)
25 {    
26     staffsize =staflen;
27     specs_l_ = rq->scriptdef_p_;
28     stem_l_ = 0;
29     pos = 0;
30     symdir=1;
31     dir =rq->dir_i_;
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         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     
82     if (stem_l_) {
83         Interval v= stem_l_->height();
84
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();
89         }
90     }
91     
92     pos = int(rint(Real(y)/inter_f));
93 }
94
95 Interval
96 Script::width() const
97 {
98     return symbol().dim.x;
99 }
100
101 Symbol
102 Script::symbol()const
103 {
104     String preidx_str = (symdir < 0) ?"-" :"";
105     return paper()->lookup_p_->script(preidx_str + specs_l_->symidx);
106 }
107
108 void
109 Script::do_pre_processing()
110 {
111     set_default_dir();
112     set_symdir();
113 }
114
115 void
116 Script::do_post_processing()
117 {
118     set_default_pos();
119 }
120
121 Molecule*
122 Script::brew_molecule_p() const
123 {
124     Real dy = paper()->internote();
125     
126     Molecule*out = new Molecule(Atom(symbol()));
127     out->translate(Offset(0,dy * pos));
128     return out;
129 }