lilypond-1.1.55
[lilypond.git] / lily / multi-measure-rest.cc
blobb249a1b9a3a511af9b87956722b37a1023f6e8a2
1 /*
2 multi-measure-rest.cc -- implement Multi_measure_rest
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--1999, 1999 Jan Nieuwenhuizen <janneke@gnu.org>
8 */
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"
21 Multi_measure_rest::Multi_measure_rest ()
23 measures_i_ = 0;
26 void
27 Multi_measure_rest::do_print () const
29 #ifndef NPRINT
30 DOUT << "measures_i_ " << measures_i_;
31 #endif
37 [TODO] 17
38 * variable-sized multi-measure rest symbol: |====| ??
40 * build 3, 5, 6, 7, 8 symbols (how far, property?)
41 from whole, brevis and longa rests
44 Molecule*
45 Multi_measure_rest::do_brew_molecule_p () const
47 Interval sp_iv;
48 Direction d = LEFT;
51 Item * col = spanned_drul_[d]->column_l ();
53 Interval coldim = col->extent (X_AXIS);
55 sp_iv[d] = coldim[-d] ;
57 while ((flip (&d)) != LEFT);
58 Molecule *mol_p = new Molecule;
59 Real x_off = 0.0;
62 Dimension_cache * col_ref = spanned_drul_[LEFT]->column_l ()->dim_cache_[X_AXIS];
64 Real rx = spanned_drul_[LEFT]->absolute_coordinate (X_AXIS);
66 we gotta stay clear of sp_iv, so move a bit to the right if
67 needed.
69 x_off += (sp_iv[LEFT] - rx) >? 0;
72 center between stuff.
74 x_off += sp_iv.length ()/ 2;
77 Molecule s;
78 if (measures_i_ == 1 || measures_i_ == 2 || measures_i_ == 4)
80 s = lookup_l ()->rest (- intlog2(measures_i_), 0, "");
81 s.translate_axis (-s.extent ()[X_AXIS].length () / 2, X_AXIS);
83 else
85 s = lookup_l ()->rest (-4, 0, "");
87 mol_p->add_molecule (s);
88 Real interline_f = staff_line_leading_f ();
89 if (measures_i_ == 1)
91 mol_p->translate_axis (interline_f, Y_AXIS);
93 else if (measures_i_ > 1)
95 Molecule s ( lookup_l ()->text ("number", to_str (measures_i_)));
97 s.translate_axis (3.0 * interline_f, Y_AXIS);
98 mol_p->add_molecule (s);
101 mol_p->translate_axis (x_off, X_AXIS);
102 return mol_p;
105 void
106 Multi_measure_rest::do_add_processing ()
108 if (column_arr_.size ())
110 set_bounds (LEFT, column_arr_[0 >? column_arr_.size () - 2]);
111 set_bounds (RIGHT, column_arr_[column_arr_.size () - 1]);
115 void
116 Multi_measure_rest::do_post_processing ()
118 if (!column_arr_.size ())
119 set_elt_property (transparent_scm_sym, SCM_BOOL_T);
123 void
124 Multi_measure_rest::do_substitute_element_pointer (Score_element* o, Score_element* n)
126 Staff_symbol_referencer::do_substitute_element_pointer (o,n);
127 if (Item* c = dynamic_cast <Item*> (o))
128 column_arr_.substitute (c, dynamic_cast<Item*> (n));
131 void
132 Multi_measure_rest::add_column (Item* c)
134 column_arr_.push (c);
135 add_dependency (c);
139 Array<Rod>
140 Multi_measure_rest::get_rods () const
142 Array<Rod> a;
144 if (!(spanned_drul_[LEFT] && spanned_drul_[RIGHT]))
146 programming_error ("Multi_measure_rest::get_rods (): I am not spanned!");
147 return a;
149 Rod r;
150 r.item_l_drul_ = spanned_drul_;
151 r.distance_f_ = paper_l ()->get_var ("mmrest_x_minimum");
152 a.push (r);
156 also set distances in case the left or right ending of the rest is
157 a broken column. This is very common: it happens if the rest is in
158 the beginning of the line, or at the end.
160 TODO: merge this code with other discretionary handling code.
162 TODO: calc mmrest_x_minimum (see brew_molecule_p ())
165 Drul_array<Item*> discretionaries;
166 Direction d = LEFT;
169 Item *i = r.item_l_drul_[d]->find_prebroken_piece (-d);
170 discretionaries[d] = i;
171 if (i)
173 Rod k (r);
175 k.item_l_drul_[d] = i;
176 a.push (k);
179 while ((flip (&d))!= LEFT);
181 if (discretionaries[LEFT] && discretionaries[RIGHT])
183 Rod k(r);
184 k.item_l_drul_ = discretionaries;
185 a.push (k);
190 return a;