2 note-column.cc -- implement Note_column
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 #include <math.h> // ceil
10 #include "axis-group-interface.hh"
11 #include "dot-column.hh"
12 #include "note-column.hh"
14 #include "note-head.hh"
18 #include "paper-def.hh"
19 #include "group-interface.hh"
20 #include "staff-symbol-referencer.hh"
23 Note_column::rest_b () const
25 SCM r
= get_elt_pointer ("rests");
31 Note_column::shift_compare (Note_column
*const &p1
, Note_column
*const&p2
)
33 SCM s1
= p1
->get_elt_property ("horizontal-shift");
34 SCM s2
= p2
->get_elt_property ("horizontal-shift");
36 int h1
= (gh_number_p (s1
))? gh_scm2int (s1
) :0;
37 int h2
= (gh_number_p (s2
)) ? gh_scm2int (s2
):0;
41 Note_column::Note_column( SCM s
)
44 set_elt_pointer ("rests", SCM_EOL
);
45 set_elt_pointer ("note-heads", SCM_EOL
);
46 Axis_group_interface (this).set_interface ();
47 Axis_group_interface (this).set_axes (X_AXIS
, Y_AXIS
);
48 Group_interface (this, "interfaces").add_thing (ly_symbol2scm ("Note_column"));
52 Note_column::stem_l () const
54 SCM s
= get_elt_pointer ("stem");
55 return dynamic_cast<Stem
*> (unsmob_element (s
));
61 Note_column::head_positions_interval() const
67 SCM h
= get_elt_pointer ("note-heads");
68 for (; gh_pair_p (h
); h
= gh_cdr (h
))
70 Score_element
*se
= unsmob_element (gh_car (h
));
71 Staff_symbol_referencer_interface
si (se
);
73 int j
= int (si
.position_f ());
74 iv
.unite (Slice (j
,j
));
80 Note_column::dir () const
83 return stem_l ()->get_direction ();
84 else if (gh_pair_p (get_elt_pointer ("note-heads")))
85 return (Direction
)sign (head_positions_interval().center ());
87 programming_error ("Note column without heads and stem!");
93 Note_column::set_stem (Stem
* stem_l
)
95 set_elt_pointer ("stem", stem_l
->self_scm_
);
97 add_dependency (stem_l
);
98 Axis_group_interface (this).add_element (stem_l
);
104 Note_column::add_head (Rhythmic_head
*h
)
106 if (Rest
*r
=dynamic_cast<Rest
*> (h
))
108 Pointer_group_interface
gi (this, "rests");
111 if (Note_head
*nh
=dynamic_cast<Note_head
*> (h
))
113 Pointer_group_interface
gi (this, "note-heads");
116 Axis_group_interface (this).add_element (h
);
120 translate the rest symbols vertically by amount DY_I.
123 Note_column::translate_rests (int dy_i
)
125 SCM s
= get_elt_pointer ("rests");
126 for (; gh_pair_p (s
); s
= gh_cdr (s
))
128 Score_element
* se
= unsmob_element (gh_car (s
));
129 Staff_symbol_referencer_interface
si (se
);
131 se
->translate_axis (dy_i
* si
.staff_space ()/2.0, Y_AXIS
);
137 Note_column::set_dotcol (Dot_column
*d
)
139 Axis_group_interface (this).add_element (d
);
144 handle rest under beam (do_post: beams are calculated now)
145 what about combination of collisions and rest under beam.
149 rest -> stem -> beam -> interpolate_y_position ()
152 GLUE_SCORE_ELEMENT(Note_column
,after_line_breaking
);
154 Note_column::member_after_line_breaking ()
156 if (!stem_l () || !rest_b ())
157 return SCM_UNDEFINED
;
159 Beam
* b
= stem_l ()->beam_l ();
160 if (!b
|| !b
->visible_stem_count ())
161 return SCM_UNDEFINED
;
163 /* ugh. Should be done by beam.
164 (what? should be done --jcn)
165 scary too?: height is calculated during post_processing
170 SCM s
= b
->get_elt_property ("height");
172 beam_dy
= gh_scm2double (s
);
174 s
= b
->get_elt_property ("y-position");
176 beam_y
= gh_scm2double (s
);
179 Real x0
= b
->first_visible_stem ()->relative_coordinate (0, X_AXIS
);
180 Real dx
= b
->last_visible_stem ()->relative_coordinate (0, X_AXIS
) - x0
;
181 Real dydx
= beam_dy
&& dx
? beam_dy
/dx
: 0;
183 Direction d
= stem_l ()->get_direction ();
184 Real beamy
= (stem_l ()->relative_coordinate (0, X_AXIS
) - x0
) * dydx
+ beam_y
;
186 s
= get_elt_pointer ("rests");
187 Score_element
* se
= unsmob_element (gh_car (s
));
188 Staff_symbol_referencer_interface
si (se
);
190 Real staff_space
= si
.staff_space ();
191 Real rest_dim
= extent (Y_AXIS
)[d
]*2.0 /staff_space
;
194 = paper_l ()->get_var ("restcollision_minimum_beamdist") ;
196 minimum_dist
+ -d
* (beamy
- rest_dim
) >? 0;
198 int stafflines
= si
.line_count ();
200 // move discretely by half spaces.
201 int discrete_dist
= int (ceil (dist
));
203 // move by whole spaces inside the staff.
204 if (discrete_dist
< stafflines
+1)
205 discrete_dist
= int (ceil (discrete_dist
/ 2.0)* 2.0);
207 translate_rests (-d
* discrete_dist
);
209 return SCM_UNDEFINED
;
214 Note_column::rest_dim () const
217 SCM s
= get_elt_pointer ("rests");
218 for (; gh_pair_p (s
); s
= gh_cdr (s
))
220 Score_element
* sc
= unsmob_element ( gh_car (s
));
221 restdim
.unite (sc
->extent (Y_AXIS
));
228 Note_column::first_head () const
230 Stem
* st
= stem_l ();
231 return st
? st
->first_head (): 0;