]> git.donarmstrong.com Git - lilypond.git/blob - lily/multi-measure-rest.cc
patch::: 1.1.52.mb2
[lilypond.git] / lily / multi-measure-rest.cc
1 /*   
2   multi-measure-rest.cc --  implement Multi_measure_rest
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1998--1999, 1999 Jan Nieuwenhuizen <janneke@gnu.org>
7   
8  */
9
10 #include "multi-measure-rest.hh"
11 #include "debug.hh"
12 #include "paper-def.hh"
13 #include "p-col.hh" // urg
14 #include "bar.hh"
15 #include "lookup.hh"
16 #include "rest.hh"
17 #include "molecule.hh"
18 #include "misc.hh"
19
20
21 Multi_measure_rest::Multi_measure_rest ()
22 {
23   measures_i_ = 0;
24 }
25
26 void
27 Multi_measure_rest::do_print () const
28 {
29 #ifndef NPRINT
30   DOUT << "measures_i_ " << measures_i_;
31 #endif
32 }
33
34
35
36 /*
37    [TODO]                                          17
38  * variable-sized multi-measure rest symbol: |====| ??
39  
40  * build 3, 5, 6, 7, 8 symbols (how far, property?)
41        from whole, brevis and longa rests
42
43 */
44 Molecule*
45 Multi_measure_rest::do_brew_molecule_p () const
46 {
47   Interval sp_iv;
48   Direction d = LEFT;
49   do
50     {
51       Item * col = spanned_drul_[d]->column_l ();
52
53       Interval coldim = col->extent (X_AXIS);
54
55       sp_iv[d] = coldim[-d]  ;
56     }
57   while ((flip (&d)) != LEFT);
58   Molecule *mol_p  = new Molecule;
59   Real x_off = 0.0;
60
61
62   Dimension_cache * col_ref = spanned_drul_[LEFT]->column_l ()->dim_cache_[X_AXIS];
63
64   Real rx  = spanned_drul_[LEFT]->absolute_coordinate (X_AXIS);
65   /*
66     we gotta stay clear of sp_iv, so move a bit to the right if
67     needed.
68    */
69   x_off += (sp_iv[LEFT] -  rx) >? 0;
70
71   /*
72     center between stuff.
73    */
74   x_off += sp_iv.length ()/ 2;
75
76   
77   Molecule s;
78   bool rest_symbol=true;
79   SCM alt_symbol_sym =get_elt_property (alt_symbol_scm_sym);
80   if (alt_symbol_sym != SCM_BOOL_F)
81     {
82       s = lookup_l () -> afm_find (ly_scm2string (SCM_CDR(alt_symbol_sym)));
83       rest_symbol = false;
84     }
85   else if (measures_i_ == 1 || measures_i_ == 2 || measures_i_ == 4) 
86     {
87       s = lookup_l ()->rest (- intlog2(measures_i_), 0, "");
88       s.translate_axis (-s.extent ()[X_AXIS].length () / 2, X_AXIS);
89     }
90   else 
91     {
92       s = lookup_l ()->rest (-4, 0, "");
93     }
94   mol_p->add_molecule (s);
95   Real interline_f = staff_line_leading_f ();
96   if (measures_i_ == 1 && rest_symbol)
97     {
98       mol_p->translate_axis (interline_f, Y_AXIS);
99     }
100   else if (measures_i_ > 1)
101     {
102       Molecule s ( lookup_l ()->text ("number", to_str (measures_i_), paper_l ()));
103
104       s.translate_axis (3.0 * interline_f, Y_AXIS);
105       mol_p->add_molecule (s);
106     }
107   mol_p->translate_axis (x_off, X_AXIS);
108   return mol_p;
109 }
110
111 void
112 Multi_measure_rest::do_add_processing ()
113 {
114   if (column_arr_.size ())
115     {
116       set_bounds (LEFT, column_arr_[0 >? column_arr_.size () - 2]);
117       set_bounds (RIGHT, column_arr_[column_arr_.size () - 1]);
118     }
119 }
120   
121 void
122 Multi_measure_rest::do_post_processing ()
123 {
124   if (!column_arr_.size ())
125     set_elt_property (transparent_scm_sym, SCM_BOOL_T);
126 }
127
128
129 void
130 Multi_measure_rest::do_substitute_element_pointer (Score_element* o, Score_element* n)
131 {
132   Staff_symbol_referencer::do_substitute_element_pointer (o,n);
133   if (Item* c = dynamic_cast <Item*> (o))
134     column_arr_.substitute (c, dynamic_cast<Item*> (n));
135 }
136   
137 void
138 Multi_measure_rest::add_column (Item* c)
139 {
140   column_arr_.push (c);
141   add_dependency (c);
142 }
143
144
145 Array<Rod>
146 Multi_measure_rest::get_rods () const
147 {
148   Array<Rod> a;
149
150   if (!(spanned_drul_[LEFT] && spanned_drul_[RIGHT]))
151     {
152       programming_error ("Multi_measure_rest::get_rods (): I am not spanned!");
153         return a;
154     }
155       Rod r;
156       r.item_l_drul_ = spanned_drul_;
157       r.distance_f_ = paper_l ()->get_var ("mmrest_x_minimum");
158       a.push (r);
159
160   
161   /*
162     also set distances in case the left or right ending of the rest is
163     a broken column. This is very common: it happens if the rest is in
164     the beginning of the line, or at the end.
165
166     TODO: merge this code with other discretionary handling code.
167
168     TODO: calc  mmrest_x_minimum (see brew_molecule_p ())
169   */
170
171   Drul_array<Item*> discretionaries;
172   Direction d = LEFT;
173   do
174     {
175       Item *i = r.item_l_drul_[d]->find_prebroken_piece (-d);
176       discretionaries[d] = i;
177       if (i)
178       {
179         Rod k (r);
180
181         k.item_l_drul_[d] = i;
182         a.push (k);
183       }
184     }
185   while ((flip (&d))!= LEFT);
186
187   if (discretionaries[LEFT] && discretionaries[RIGHT])
188     {
189       Rod k(r);
190       k.item_l_drul_ = discretionaries;
191       a.push (k);
192     }
193
194
195
196   return a;
197 }