]> git.donarmstrong.com Git - lilypond.git/blob - lily/scoreline.cc
release: 0.0.65
[lilypond.git] / lily / scoreline.cc
1 /*
2   scoreline.cc -- implement Line_of_score
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996, 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "scoreline.hh"
10 #include "staffline.hh"
11 #include "dimen.hh"
12 #include "spanner.hh"
13 #include "symbol.hh"
14 #include "paper-def.hh"
15 #include "p-col.hh"
16 #include "p-score.hh"
17
18
19 /* To do:
20    take out hard coded TeX stuff.
21    
22    */
23 String
24 Line_of_score::TeX_string() const
25 {
26      String s("\\hbox{%<- line of score\n");
27      if (error_mark_b_)
28          s+= "\\scorelineerrormark";
29      
30      
31      Real lastpos = cols[0]->hpos;
32      for (int i=0; i < cols.size();  i++){
33          PCol* col_l= cols[i];
34          // all items in the current line & staff.
35          String chunk_str;
36          Real delta  = col_l->hpos - lastpos;
37             
38             
39          if (col_l->error_mark_b_) {
40              chunk_str += String("\\columnerrormark");
41          }
42          // now output the items.
43          for (iter_top(col_l->its,j); j.ok(); j++) {
44              chunk_str += j->TeX_string();
45          }
46          // spanners.
47          for (iter_top(col_l->starters,j); j.ok(); j++) {
48              if (j->name() != name())
49                  chunk_str += j->TeX_string();
50          }
51          if (chunk_str!="") {
52              // moveover
53              if (delta)
54                  s +=String( "\\kern ") + print_dimen(delta);
55              s += chunk_str;
56              lastpos = col_l->hpos;
57          }
58      }
59      s += "}";
60      return s;
61 }
62
63
64 Line_of_score::Line_of_score()
65 {
66     error_mark_b_ = 0;
67 }
68
69
70 void
71 Line_of_score::do_substitute_dependency(Score_elem*o, Score_elem*n)
72 {
73     Spanner_elem_group::do_substitute_dependency(o,n);
74     
75     int i;
76     while ((i =line_arr_.find_i((Spanner_elem_group*)o->spanner())) >=0)
77         if (n)
78             line_arr_[i] = (Spanner_elem_group*)n->spanner();
79         else 
80             line_arr_.del(i);
81 }
82
83
84 void
85 Line_of_score::do_post_processing()
86 {
87     Real y_pos=0;
88     for (int i=line_arr_.size(); i--; ) {
89         Interval y = line_arr_[i]->height() ;
90         if (y.empty_b())
91             continue;
92         line_arr_[i]->translate(Offset(0, -y[-1] + y_pos));
93         y_pos += y.length();
94     }
95     translate(Offset(0, -y_pos));
96 }
97
98 IMPLEMENT_STATIC_NAME(Line_of_score);
99
100 void
101 Line_of_score::add_line(Spanner_elem_group*e)
102 {
103     add_element(e);
104     line_arr_.push(e);
105 }
106
107 bool
108 Line_of_score::contains_b(PCol const* c)const
109 {
110     return cols.find_l((PCol*)c);
111 }
112
113 void
114 Line_of_score::do_pre_processing()
115 {
116     left_col_l_ = pscore_l_->cols.top();
117     right_col_l_ = pscore_l_->cols.bottom();
118     for (int i=0; i < line_arr_.size(); i++){
119         line_arr_[i]->left_col_l_ = left_col_l_;
120         line_arr_[i]->right_col_l_ = right_col_l_;
121     }
122 }
123
124 void
125 Line_of_score::set_breaking(Array<Col_hpositions> const &breaking)
126 {
127     for (int j=0; j < breaking.size(); j++) {
128         const Array<PCol*> &curline(breaking[j].cols);
129         const Array<PCol*> &errors(breaking[j].error_col_l_arr_);
130         const Array<Real> &config(breaking[j].config);
131         
132         for (int i=0; i < errors.size(); i++)
133             errors[i]->error_mark_b_ = true;
134
135         Line_of_score *line_p = (Line_of_score*)clone();
136         for (int i=0; i < curline.size(); i++){
137             curline[i]->hpos = config[i];
138             curline[i]->line_l_ = (Line_of_score*)line_p;
139         }
140         ((Array<PCol*> &)line_p->cols) = curline;
141         line_p->left_col_l_ =  curline[0];
142         line_p->right_col_l_= curline.top();
143         pscore_l_->typeset_broken_spanner(line_p);
144         broken_into_l_arr_.push(line_p);
145     }
146 }
147
148 void
149 Line_of_score::break_into_pieces()
150 {
151     
152 }
153
154 Link_array<Line_of_score>
155 Line_of_score::get_lines()const
156 {
157     Link_array<Line_of_score> ret;
158     assert(broken_into_l_arr_.size());
159     for (int i=0; i < broken_into_l_arr_.size(); i++) {
160         ret.push((Line_of_score*)broken_into_l_arr_[i]);
161     }
162     return ret;
163 }