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