]> git.donarmstrong.com Git - lilypond.git/blob - stem.cc
release: 0.0.8
[lilypond.git] / stem.cc
1 #include "stem.hh"
2 #include "dimen.hh" 
3 #include "debug.hh"
4 #include "pstaff.hh"
5 #include "pscore.hh"
6 #include "paper.hh"
7 #include "lookupsyms.hh"
8 #include "molecule.hh"
9
10 const int STEMLEN=7;
11
12 Stem::Stem(int c)
13 {
14     minnote = maxnote = 0;
15     bot = top = 0;
16     flag = 4;
17     staff_center=c;
18 }
19
20 void
21 Stem::print()const
22 {
23     mtor << "Stem minmax=["<< minnote<<","<<maxnote<<"], flag: "<<flag;
24     Item::print();
25 }
26
27 void
28 Stem::calculate()
29 {
30     assert(minnote<=maxnote);
31     int stafftop = 2*staff_center;
32
33     if (maxnote < -2){
34         bot = minnote;
35         top = staff_center - staff_center/2; // uhh... how about non 5-line staffs?
36         
37     }else if (minnote > stafftop + 2) {
38         top = maxnote;
39         bot = staff_center + staff_center/2;
40         flag = -flag;
41     }else {
42         Real mean = (minnote+maxnote)/2;
43         
44         top = (mean > staff_center) ? maxnote : maxnote+STEMLEN;
45         bot = (mean > staff_center) ? minnote-STEMLEN : minnote;
46         flag = (mean > staff_center) ? -flag : flag;
47     }
48 }
49
50 void
51 Stem::postprocess()
52 {
53     calculate();
54     brew_molecole();
55 }
56
57 Interval
58 Stem::width()const
59 {
60     if (ABS(flag) <= 4)
61         return Interval(0,0);   // TODO!
62     Paperdef*p= pstaff_->pscore_->paper_;
63     return p->lookup_->flag(flag).dim.x;
64 }
65
66 void
67 Stem::brew_molecole()
68 {
69     assert(pstaff_);
70     assert(bot!=top);
71     assert(!output);
72     
73     Paperdef *p = pstaff_->pscore_->paper_;
74     Parametric_symbol *stem = p->lookup_->stem();
75     
76     Real dy = p->interline()/2;
77     String y1 =print_dimen( dy * bot);
78     String y2 = print_dimen(dy * top);
79     Symbol ss =stem->eval(y1,y2);
80     delete stem;
81     
82     output = new Molecule(Atom(ss));
83
84     if (ABS(flag) > 4){
85         Symbol fl = p->lookup_->flag(flag);
86         Molecule m(fl);
87         if (flag < -4){         
88             output->add_bot(m);
89         } else if (flag > 4) {
90             output->add_top(m);
91         } else
92             assert(false); 
93     }
94
95     if (flag > 0){      
96         Real dx = pstaff_->pscore_->paper_->note_width(); // ugh
97         output->translate(Offset(dx,0));
98     }
99 }