lilypond-0.0.5
[lilypond.git] / line.cc
blobebe9595d3b78b1a94e534d9559cff414c56b3557
1 #include "line.hh"
2 #include "dimen.hh"
3 #include "symbol.hh"
4 #include "pcol.hh"
5 #include "pscore.hh"
7 String
8 Line_of_staff::TeXstring() const
10 String s("%line_of_staff\n\\vbox to ");
11 s += print_dimen(maxheight() ) +"{";
13 //make some room
14 s += vstrut(base);
16 // the staff itself: eg lines, accolades
17 s += "\\hbox{";
19 Symbol sym = pstaff_->get_stafsym(scor->score->linewidth);
20 s+=sym.tex;
21 PCursor<const PCol *> cc(scor->cols);
22 Real lastpos=cc->hpos;
24 // all items in the current line & staff.
25 for (; cc.ok(); cc++) {
26 Real delta=cc->hpos - lastpos;
27 lastpos = cc->hpos;
29 // moveover
30 s +=String( "\\kern ") + print_dimen(delta);
32 // now output the items.
34 for (PCursor<const Item *> ic(cc->its); ic.ok(); ic++) {
35 if (ic->pstaff_ == pstaff_)
36 s += ic->TeXstring();
38 // spanners.
39 for (PCursor<const Spanner *> sc(cc->starters); sc.ok(); sc++)
40 if (sc->pstaff_ == pstaff_)
41 s += sc->TeXstring();
44 s+="\\hss}\\vss}";
45 return s;
48 String
49 Line_of_score::TeXstring() const
51 String s("\\vbox{");
52 for (PCursor<Line_of_staff*> sc(staffs); sc.ok(); sc++){
53 s += sc->TeXstring();
54 if ((sc+1).ok())
55 s+= "\\interstaffline\n";
57 s += "}";
58 return s;
61 /// testing this entry
62 Line_of_score::Line_of_score(svec<const PCol *> sv,
63 const PScore *ps)
65 score = ps;
66 for (int i=0; i< sv.sz(); i++) {
67 PCol *p=(PCol *) sv[i];
68 cols.bottom().add(p);
69 p->line=this;
72 for (PCursor<PStaff*> sc(score->staffs); sc.ok(); sc++)
73 staffs.bottom().add(new Line_of_staff(this, sc));
75 /** construct a line with the named columns. Make the line field
76 in each column point to this
78 #sv# isn't really const!!
81 Line_of_staff::Line_of_staff(Line_of_score * sc, PStaff*st)
83 // [don't know how to calc dimensions yet.]
84 height = 0.0;
85 base =0.0;
87 scor=sc;
88 pstaff_=st;
90 const PCol *linestart= sc->cols.top();
91 const PCol *linestop=sc->cols.bottom();
93 for (PCursor<const Spanner*> sp(pstaff_->spans); sp.ok(); sp++) {
94 const PCol *brokenstart = &MAX(*linestart, *sp->left);
95 const PCol *brokenstop = &MIN(*linestop, *sp->right);
97 if (*brokenstop < *brokenstart)
98 brokenspans.bottom().add(sp->broken_at(brokenstop, brokenstart));
103 Real
104 Line_of_staff::maxheight() const
106 Interval y;
108 Symbol s = pstaff_->stafsym->eval(scor->score->linewidth);
109 y = s.dim.y;
111 PCursor<const PCol *> cc(scor->cols);
113 // all items in the current line & staff.
114 for (; cc.ok(); cc++) {
117 for (PCursor<const Item *> ic(cc->its); ic.ok(); ic++) {
118 if (ic->pstaff_ == pstaff_) {
119 y.unite(ic->height());
122 // spanners.
123 for (PCursor<const Spanner *> sc(cc->starters); sc.ok(); sc++)
124 if (sc->pstaff_ == pstaff_)
125 assert(false);
128 return y.max;