]> git.donarmstrong.com Git - lilypond.git/blob - src/staffline.cc
release: 0.0.11
[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 "pcol.hh"
8 #include "pscore.hh"
9
10 static String
11 make_vbox(Interval i)
12 {    
13     String s("\\vbox to ");
14     s += print_dimen(i.length());
15     s += "{\\vskip "+print_dimen(i.max)+" ";
16     return s;
17 }
18
19     
20 String
21 Line_of_staff::TeXstring() const
22 {
23     String s("%line_of_staff\n");
24     s+=make_vbox(height());
25     // the staff itself: eg lines, accolades
26     s += "\\hbox{";
27     {
28         Symbol sym = pstaff_->get_stafsym(line_of_score_->pscore_-> // ugh
29                                           paper_->linewidth);
30         s+=sym.tex;
31         PCursor<const PCol *> cc(line_of_score_->cols);
32         Real lastpos=cc->hpos;
33
34         // all items in the current line & staff.
35         for (; cc.ok(); cc++) {
36             Real delta=cc->hpos - lastpos;
37             lastpos = cc->hpos;
38
39             // moveover
40             if (delta)
41                 s +=String( "\\kern ") + print_dimen(delta);
42
43             // now output the items.
44
45             for (PCursor<const Item *> ic(cc->its); ic.ok(); ic++) {
46                 if (ic->pstaff_ == pstaff_)
47                     s += ic->TeXstring();
48             }
49             // spanners.
50             for (PCursor<const Spanner *> sc(cc->starters); sc.ok(); sc++)
51                 if (sc->pstaff_ == pstaff_)
52                     s += sc->TeXstring();
53         }
54     }
55     s+="\\hss}\\vss}";
56     return s;
57 }
58
59 Line_of_staff::Line_of_staff(Line_of_score * sc, PStaff*st)
60 {
61     line_of_score_=sc;
62     pstaff_=st;
63
64     
65     const PCol *linestart = sc->cols.top();
66     const PCol *linestop = sc->cols.bottom();
67
68     
69     for (PCursor<const Spanner*> sp(pstaff_->spans); sp.ok(); sp++) {
70         const PCol *brokenstart = &MAX(*linestart, *sp->left);
71         const PCol *brokenstop = &MIN(*linestop, *sp->right);
72         if ( *brokenstart < *brokenstop) {
73             line_of_score_->pscore_-> // higghl
74                 add_broken(sp->broken_at(brokenstart,brokenstop));
75         }
76     }
77 }
78
79
80 Interval
81 Line_of_staff::height() const
82 {
83     Interval y;
84     {
85         Symbol s = pstaff_->stafsym->eval(line_of_score_->pscore_->
86                                           paper_->linewidth);
87         y = s.dim.y;
88     }
89     PCursor<const PCol *> cc(line_of_score_->cols);
90     
91     // all items in the current line & staff.
92     for (; cc.ok(); cc++) {
93         for (PCursor<const Item *> ic(cc->its); ic.ok(); ic++) {
94             if (ic->pstaff_ == pstaff_) {
95                 y.unite(ic->height());
96         }
97             
98         // spanners.
99         for (PCursor<const Spanner *> sc(cc->starters); sc.ok(); sc++)
100             if (sc->pstaff_ == pstaff_) {
101                 y.unite(sc->height());
102             }
103         }
104     }
105     return y;
106 }
107
108