]> git.donarmstrong.com Git - lilypond.git/blob - lily/multi-measure-rest.cc
release: 1.3.69
[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--2000 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 "paper-column.hh" // urg
14 #include "bar.hh"
15 #include "lookup.hh"
16 #include "rest.hh"
17 #include "molecule.hh"
18 #include "misc.hh"
19 #include "group-interface.hh"
20 #include "stem.hh"
21 #include "staff-symbol-referencer.hh"
22 void
23 Multi_measure_rest::set_interface (Score_element*me)
24 {
25   me->set_elt_property ("columns", SCM_EOL);
26 }
27
28 Multi_measure_rest::Multi_measure_rest (SCM s)
29   : Spanner(s)
30 {}
31
32 /*
33    [TODO]                                      17
34  * variable-sized multi-measure rest symbol: |====| ??
35 */
36 MAKE_SCHEME_CALLBACK(Multi_measure_rest,brew_molecule);
37 SCM
38 Multi_measure_rest::brew_molecule (SCM smob) 
39 {
40   Score_element *me = unsmob_element (smob);
41   Spanner * sp = dynamic_cast<Spanner*> (me);
42   Real staff_space
43     = Staff_symbol_referencer::staff_space (me);
44
45   Interval sp_iv;
46   Direction d = LEFT;
47   do
48     {
49       Item * col = sp->get_bound (d)->column_l ();
50
51       Interval coldim = col->extent (X_AXIS)
52         + col->relative_coordinate (0, X_AXIS);
53
54       sp_iv[d] = coldim[-d]  ;
55     }
56   while ((flip (&d)) != LEFT);
57   Molecule mol;
58   Real x_off = 0.0;
59
60   Real rx  = sp->get_bound (LEFT)->relative_coordinate (0, X_AXIS);
61   /*
62     we gotta stay clear of sp_iv, so move a bit to the right if
63     needed.
64    */
65   x_off += (sp_iv[LEFT] -  rx) >? 0;
66
67   /*
68     center between stuff.
69    */
70   x_off += sp_iv.length ()/ 2;
71
72   
73   Molecule s;
74
75   int measures = 1;
76   SCM m (me->get_elt_property ("measure-count"));
77   if (gh_number_p (m))
78     {
79       measures = gh_scm2int (m);
80     }
81   
82
83   if (measures <= me->paper_l() ->get_var ("multi_measure_rest_expand_limit"))
84     {
85       /*
86         Build a rest from smaller parts. Distances inbetween are
87         really variable, see Wanske pp. 125 */
88
89       int l = measures;
90       while (l)
91         {
92           int k;
93           if (l >= 4)
94             {
95               l-=4;
96               k = -2;
97             }
98           else if (l>= 2)
99             {
100               l -= 2;
101               k = -1;
102             }
103           else
104             {
105               k = 0;
106               l --;
107             }
108
109           Real pad = s.empty_b ()
110             ? 0.0 : me->paper_l ()->get_var ("multi_measure_rest_padding");
111       
112           Molecule r (me->lookup_l ()->afm_find ("rests-" + to_str (k)));
113           if (k == 0)
114             r.translate_axis (staff_space, Y_AXIS);
115           
116           s.add_at_edge (X_AXIS, RIGHT, r, pad);
117         }
118
119
120       s.align_to (X_AXIS, CENTER);
121     }
122   else 
123     {
124       String idx =  ("rests-") + to_str (-4);
125       s = me->lookup_l ()->afm_find (idx);
126     }
127   
128   mol.add_molecule (s);
129
130   if (measures > 1)
131     {
132       Molecule s (me->lookup_l ()->text ("number", to_str (measures), me->paper_l ()));
133       s.align_to (X_AXIS, CENTER);
134       s.translate_axis (3.0 * staff_space, Y_AXIS);
135       mol.add_molecule (s);
136     }
137   mol.translate_axis (x_off, X_AXIS);
138   return mol.create_scheme();
139 }
140
141 /*
142   UGH. JUNKME elt prop "columns" isn't really needed. 
143  */
144 void
145 Multi_measure_rest::add_column (Score_element*me,Item* c)
146 {
147   Pointer_group_interface gi (me, "columns");
148   gi.add_element (c);
149
150   add_bound_item (dynamic_cast<Spanner*> (me),c);
151 }
152
153
154 Array<Rod>
155 Multi_measure_rest::get_rods () const
156 {
157   Array<Rod> a;
158
159   if (!(get_bound (LEFT) && get_bound (RIGHT)))
160     {
161       programming_error ("Multi_measure_rest::get_rods (): I am not spanned!");
162       return a;
163     }
164
165   Item * l = get_bound (LEFT)->column_l ();
166   Item * r = get_bound (RIGHT)->column_l ();
167   Item * lb = l->find_prebroken_piece (RIGHT);
168   Item * rb = r->find_prebroken_piece (LEFT);      
169   
170   Item* combinations[4][2]={{l,r}, {lb,r}, {l,rb},{lb,rb}};
171   for (int i=0; i < 4; i++)
172     {
173       Item * l =  combinations[i][0];
174       Item *r = combinations[i][1];
175
176       if (!l || !r)
177         continue;
178
179       Rod rod;
180       rod.item_l_drul_[LEFT] = l;
181       rod.item_l_drul_[RIGHT] = r;
182
183         /*
184           should do something more advanced.
185          */
186       rod.distance_f_ = l->extent (X_AXIS)[BIGGER] - r->extent (X_AXIS)[SMALLER]
187         + paper_l ()->get_var ("multi_measure_rest_x_minimum");
188   
189       a.push (rod);
190     }
191   
192   return a;
193 }
194