]> git.donarmstrong.com Git - lilypond.git/blob - src/staffline.cc
release: 0.0.22
[lilypond.git] / src / staffline.cc
1 #include "staffline.hh"
2 #include "scoreline.hh"
3 #include "dimen.hh"
4 #include "spanner.hh"
5 #include "symbol.hh"
6 #include "paper.hh"
7 #include "molecule.hh"
8 #include "pcol.hh"
9 #include "pscore.hh"
10
11 static String
12 make_vbox(Interval i)
13 {    
14     String s("\\vbox to ");
15     s += print_dimen(i.length());
16     s += "{\\vskip "+print_dimen(i.right)+" ";
17     return s;
18 }
19
20     
21 String
22 Line_of_staff::TeXstring() const
23 {
24     String s("%line_of_staff\n");
25     s+=make_vbox(height());
26     // the staff itself: eg lines, accolades
27     s += "\\hbox{";
28     {                           
29         ((PStaff*)pstaff_l_)->
30             brew_molecule(line_of_score_l_->pscore_l_->paper_l_->linewidth);
31
32         s+=pstaff_l_->stafsym_p_->TeXstring();
33         iter_top(line_of_score_l_->cols,cc);
34         Real lastpos=cc->hpos;
35
36         // all items in the current line & staff.
37         for (; cc.ok(); cc++) {
38             Real delta=cc->hpos - lastpos;
39             lastpos = cc->hpos;
40
41             // moveover
42             if (delta)
43                 s +=String( "\\kern ") + print_dimen(delta);
44
45             // now output the items.
46
47             for (iter_top(cc->its,i); i.ok(); i++) {
48                 if (i->pstaff_l_ == pstaff_l_)
49                     s += i->TeXstring();
50             }
51             // spanners.
52             for (iter_top(cc->starters,i); i.ok(); i++)
53                 if (i->pstaff_l_ == pstaff_l_)
54                     s += i->TeXstring();
55         }
56     }
57     s+="\\hss}\\vss}";
58     return s;
59 }
60
61 Line_of_staff::Line_of_staff(Line_of_score * sc, PStaff*st)
62 {
63     line_of_score_l_=sc;
64     pstaff_l_=st;
65
66     PCol *linestart = sc->cols.top();
67     PCol *linestop = sc->cols.bottom();
68     
69     for (iter_top(pstaff_l_->spans,i); i.ok(); i++) {
70
71         PCol *brokenstart = &max(*linestart, *i->left);
72         PCol *brokenstop = &min(*linestop, *i->right);
73         if ( *brokenstart < *brokenstop) {
74             Spanner*span_p =i->broken_at(brokenstart,brokenstop);
75             line_of_score_l_->pscore_l_-> // higghl
76                 add_broken(span_p);
77         }
78     }
79 }
80
81
82 Interval
83 Line_of_staff::height() const
84 {
85     Interval y = pstaff_l_->stafsym_p_->extent().y;
86     iter_top(line_of_score_l_->cols,cc);
87     
88     // all items in the current line & staff.
89     for (; cc.ok(); cc++) {
90         for (iter_top(cc->its,i); i.ok(); i++) {
91             if (i->pstaff_l_ == pstaff_l_) 
92                 y.unite(i->height());
93             
94         }
95         // spanners.
96         for (iter_top(cc->starters,i); i.ok(); i++)
97             if (i->pstaff_l_ == pstaff_l_) {
98                 y.unite(i->height());
99             }
100     }
101     
102     return y;
103 }
104
105 void
106 Line_of_staff::process()
107 {
108     if (!pstaff_l_->stafsym_p_)
109         pstaff_l_->brew_molecule(line_of_score_l_->pscore_l_->
110                                paper_l_->linewidth);
111 }