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