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