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