lilypond-1.3.100
[lilypond.git] / lily / multi-measure-rest.cc
blobceb5657642211ad4eace1b44b4e933e6f177add1
1 /*
2 multi-measure-rest.cc -- implement Multi_measure_rest
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2000 Jan Nieuwenhuizen <janneke@gnu.org>
8 */
10 #include "multi-measure-rest.hh"
11 #include "debug.hh"
12 #include "paper-def.hh"
13 #include "paper-column.hh" // urg
14 #include "font-interface.hh"
15 #include "rest.hh"
16 #include "molecule.hh"
17 #include "misc.hh"
18 #include "group-interface.hh"
19 #include "spanner.hh"
20 #include "staff-symbol-referencer.hh"
21 #include "text-item.hh"
23 void
24 Multi_measure_rest::set_interface (Score_element*me)
26 me->set_interface (ly_symbol2scm ("multi-measure-rest-interface"));
29 bool
30 Multi_measure_rest::has_interface (Score_element*me)
32 return me->has_interface (ly_symbol2scm ("multi-measure-rest-interface"));
36 [TODO] 17
37 * variable-sized multi-measure rest symbol: |====| ??
39 MAKE_SCHEME_CALLBACK(Multi_measure_rest,brew_molecule,1);
40 SCM
41 Multi_measure_rest::brew_molecule (SCM smob)
43 Score_element *me = unsmob_element (smob);
44 Spanner * sp = dynamic_cast<Spanner*> (me);
45 Real staff_space = Staff_symbol_referencer::staff_space (me);
47 Interval sp_iv;
48 Direction d = LEFT;
51 Item * col = sp->get_bound (d)->column_l ();
53 Interval coldim = col->extent (0, X_AXIS);
55 sp_iv[d] = coldim[-d] ;
57 while ((flip (&d)) != LEFT);
58 Molecule mol;
59 Real x_off = 0.0;
61 Real rx = sp->get_bound (LEFT)->relative_coordinate (0, X_AXIS);
63 we gotta stay clear of sp_iv, so move a bit to the right if
64 needed.
66 x_off += (sp_iv[LEFT] - rx) >? 0;
69 center between stuff.
71 x_off += sp_iv.length ()/ 2;
74 Molecule s;
76 int measures = 1;
77 SCM m (me->get_elt_property ("measure-count"));
78 if (gh_number_p (m))
80 measures = gh_scm2int (m);
84 SCM limit = me->get_elt_property ("expand-limit");
85 if (measures <= gh_scm2int (limit))
88 Build a rest from smaller parts. Distances inbetween are
89 really variable, see Wanske pp. 125 */
91 int l = measures;
92 while (l)
94 int k;
95 if (l >= 4)
97 l-=4;
98 k = -2;
100 else if (l>= 2)
102 l -= 2;
103 k = -1;
105 else
107 k = 0;
108 l --;
111 Real pad = s.empty_b ()
112 ? 0.0 : gh_scm2double (me->get_elt_property ("padding")) * staff_space;
114 Molecule r (Font_interface::get_default_font (me)->find_by_name ("rests-" + to_str (k)));
115 if (k == 0)
116 r.translate_axis (staff_space, Y_AXIS);
118 s.add_at_edge (X_AXIS, RIGHT, r, pad);
122 s.align_to (X_AXIS, CENTER);
124 else
126 String idx = ("rests-") + to_str (-4);
127 s = Font_interface::get_default_font (me)->find_by_name (idx);
130 mol.add_molecule (s);
132 if (measures > 1)
134 SCM properties = gh_list (me->mutable_property_alist_,
135 me->immutable_property_alist_,
136 SCM_UNDEFINED);
137 Molecule s =
138 Text_item::text2molecule (me,
139 ly_str02scm (to_str (measures).ch_C ()),
140 properties);
141 s.align_to (X_AXIS, CENTER);
142 s.translate_axis (3.0 * staff_space, Y_AXIS);
143 mol.add_molecule (s);
145 mol.translate_axis (x_off, X_AXIS);
146 return mol.create_scheme();
150 UGH. JUNKME elt prop "columns" isn't really needed.
152 void
153 Multi_measure_rest::add_column (Score_element*me,Item* c)
155 Pointer_group_interface::add_element (me, "columns",c);
157 add_bound_item (dynamic_cast<Spanner*> (me),c);
161 MAKE_SCHEME_CALLBACK (Multi_measure_rest, set_spacing_rods,1);
164 Multi_measure_rest::set_spacing_rods (SCM smob)
166 Score_element*me = unsmob_element (smob);
168 Spanner*sp = dynamic_cast<Spanner*> (me);
169 if (!(sp->get_bound (LEFT) && sp->get_bound (RIGHT)))
171 programming_error ("Multi_measure_rest::get_rods (): I am not spanned!");
172 return SCM_UNSPECIFIED;
175 Item * l = sp->get_bound (LEFT)->column_l ();
176 Item * r = sp->get_bound (RIGHT)->column_l ();
177 Item * lb = l->find_prebroken_piece (RIGHT);
178 Item * rb = r->find_prebroken_piece (LEFT);
180 Item* combinations[4][2]={{l,r}, {lb,r}, {l,rb},{lb,rb}};
181 Real staff_space = Staff_symbol_referencer::staff_space (me);
182 for (int i=0; i < 4; i++)
184 Item * l = combinations[i][0];
185 Item *r = combinations[i][1];
187 if (!l || !r)
188 continue;
190 Rod rod;
191 rod.item_l_drul_[LEFT] = l;
192 rod.item_l_drul_[RIGHT] = r;
195 should do something more advanced.
197 rod.distance_f_ = l->extent (l, X_AXIS)[BIGGER] - r->extent (r, X_AXIS)[SMALLER]
198 + gh_scm2double (me->get_elt_property ("minimum-width")) * staff_space;
200 rod.add_to_cols ();
202 return SCM_UNSPECIFIED;