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