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