lilypond-0.0.4
[lilypond.git] / line.cc
blobd0a5d794bbf90ab7f5878b1cf3bcd9a07d6e8912
1 #include "line.hh"
2 #include "symbol.hh"
3 #include "cols.hh"
4 #include "pscore.hh"
6 String
7 Line_of_staff::TeXstring() const
9 String s("%line_of_staff\n\\vbox to ");
10 s += String(maxheight() * VERT_TO_PT) +"pt{";
12 //make some room
13 s += vstrut(base* VERT_TO_PT);
15 // the staff itself: eg lines, accolades
16 s += "\\hbox{";
18 s+=(*pstaff_->stafsym)(scor->score->linewidth);
19 PCursor<const PCol *> cc(scor->cols);
20 Real lastpos=cc->hpos;
22 // all items in the current line & staff.
23 for (; cc.ok(); cc++) {
24 Real delta=cc->hpos - lastpos;
25 lastpos = cc->hpos;
27 // moveover
28 s +=String( "\\kern ") + HOR_TO_PT*delta + "pt ";
30 // now output the items.
32 for (PCursor<const Item *> ic(cc->its); ic.ok(); ic++) {
33 if (ic->pstaff_ == pstaff_)
34 s += ic->TeXstring();
36 // spanners.
37 for (PCursor<const Spanner *> sc(cc->starters); sc.ok(); sc++)
38 if (sc->pstaff_ == pstaff_)
39 s += sc->TeXstring();
42 s+="\\hss}\\vss}";
43 return s;
46 String
47 Line_of_score::TeXstring() const
49 String s("\\vbox{");
50 for (PCursor<Line_of_staff*> sc(staffs); sc.ok(); sc++){
51 s += sc->TeXstring();
52 if ((sc+1).ok())
53 s+= "\\interstaffline\n";
55 s += "}";
56 return s;
59 /// testing this entry
60 Line_of_score::Line_of_score(svec<const PCol *> sv,
61 const PScore *ps)
63 score = ps;
64 for (int i=0; i< sv.sz(); i++) {
65 PCol *p=(PCol *) sv[i];
66 cols.bottom().add(p);
67 p->line=this;
70 for (PCursor<PStaff*> sc(score->staffs); sc.ok(); sc++)
71 staffs.bottom().add(new Line_of_staff(this, sc));
73 /** construct a line with the named columns. Make the line field
74 in each column point to this
76 #sv# isn't really const!!
79 Line_of_staff::Line_of_staff(Line_of_score * sc, PStaff*st)
81 // [don't know how to calc dimensions yet.]
82 height = 0.0;
83 base =0.0;
85 scor=sc;
86 pstaff_=st;
88 const PCol *linestart= sc->cols.top();
89 const PCol *linestop=sc->cols.bottom();
91 for (PCursor<const Spanner*> sp(pstaff_->spans); sp.ok(); sp++) {
92 const PCol *brokenstart = &MAX(*linestart, *sp->left);
93 const PCol *brokenstop = &MIN(*linestop, *sp->right);
95 if (*brokenstop < *brokenstart)
96 brokenspans.bottom().add(sp->broken_at(brokenstop, brokenstart));
101 Real
102 Line_of_staff::maxheight() const
104 Interval y;
105 y = pstaff_->stafsym->height(scor->score->linewidth);
106 PCursor<const PCol *> cc(scor->cols);
108 // all items in the current line & staff.
109 for (; cc.ok(); cc++) {
112 for (PCursor<const Item *> ic(cc->its); ic.ok(); ic++) {
113 if (ic->pstaff_ == pstaff_) {
114 y.unite(ic->height());
117 // spanners.
118 for (PCursor<const Spanner *> sc(cc->starters); sc.ok(); sc++)
119 if (sc->pstaff_ == pstaff_)
120 assert(false);
123 return y.max;