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