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