From: Han-Wen Nienhuys Date: Wed, 9 Mar 2005 00:01:17 +0000 (+0000) Subject: (set_spacing_rods): new X-Git-Tag: release/2.5.15~37 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=c1dcc83ffe9c356e9ab3df20c4fde22f9c1aab8d;p=lilypond.git (set_spacing_rods): new function. Keep ledgered note heads at a minimum distance. Introduce minimum-length-fraction (print): introduce length-fraction property. --- diff --git a/ChangeLog b/ChangeLog index 9a040a2030..ce38da0b23 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-03-09 Han-Wen Nienhuys + + * lily/ledger-line-spanner.cc (set_spacing_rods): new + function. Keep ledgered note heads at a minimum distance. + Introduce minimum-length-fraction + (print): introduce length-fraction property. + +2005-03-08 Han-Wen Nienhuys + + * tex/GNUmakefile: remove latin1.enc rules. + 2005-03-08 Jan Nieuwenhuizen * scm/titling.scm: Typo. diff --git a/lily/include/rod.hh b/lily/include/rod.hh index 0ffba421d6..d334db2a37 100644 --- a/lily/include/rod.hh +++ b/lily/include/rod.hh @@ -15,7 +15,7 @@ struct Rod { - Drul_array item_l_drul_; + Drul_array item_drul_; Real distance_; /** diff --git a/lily/include/spring.hh b/lily/include/spring.hh index 58b72feb0e..2efb1105fd 100644 --- a/lily/include/spring.hh +++ b/lily/include/spring.hh @@ -28,7 +28,7 @@ DECLARE_UNSMOB(Spring_smob, spring); struct Spring { - Drul_array item_l_drul_; + Drul_array item_drul_; Real distance_; bool expand_only_b_; diff --git a/lily/ledger-line-spanner.cc b/lily/ledger-line-spanner.cc index 7d4b922a03..0af662952f 100644 --- a/lily/ledger-line-spanner.cc +++ b/lily/ledger-line-spanner.cc @@ -8,7 +8,9 @@ */ #include +#include +#include "item.hh" #include "note-head.hh" #include "staff-symbol-referencer.hh" #include "staff-symbol.hh" @@ -20,6 +22,7 @@ struct Ledger_line_spanner { DECLARE_SCHEME_CALLBACK (print, (SCM )); + DECLARE_SCHEME_CALLBACK (set_spacing_rods, (SCM )); static Stencil brew_ledger_lines (Grob *me, int pos, int interspaces, @@ -79,6 +82,99 @@ Ledger_line_spanner::brew_ledger_lines (Grob *staff, } +typedef std::map > Head_extents_map; +typedef std::map Column_map; + +MAKE_SCHEME_CALLBACK (Ledger_line_spanner, set_spacing_rods, 1); +SCM +Ledger_line_spanner::set_spacing_rods (SCM smob) +{ + Spanner *me = dynamic_cast (unsmob_grob (smob)); + + // find size of note heads. + Grob * staff = Staff_symbol_referencer::get_staff_symbol (me); + if (!staff) + return SCM_EOL; + + Link_array heads (Pointer_group_interface__extract_grobs (me, (Grob*)0, "note-heads")); + + if (heads.is_empty ()) + return SCM_EOL; + + Real min_length_fraction + = robust_scm2double (me->get_property ("minimum-length-fraction"), 0.15); + + Head_extents_map head_extents; + Column_map columns; + + int interspaces = Staff_symbol::line_count (staff)-1; + for (int i = heads.size (); i--; ) + { + Item *h = dynamic_cast (heads[i]); + + int pos = Staff_symbol_referencer::get_rounded_position (h); + if (pos + && abs (pos) > interspaces) + { + Grob *column = h->get_column (); + int rank = Paper_column::get_rank (column); + + Interval head_extent = h->extent (column, X_AXIS); + Direction vdir = Direction (sign (pos)); + if (!vdir) + continue; + + Interval prev_extent; + + Head_extents_map::iterator j = head_extents.find (rank); + if (j != head_extents.end ()) + prev_extent = (*j).second[vdir]; + else + columns[rank] = column; + + prev_extent.unite (head_extent); + head_extents[rank][vdir] = prev_extent; + } + } + + for (Column_map::const_iterator c (columns.begin()); c != columns.end(); c++) + { + Grob *column = (*c).second; + int rank = (*c).first; + + int next_rank = rank + 2; + + if (head_extents.find (next_rank) != head_extents.end ()) + { + Drul_array extents_left = head_extents[rank]; + Drul_array extents_right = head_extents[next_rank]; + + Direction d = DOWN; + do + { + if (!extents_right[d].is_empty () && !extents_right[d].is_empty ()) + { + Real l1 = extents_right[d].length() * min_length_fraction; + Real l2 = extents_left[d].length() * min_length_fraction; + + Rod rod; + rod.distance_ = l1 + l2 + (l1+ l2)/2.0 + + extents_left[d][RIGHT] + - extents_right[d][LEFT]; + + rod.item_drul_[LEFT] = dynamic_cast (column); + rod.item_drul_[RIGHT] = dynamic_cast (columns[next_rank]); + rod.add_to_cols (); + } + } + while (flip (&d) != DOWN); + } + } + + return SCM_UNSPECIFIED; +} + + struct Ledger_request { Interval ledger_extent_; @@ -115,6 +211,9 @@ Ledger_line_spanner::print (SCM smob) return SCM_EOL; + Real length_fraction + = robust_scm2double (me->get_property ("length-fraction"), 0.25); + Stencil ledgers; Stencil default_ledger; @@ -131,7 +230,6 @@ Ledger_line_spanner::print (SCM smob) int interspaces = Staff_symbol::line_count (staff)-1; Ledger_requests reqs; - Real length_fraction = 0.25; for (int i = heads.size (); i--; ) { Item *h = dynamic_cast (heads[i]); @@ -239,7 +337,6 @@ Ledger_line_spanner::print (SCM smob) } } - ledgers.translate_axis (-me->relative_coordinate (common[X_AXIS], X_AXIS), X_AXIS); @@ -249,7 +346,7 @@ Ledger_line_spanner::print (SCM smob) ADD_INTERFACE (Ledger_line_spanner, "ledger-line-interface", "This spanner draws the ledger lines of a staff, for note heads that stick out. ", - "note-heads thickness gap length minimum-length"); + "note-heads thickness minimum-length-fraction length-fraction gap"); struct Ledgered_interface { diff --git a/lily/lyric-hyphen.cc b/lily/lyric-hyphen.cc index f98d5c446f..07a393e7d2 100644 --- a/lily/lyric-hyphen.cc +++ b/lily/lyric-hyphen.cc @@ -100,14 +100,14 @@ Hyphen_spanner::set_spacing_rods (SCM smob) Direction d = LEFT; do { - r.item_l_drul_[d] = sp->get_bound (d); - if (r.item_l_drul_[d]) - r.distance_ += r.item_l_drul_[d]->extent (r.item_l_drul_[d], X_AXIS)[-d]; + r.item_drul_[d] = sp->get_bound (d); + if (r.item_drul_[d]) + r.distance_ += r.item_drul_[d]->extent (r.item_drul_[d], X_AXIS)[-d]; } while (flip (&d) != LEFT); - if (r.item_l_drul_[LEFT] - && r.item_l_drul_[RIGHT]) + if (r.item_drul_[LEFT] + && r.item_drul_[RIGHT]) r.add_to_cols (); return SCM_UNSPECIFIED; diff --git a/lily/multi-measure-rest.cc b/lily/multi-measure-rest.cc index 31a1c8b9ad..f2298a92de 100644 --- a/lily/multi-measure-rest.cc +++ b/lily/multi-measure-rest.cc @@ -328,8 +328,8 @@ Multi_measure_rest::set_spacing_rods (SCM smob) continue; Rod rod; - rod.item_l_drul_[LEFT] = li; - rod.item_l_drul_[RIGHT] = ri; + rod.item_drul_[LEFT] = li; + rod.item_drul_[RIGHT] = ri; rod.distance_ = li->extent (li, X_AXIS)[BIGGER] - ri->extent (ri, X_AXIS)[SMALLER] diff --git a/lily/piano-pedal-performer.cc b/lily/piano-pedal-performer.cc index e5c8a70129..e423e01106 100644 --- a/lily/piano-pedal-performer.cc +++ b/lily/piano-pedal-performer.cc @@ -18,7 +18,7 @@ class Piano_pedal_performer : public Performer { char const *name_; Music* start_req_; - Drul_array req_l_drul_; + Drul_array req_drul_; }; public: @@ -58,8 +58,8 @@ Piano_pedal_performer::initialize () do { p->name_ = *np; - p->req_l_drul_[START] = 0; - p->req_l_drul_[STOP] = 0; + p->req_drul_[START] = 0; + p->req_drul_[STOP] = 0; p->start_req_ = 0; p++; @@ -73,11 +73,11 @@ Piano_pedal_performer::create_audio_elements () for (Pedal_info*p = info_alist_; p && p->name_; p ++) { - if (p->req_l_drul_[STOP]) + if (p->req_drul_[STOP]) { if (!p->start_req_) { - p->req_l_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'", String (p->name_))); + p->req_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'", String (p->name_))); } else { @@ -89,16 +89,16 @@ Piano_pedal_performer::create_audio_elements () p->start_req_ = 0; } - if (p->req_l_drul_[START]) + if (p->req_drul_[START]) { - p->start_req_ = p->req_l_drul_[START]; + p->start_req_ = p->req_drul_[START]; Audio_piano_pedal* a = new Audio_piano_pedal; a->type_string_ = String (p->name_); a->dir_ = START; audios_.push (a); } - p->req_l_drul_[START] = 0; - p->req_l_drul_[STOP] = 0; + p->req_drul_[START] = 0; + p->req_drul_[STOP] = 0; } } @@ -115,8 +115,8 @@ Piano_pedal_performer::start_translation_timestep () { for (Pedal_info*p = info_alist_; p && p->name_; p ++) { - p->req_l_drul_[STOP] = 0; - p->req_l_drul_[START] = 0; + p->req_drul_[STOP] = 0; + p->req_drul_[START] = 0; } } @@ -132,7 +132,7 @@ Piano_pedal_performer::try_music (Music* r) scm_str2symbol (nm.to_str0()))) { Direction d = to_dir (r->get_property ("span-direction")); - p->req_l_drul_[d] = r; + p->req_drul_[d] = r; return true; } } diff --git a/lily/rod.cc b/lily/rod.cc index de174e9ea1..889429a63e 100644 --- a/lily/rod.cc +++ b/lily/rod.cc @@ -17,7 +17,7 @@ Rod::Rod () { distance_ = 0.0; - item_l_drul_[LEFT] = item_l_drul_[RIGHT] = 0; + item_drul_[LEFT] = item_drul_[RIGHT] = 0; } @@ -25,15 +25,15 @@ Rod::Rod () void Rod::columnize () { - if (!item_l_drul_[LEFT] - || !item_l_drul_[RIGHT]) + if (!item_drul_[LEFT] + || !item_drul_[RIGHT]) return ; Direction d = LEFT; do { - Paper_column * pc = item_l_drul_[d]->get_column (); - distance_ += - d * item_l_drul_[d]->relative_coordinate (pc, X_AXIS); - item_l_drul_[d] = pc; + Paper_column * pc = item_drul_[d]->get_column (); + distance_ += - d * item_drul_[d]->relative_coordinate (pc, X_AXIS); + item_drul_[d] = pc; } while ((flip (&d))!= LEFT); } @@ -42,10 +42,10 @@ void Rod::add_to_cols () { columnize (); - if (item_l_drul_[LEFT] != item_l_drul_[RIGHT] - && item_l_drul_[LEFT] && item_l_drul_[RIGHT]) - Spaceable_grob::add_rod (item_l_drul_[LEFT], - item_l_drul_[RIGHT], + if (item_drul_[LEFT] != item_drul_[RIGHT] + && item_drul_[LEFT] && item_drul_[RIGHT]) + Spaceable_grob::add_rod (item_drul_[LEFT], + item_drul_[RIGHT], distance_); } diff --git a/lily/separating-group-spanner.cc b/lily/separating-group-spanner.cc index 2cc6c35999..7481ee0684 100644 --- a/lily/separating-group-spanner.cc +++ b/lily/separating-group-spanner.cc @@ -42,8 +42,8 @@ Separating_group_spanner::find_rods (Item * r, SCM next, Real padding) { Rod rod; - rod.item_l_drul_[LEFT] = lb; - rod.item_l_drul_[RIGHT] = r; + rod.item_drul_[LEFT] = lb; + rod.item_drul_[RIGHT] = r; rod.distance_ = li[RIGHT] - ri[LEFT] + padding; rod.add_to_cols (); @@ -56,8 +56,8 @@ Separating_group_spanner::find_rods (Item * r, SCM next, Real padding) { Rod rod; - rod.item_l_drul_[LEFT] = l; - rod.item_l_drul_[RIGHT]= r; + rod.item_drul_[LEFT] = l; + rod.item_drul_[RIGHT]= r; rod.distance_ = li[RIGHT] - ri[LEFT] + padding; diff --git a/lily/separation-item.cc b/lily/separation-item.cc index b6a99a5ee5..7d852f69d7 100644 --- a/lily/separation-item.cc +++ b/lily/separation-item.cc @@ -170,7 +170,5 @@ Separation_item::extremal_break_aligned_grob (Grob *separation_item, Direction d ADD_INTERFACE (Separation_item, "separation-item-interface", "Item that computes widths to generate spacing rods. " "This is done in concert with @ref{separation-spanner-interface}." - , - "padding X-extent conditional-elements elements"); diff --git a/lily/spacing-spanner.cc b/lily/spacing-spanner.cc index 97604610c2..389593ff93 100644 --- a/lily/spacing-spanner.cc +++ b/lily/spacing-spanner.cc @@ -244,8 +244,8 @@ Spacing_spanner::prune_loose_columns (Grob*me, Link_array *cols, Rational Rod r; r.distance_ = dists[LEFT] + dists[RIGHT]; - r.item_l_drul_[LEFT] = dynamic_cast (cols->elem (i-1)); - r.item_l_drul_[RIGHT] = dynamic_cast (cols->elem (i+1)); + r.item_drul_[LEFT] = dynamic_cast (cols->elem (i-1)); + r.item_drul_[RIGHT] = dynamic_cast (cols->elem (i+1)); r.add_to_cols (); } diff --git a/lily/spanner.cc b/lily/spanner.cc index 0e4c9e04c0..842d706e6d 100644 --- a/lily/spanner.cc +++ b/lily/spanner.cc @@ -343,8 +343,8 @@ Spanner::set_spacing_rods (SCM smob) Rod r; Spanner*sp = dynamic_cast (me); - r.item_l_drul_[LEFT] = sp->get_bound (LEFT); - r.item_l_drul_[RIGHT] = sp->get_bound (RIGHT); + r.item_drul_[LEFT] = sp->get_bound (LEFT); + r.item_drul_[RIGHT] = sp->get_bound (RIGHT); r.distance_ = robust_scm2double (me->get_property ("minimum-length"), 0); diff --git a/ly/paper-defaults.ly b/ly/paper-defaults.ly index 06796d7d04..925f1c3ffa 100644 --- a/ly/paper-defaults.ly +++ b/ly/paper-defaults.ly @@ -72,7 +72,7 @@ (else 'latin1))) ;; add to taste here. - (baseline-skip . 2) + (baseline-skip . 3) (word-space . 0.6))) #(define page-breaking ly:optimal-page-breaks) diff --git a/scm/backend-library.scm b/scm/backend-library.scm index ce407e53f6..431c7b48a6 100644 --- a/scm/backend-library.scm +++ b/scm/backend-library.scm @@ -25,7 +25,7 @@ (newline (current-error-port)) ;; hmmm. what's the best failure option? - (throw 'ly-file-failed)))) + (throw 'ly-file-failed))))) (define-public (sanitize-command-option str) (string-append diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index f723e580b0..3036987af8 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -287,6 +287,7 @@ second for staff space. Both contributions are added.") left to a group of accidentals.") (length ,ly:dimension? "User override for the stem length of unbeamed stems.") + (length-fraction ,number? "Length of ledger line as fraction of note head size.") (lengths ,list? "Default stem lengths. The list gives a length for each flag-count.") (line-count ,integer? "The number of staff lines.") @@ -305,6 +306,7 @@ polyphonic guitar notation. The value of this setting is used by collisions, even if they have a different number of dots. This normal notation for some types of polyphonic music. ") + (minimum-length-fraction ,number? "Minimum length of ledger line as fraction of note head size.") (minimum-distance ,ly:dimension? "Minimum distance between rest and notes or beam.") (minimum-X-extent ,number-pair? "Minimum size of an object in X diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index fece9d0b2e..487ad88ffc 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -569,6 +569,7 @@ (print-function . ,Ledger_line_spanner::print) (X-extent-callback . #f) (Y-extent-callback . #f) + (spacing-procedure . ,Ledger_line_spanner::set_spacing_rods) (print-function . ,Ledger_line_spanner::print) (layer . 0) (meta . ((interfaces . (spanner-interface ledger-line-interface))))