]> git.donarmstrong.com Git - lilypond.git/blob - lily/multi-measure-rest.cc
ea462cee20b90a34ad06fcf30df884337f303a4b
[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   measures_i_ = 0;
26   set_elt_property ("columns", SCM_EOL);
27 }
28
29
30 /*
31    [TODO]                                          17
32  * variable-sized multi-measure rest symbol: |====| ??
33  
34  * build 3, 5, 6, 7, 8 symbols (how far, property?)
35        from whole, brevis and longa rests
36
37 */
38 Molecule*
39 Multi_measure_rest::do_brew_molecule_p () const
40 {
41   Interval sp_iv;
42   Direction d = LEFT;
43   do
44     {
45       Item * col = spanned_drul_[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_p  = new Molecule;
54   Real x_off = 0.0;
55
56   Real rx  = spanned_drul_[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   bool rest_symbol=true;
71   SCM alt_symbol_sym =get_elt_property ("alt-symbol");
72   if (gh_string_p (alt_symbol_sym))
73     {
74       s = lookup_l () -> afm_find (ly_scm2string (alt_symbol_sym));
75       rest_symbol = false;
76     }
77   else if (measures_i_ == 1 || measures_i_ == 2 || measures_i_ == 4) 
78     {
79       s = lookup_l ()->afm_find ("rests-" + to_str (- intlog2(measures_i_)));
80       s.translate_axis (-s.extent ()[X_AXIS].length () / 2, X_AXIS);
81     }
82   else 
83     {
84       String idx =  ("rests-") + to_str (-4);
85       s = lookup_l ()->afm_find (idx);
86     }
87   
88   mol_p->add_molecule (s);
89   Real staff_space
90     = staff_symbol_referencer (this).staff_space ();
91   if (measures_i_ == 1 && rest_symbol)
92     {
93       mol_p->translate_axis (staff_space, Y_AXIS);
94     }
95   else if (measures_i_ > 1)
96     {
97       Molecule s (lookup_l ()->text ("number", to_str (measures_i_), paper_l ()));
98       s.align_to (X_AXIS, CENTER);
99       s.translate_axis (3.0 * staff_space, Y_AXIS);
100       mol_p->add_molecule (s);
101     }
102   mol_p->translate_axis (x_off, X_AXIS);
103   return mol_p;
104 }
105
106 /*
107   UGH. JUNKME elt prop "columns" isn't really needed. 
108  */
109
110 void
111 Multi_measure_rest::do_add_processing ()
112 {
113   if (gh_pair_p (get_elt_property ("columns")))
114     {
115       Link_array<Item> column_arr (Group_interface__extract_elements (this, (Item*)0, "columns"));
116                                     
117       set_bounds (LEFT, column_arr[0 >? column_arr.size () - 2]);
118       set_bounds (RIGHT, column_arr.top ());
119     }
120 }
121   
122 void
123 Multi_measure_rest::do_post_processing ()
124 {
125   if (!gh_pair_p (get_elt_property ("columns")))
126     set_elt_property ("transparent", SCM_BOOL_T);
127 }
128
129
130  
131 void
132 Multi_measure_rest::add_column (Item* c)
133 {
134   Group_interface gi (this, "columns");
135   gi.add_element (c);
136
137   
138   add_dependency (c);
139 }
140
141
142 Array<Rod>
143 Multi_measure_rest::get_rods () const
144 {
145   Array<Rod> a;
146
147   if (!(spanned_drul_[LEFT] && spanned_drul_[RIGHT]))
148     {
149       programming_error ("Multi_measure_rest::get_rods (): I am not spanned!");
150       return a;
151     }
152
153   Item * l = spanned_drul_[LEFT]->column_l ();
154   Item * r = spanned_drul_[RIGHT]->column_l ();
155   Item * lb = l->find_broken_piece (RIGHT);
156   Item * rb = r->find_broken_piece (LEFT);      
157   
158   Item* combinations[4][2]={{l,r}, {lb,r}, {l,rb},{lb,rb}};
159   for (int i=0; i < 4; i++)
160     {
161       Item * l =  combinations[i][0];
162       Item *r = combinations[i][1];
163
164       if (!l || !r)
165         continue;
166
167       Rod rod;
168       rod.item_l_drul_[LEFT] = l;
169       rod.item_l_drul_[RIGHT] = r;
170
171         /*
172           should do something more advanced.
173          */
174       rod.distance_f_ = l->extent (X_AXIS)[BIGGER] - r->extent (X_AXIS)[SMALLER]
175         + paper_l ()->get_var ("mmrest_x_minimum");
176   
177       a.push (rod);
178     }
179   
180   return a;
181 }
182