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