2 staff-spacing.cc -- implement Staff_spacing
4 source file of the GNU LilyPond music typesetter
6 (c) 2001--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "paper-column.hh"
12 #include "separation-item.hh"
14 #include "staff-spacing.hh"
17 #include "bar-line.hh"
18 #include "staff-symbol-referencer.hh"
19 #include "note-column.hh"
23 Staff_spacing::has_interface (Grob* g)
25 return g && g->has_interface (ly_symbol2scm ("staff-spacing-interface"));
29 Insert some more space for the next note, in case it has a stem in
34 Staff_spacing::next_note_correction (Grob * me,
38 if (!g || !Note_column::has_interface (g))
41 Item *col =dynamic_cast<Item*> (g)->column_l ();
42 Real max_corr = 0. >? (- g->extent (col, X_AXIS)[LEFT]);
45 Duh. If this gets out of hand, we should invent something more generic.
47 if (Grob * a = Note_column::accidentals (g))
49 max_corr = max_corr >? (- a->extent (col, X_AXIS)[LEFT]);
51 if (Grob* a = unsmob_grob (g->get_grob_property ("arpeggio")))
53 max_corr = max_corr >? (- a->extent (col, X_AXIS)[LEFT]);
57 Let's decrease the space a little if the problem is not located
60 if (bar_size.empty_b ())
63 if (!bar_size.empty_b())
64 if (Grob *stem = Note_column::stem_l (g))
66 Direction d = Stem::get_direction (stem);
69 Real stem_start = Stem::head_positions (stem) [DOWN];
70 Real stem_end = Stem::stem_end_position (stem);
71 Interval stem_posns (stem_start <? stem_end,
72 stem_end >? stem_start);
74 stem_posns.intersect (bar_size);
76 Real corr = abs (stem_posns.length ()/7.) <? 1.0;
78 gh_scm2double (me->get_grob_property ("stem-spacing-correction"));
82 max_corr = max_corr >? corr;
90 Y-positions that are covered by BAR_GROB, in the case that it is a
93 Staff_spacing::bar_y_positions (Grob *bar_grob)
97 if (Bar_line::has_interface (bar_grob))
99 SCM glyph = bar_grob->get_grob_property ("glyph");
101 String glyph_str = gh_string_p (glyph) ? ly_scm2string (glyph) : "";
102 if (glyph_str.left_str (1) == "|" || glyph_str.left_str (1) == ".")
104 SCM sz = Bar_line::get_staff_bar_size (bar_grob->self_scm());
105 bar_size = Interval (-1,1);
106 bar_size *= gh_scm2double (sz)
107 / Staff_symbol_referencer::staff_space (bar_grob);
114 Do corrections for the following notes.
116 This is slightly convoluted, since the staffspacing grob gets
117 pointers to the separation-items, not the note-columns or
122 Staff_spacing::next_notes_correction (Grob *me, Grob * last_grob)
124 Interval bar_size = bar_y_positions (last_grob);
126 for (SCM s = me->get_grob_property ("right-items");
127 gh_pair_p (s); s = gh_cdr (s))
129 Grob * g = unsmob_grob (gh_car (s));
130 max_corr = max_corr >? next_note_correction (me, g, bar_size);
131 for (SCM t = g->get_grob_property ("elements");
132 gh_pair_p (t); t = gh_cdr (t))
133 max_corr = max_corr >? next_note_correction (me, unsmob_grob (gh_car (t)), bar_size);
140 Try to find the break-aligned symbol in SEPARATION_ITEM that is
141 sticking out at direction D. The x size is put in LAST_EXT
144 Staff_spacing::extremal_break_aligned_grob (Grob *separation_item, Direction d,
147 Grob *left_col = dynamic_cast<Item*> (separation_item)->column_l ();
148 last_ext->set_empty ();
150 for (SCM s = separation_item->get_grob_property ("elements");
151 gh_pair_p (s); s = gh_cdr (s))
153 Grob * break_item = unsmob_grob (gh_car (s));
155 if (!gh_symbol_p (break_item->get_grob_property ("break-align-symbol")))
158 Interval ext = break_item->extent (left_col, X_AXIS);
163 || (last_grob && d * (ext[d]- (*last_ext)[d]) > 0) )
166 last_grob = break_item;
176 Staff_spacing::get_spacing_params (Grob *me, Real * space, Real * fixed)
181 Grob * separation_item=0;
183 for (SCM s = me->get_grob_property ("left-items");
184 gh_pair_p (s); s = gh_cdr(s))
186 Grob * cand = unsmob_grob(gh_car (s));
187 if (cand && Separation_item::has_interface (cand))
188 separation_item = cand ;
191 // printf ("doing col %d\n" , Paper_column::rank_i(left_col));
193 if (!separation_item)
195 programming_error ("no sep item");
200 Grob *last_grob = extremal_break_aligned_grob (separation_item, RIGHT,
204 programming_error ("empty break column? --fixme");
208 *fixed = last_ext[RIGHT];
209 *space = *fixed + 1.0;
211 SCM alist = last_grob->get_grob_property ("space-alist");
212 if (!scm_list_p (alist))
215 SCM space_def = scm_sloppy_assq (ly_symbol2scm ("begin-of-note"), alist);
216 if (!gh_pair_p (space_def))
218 programming_error ("Unknown prefatory spacing. ");
222 space_def = gh_cdr (space_def);
223 Real distance = gh_scm2double (gh_cdr (space_def));
224 SCM type = gh_car (space_def) ;
226 *fixed = last_ext[RIGHT];
227 if (type == ly_symbol2scm ("extra-space"))
228 *space = *fixed + distance;
229 else if (type == ly_symbol2scm("minimum-space"))
230 *space = last_ext[LEFT] + (last_ext.length () >? distance);
233 *space += next_notes_correction (me, last_grob);