]> git.donarmstrong.com Git - lilypond.git/blob - lily/script.cc
release: 0.0.70pre
[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         stem_l_ = n ? (Stem*)n->item() : 0;
30     }
31 }
32
33 void
34 Script::set_stem(Stem*st_l)
35 {
36     stem_l_ = st_l;
37     add_support(st_l);
38 }
39
40
41 Script::Script()
42 {    
43     specs_l_ = 0;
44     inside_staff_b_ = false;
45     stem_l_ = 0;
46     pos_i_ = 0;
47     dir_i_ =  0;
48 }
49
50 void
51 Script::set_default_dir()
52 {
53     int s_i=specs_l_->rel_stem_dir_i();
54     if (s_i) { 
55         if(stem_l_)
56             dir_i_ = stem_l_->dir_i_ * s_i;
57         else{ 
58             specs_l_->warning("Script needs stem direction");
59             dir_i_ = -1;
60         }
61     } else {
62         dir_i_ =specs_l_->staff_dir_i();
63     }
64     assert(dir_i_);
65 }
66
67 void
68 Script::set_default_index()
69 {
70     pos_i_ = get_position_i(specs_l_->get_atom(paper(), dir_i_).extent().y);
71 }
72
73 Interval
74 Script::do_width() const
75 {
76     return specs_l_->get_atom(paper(), dir_i_).extent().x;
77 }
78
79 void
80 Script::do_pre_processing()
81 {
82     if (!dir_i_)
83         set_default_dir();
84     inside_staff_b_ = specs_l_->inside_b();
85 }
86
87 void
88 Script::do_post_processing()
89 {
90     set_default_index();
91 }
92
93 Molecule*
94 Script::brew_molecule_p() const
95 {
96     Real dy = paper()->internote_f();
97     
98     Molecule*out = new Molecule(specs_l_->get_atom(paper(), dir_i_));
99     out->translate_y(dy * pos_i_);
100     return out;
101 }
102
103 IMPLEMENT_STATIC_NAME(Script);
104 IMPLEMENT_IS_TYPE_B2(Script,Item,Staff_side);
105
106 int 
107 Script::compare(Script  *const&l1, Script *const&l2) 
108 {
109     return l1->specs_l_->priority_i() - l2->specs_l_->priority_i();
110 }
111