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"
21 #include "accidental-placement.hh"
24 Insert some more space for the next note, in case it has a stem in
29 Staff_spacing::next_note_correction (Grob * me,
33 if (!g || !Note_column::has_interface (g))
36 Item *col =dynamic_cast<Item*> (g)->get_column ();
37 Real max_corr = 0. >? (- g->extent (col, X_AXIS)[LEFT]);
40 Duh. If this gets out of hand, we should invent something more generic.
42 if (Grob * a = Note_column::accidentals (g))
45 if (Accidental_placement::has_interface (a))
47 v = Accidental_placement::get_relevant_accidental_extent(a, col, me);
50 v = a->extent (col, X_AXIS);
52 max_corr = max_corr >? (- v[LEFT]);
54 if (Grob* a = unsmob_grob (g->get_grob_property ("arpeggio")))
56 max_corr = max_corr >? (- a->extent (col, X_AXIS)[LEFT]);
60 Let's decrease the space a little if the problem is not located
63 if (bar_size.empty_b ())
66 if (!bar_size.empty_b())
67 if (Grob *stem = Note_column::get_stem (g))
69 Direction d = Stem::get_direction (stem);
72 Real stem_start = Stem::head_positions (stem) [DOWN];
73 Real stem_end = Stem::stem_end_position (stem);
74 Interval stem_posns (stem_start <? stem_end,
75 stem_end >? stem_start);
77 stem_posns.intersect (bar_size);
79 Real corr = abs (stem_posns.length ()/7.) <? 1.0;
81 gh_scm2double (me->get_grob_property ("stem-spacing-correction"));
85 max_corr = max_corr >? corr;
93 Y-positions that are covered by BAR_GROB, in the case that it is a
96 Staff_spacing::bar_y_positions (Grob *bar_grob)
100 if (Bar_line::has_interface (bar_grob))
102 SCM glyph = bar_grob->get_grob_property ("glyph");
104 String glyph_string = gh_string_p (glyph) ? ly_scm2string (glyph) : "";
105 if (glyph_string.left_string (1) == "|" || glyph_string.left_string (1) == ".")
107 SCM sz = Bar_line::get_staff_bar_size (bar_grob->self_scm());
108 bar_size = Interval (-1,1);
109 bar_size *= gh_scm2double (sz)
110 / Staff_symbol_referencer::staff_space (bar_grob);
117 Do corrections for the following notes.
119 This is slightly convoluted, since the staffspacing grob gets
120 pointers to the separation-items, not the note-columns or
125 Staff_spacing::next_notes_correction (Grob *me, Grob * last_grob)
127 Interval bar_size = bar_y_positions (last_grob);
129 for (SCM s = me->get_grob_property ("right-items");
130 gh_pair_p (s); s = gh_cdr (s))
132 Grob * g = unsmob_grob (gh_car (s));
133 max_corr = max_corr >? next_note_correction (me, g, bar_size);
134 for (SCM t = g->get_grob_property ("elements");
135 gh_pair_p (t); t = gh_cdr (t))
136 max_corr = max_corr >? next_note_correction (me, unsmob_grob (gh_car (t)), bar_size);
143 Try to find the break-aligned symbol in SEPARATION_ITEM that is
144 sticking out at direction D. The x size is put in LAST_EXT
147 Staff_spacing::extremal_break_aligned_grob (Grob *separation_item, Direction d,
150 Grob *left_col = dynamic_cast<Item*> (separation_item)->get_column ();
151 last_ext->set_empty ();
153 for (SCM s = separation_item->get_grob_property ("elements");
154 gh_pair_p (s); s = gh_cdr (s))
156 Grob * break_item = unsmob_grob (gh_car (s));
158 if (!gh_symbol_p (break_item->get_grob_property ("break-align-symbol")))
161 Interval ext = break_item->extent (left_col, X_AXIS);
166 || (last_grob && d * (ext[d]- (*last_ext)[d]) > 0) )
169 last_grob = break_item;
177 Staff_spacing::get_spacing_params (Grob *me, Real * space, Real * fixed)
182 Grob * separation_item=0;
183 Item * me_item = dynamic_cast<Item*> (me);
185 for (SCM s = me->get_grob_property ("left-items");
186 gh_pair_p (s); s = gh_cdr(s))
188 Grob * cand = unsmob_grob(gh_car (s));
189 if (cand && Separation_item::has_interface (cand))
190 separation_item = cand ;
193 // printf ("doing col %d\n" , Paper_column::get_rank (left_col));
195 if (!separation_item)
197 programming_error ("no sep item");
202 Grob *last_grob = extremal_break_aligned_grob (separation_item, RIGHT,
209 Should insert a adjustable space here? For excercises, you might want to
210 use a staff without a clef in the beginning.
214 we used to have a warning here, but itgenerates a lot of
215 spurious error messages.
220 *fixed = last_ext[RIGHT];
221 *space = *fixed + 1.0;
223 SCM alist = last_grob->get_grob_property ("space-alist");
224 if (!scm_list_p (alist))
228 SCM space_def = scm_sloppy_assq (ly_symbol2scm ("first-note"), alist);
229 if (me_item->break_status_dir () == CENTER)
231 SCM nndef = scm_sloppy_assq (ly_symbol2scm ("next-note"), alist);
232 if (gh_pair_p (nndef ))
236 if (!gh_pair_p (space_def))
238 programming_error ("Unknown prefatory spacing. ");
242 space_def = gh_cdr (space_def);
243 Real distance = gh_scm2double (gh_cdr (space_def));
244 SCM type = gh_car (space_def) ;
246 *fixed = last_ext[RIGHT];
247 if (type == ly_symbol2scm ("extra-space"))
248 *space = *fixed + distance;
249 else if (type == ly_symbol2scm("minimum-space"))
250 *space = last_ext[LEFT] + (last_ext.length () >? distance);
253 *space += next_notes_correction (me, last_grob);
257 ADD_INTERFACE (Staff_spacing,"staff-spacing-interface",
259 "stem-spacing-correction left-items right-items");