From: Han-Wen Nienhuys Date: Fri, 23 Dec 2005 16:12:09 +0000 (+0000) Subject: * lily/beam.cc (calc_direction): use default-direction X-Git-Tag: release/2.7.25~2 X-Git-Url: https://git.donarmstrong.com/lilypond.git?a=commitdiff_plain;h=f1b323b28c4ed9e06193ed9a0447d48423fb05d5;p=lilypond.git * lily/beam.cc (calc_direction): use default-direction iso. get_default_direction() * scm/define-grob-properties.scm (all-user-grob-properties): add default-direction property. * scm/define-grobs.scm (all-grob-descriptions): add MelodyItem. * lily/stem.cc (calc_default_direction): remove Stem::get_default_direction, use default-direction with callback instead. * lily/melody-spanner.cc (calc_neutral_stem_direction): * lily/melody-engraver.cc: new file. Acknowledge stems for interpolated stem directions. * lily/melody-spanner.cc: new file. Interpolate stem directions. * scm/define-grobs.scm (all-grob-descriptions): add MelodyItem * lily/slur-engraver.cc (acknowledge_extra_object): remove DynamicText hardcoding. --- diff --git a/ChangeLog b/ChangeLog index 3ce49ae40b..3a73ce87e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,26 @@ 2005-12-23 Han-Wen Nienhuys + * lily/beam.cc (calc_direction): use default-direction + iso. get_default_direction() + + * scm/define-grob-properties.scm (all-user-grob-properties): add + default-direction property. + + * scm/define-grobs.scm (all-grob-descriptions): add MelodyItem. + + * lily/stem.cc (calc_default_direction): remove + Stem::get_default_direction, use default-direction with callback + instead. + + * lily/melody-spanner.cc (calc_neutral_stem_direction): + + * lily/melody-engraver.cc: new file. Acknowledge stems for + interpolated stem directions. + + * lily/melody-spanner.cc: new file. Interpolate stem directions. + + * scm/define-grobs.scm (all-grob-descriptions): add MelodyItem + * lily/slur-configuration.cc (fit_factor): more robust check for point in curve X-extent. diff --git a/lily/beam.cc b/lily/beam.cc index 8a98a3e965..b25a48ada5 100644 --- a/lily/beam.cc +++ b/lily/beam.cc @@ -140,13 +140,7 @@ Beam::calc_direction (SCM smob) } else { - /* - ugh. - - can happen in stem-tremolo case. - TODO: fixme. - */ - d = Stem::get_default_dir (stems[0]); + d = to_dir (stems[0]->get_property ("default-direction")); } } @@ -538,7 +532,10 @@ Beam::get_default_dir (Grob *me) if (is_direction (stem_dir_scm)) stem_dir = to_dir (stem_dir_scm); else - stem_dir = Stem::get_default_dir (s); + stem_dir = to_dir (s->get_property ("default-direction")); + + if (!stem_dir) + stem_dir = to_dir (s->get_property ("neutral-direction")); if (stem_dir) { @@ -1196,8 +1193,11 @@ Beam::forced_stem_count (Grob *me) /* I can imagine counting those boundaries as a half forced stem, but let's count them full for now. */ + Direction defdir = to_dir (s->get_property ("default-direction")); + if (abs (Stem::chord_start_y (s)) > 0.1 - && (get_grob_direction (s) != Stem::get_default_dir (s))) + && defdir + && get_grob_direction (s) != defdir) f++; } return f; diff --git a/lily/include/melody-spanner.hh b/lily/include/melody-spanner.hh new file mode 100644 index 0000000000..023c7456ab --- /dev/null +++ b/lily/include/melody-spanner.hh @@ -0,0 +1,25 @@ +/* + melody-spanner.hh -- declare Melody_spanner + + source file of the GNU LilyPond music typesetter + + (c) 2005 Han-Wen Nienhuys + +*/ + +#ifndef MELODY_SPANNER_HH +#define MELODY_SPANNER_HH + +#include "lily-guile.hh" +#include "lily-proto.hh" + +class Melody_spanner +{ +public: + static bool has_interface (Grob*); + static void add_stem (Grob*, Grob*); + DECLARE_SCHEME_CALLBACK(calc_neutral_stem_direction, (SCM)); +}; + +#endif /* MELODY_SPANNER_HH */ + diff --git a/lily/include/stem.hh b/lily/include/stem.hh index dbbb3e8438..44e060040c 100644 --- a/lily/include/stem.hh +++ b/lily/include/stem.hh @@ -40,6 +40,7 @@ public: static void set_spacing_hints (Grob *); DECLARE_SCHEME_CALLBACK (print, (SCM)); + DECLARE_SCHEME_CALLBACK (calc_default_direction, (SCM)); DECLARE_SCHEME_CALLBACK (offset_callback, (SCM element)); DECLARE_SCHEME_CALLBACK (calc_direction, (SCM)); DECLARE_SCHEME_CALLBACK (calc_beaming, (SCM)); diff --git a/lily/melody-engraver.cc b/lily/melody-engraver.cc new file mode 100644 index 0000000000..5c9ee1c826 --- /dev/null +++ b/lily/melody-engraver.cc @@ -0,0 +1,51 @@ +/* + melody-engraver.cc -- implement Melody_engraver + + source file of the GNU LilyPond music typesetter + + (c) 1997--2005 Han-Wen Nienhuys +*/ + + +#include "engraver.hh" + +#include "item.hh" +#include "melody-spanner.hh" + +/** + Make stems upon receiving noteheads. +*/ +class Melody_engraver : public Engraver +{ + Grob *melody_item_; +protected: + + DECLARE_ACKNOWLEDGER (stem); + TRANSLATOR_DECLARATIONS (Melody_engraver); +}; + + +Melody_engraver::Melody_engraver () +{ + melody_item_ = 0; +} + +void +Melody_engraver::acknowledge_stem (Grob_info info) +{ + if (!melody_item_) + melody_item_ = make_item ("MelodyItem", info.grob ()->self_scm ()); + + Melody_spanner::add_stem (melody_item_, info.grob ()); +} + + +#include "translator.icc" +ADD_ACKNOWLEDGER (Melody_engraver, stem); +ADD_TRANSLATOR (Melody_engraver, + "Create information for context dependent typesetting decisions. ", + "MelodyItem", + "", + "", + ""); + diff --git a/lily/melody-spanner.cc b/lily/melody-spanner.cc new file mode 100644 index 0000000000..fed63657cf --- /dev/null +++ b/lily/melody-spanner.cc @@ -0,0 +1,96 @@ +/* + melody-spanner.cc -- implement Melody_spanner + + source file of the GNU LilyPond music typesetter + + (c) 2005 Han-Wen Nienhuys + +*/ + +#include "melody-spanner.hh" +#include "grob.hh" +#include "pointer-group-interface.hh" + +/* + TODO: this could be either item or spanner. For efficiency reasons, + let's take item for now. +*/ + + +/* + Interpolate stem directions for neutral stems. + */ +MAKE_SCHEME_CALLBACK(Melody_spanner,calc_neutral_stem_direction, 1); +SCM +Melody_spanner::calc_neutral_stem_direction (SCM smob) +{ + Grob *stem = unsmob_grob (smob); + Grob *me = unsmob_grob (stem->get_object ("melody-spanner")); + + extract_grob_set (me, "stems", stems); + + Array dirs; + for (int i = 0; i < stems.size (); i++) + { + dirs.push (to_dir (stems[i]->get_property ("default-direction"))); + } + + int last_nonneutral = -1; + int next_nonneutral = 0; + while (next_nonneutral < dirs.size() && !dirs[next_nonneutral]) + next_nonneutral ++; + + while (last_nonneutral < dirs.size () - 1) + { + Direction d1 = CENTER; + Direction d2 = CENTER; + if (last_nonneutral >= 0) + d1 = dirs[last_nonneutral]; + if (next_nonneutral < dirs.size ()) + d2 = dirs[next_nonneutral]; + + Direction total = CENTER; + if (d1 && d1 == d2) + total = d1; + else if (d1 && !d2) + total = d1; + else if (d2 && !d1) + total = d2; + else + total = to_dir (me->get_property ("neutral-direction")); + + for (int i = last_nonneutral + 1; i < next_nonneutral; i++) + stems[i]->set_property ("neutral-direction", scm_from_int (total)); + + + last_nonneutral = next_nonneutral; + while (last_nonneutral < dirs.size () + && dirs[last_nonneutral]) + last_nonneutral ++; + next_nonneutral = last_nonneutral; + last_nonneutral --; + + while (next_nonneutral < dirs.size () + && !dirs[next_nonneutral]) + next_nonneutral ++; + } + + me->suicide (); + return SCM_UNSPECIFIED; +} + +void +Melody_spanner::add_stem (Grob *me, Grob *stem) +{ + Pointer_group_interface::add_grob (me, ly_symbol2scm ("stems"), stem); + stem->set_object ("melody-spanner", me->self_scm ()); + stem->set_property ("neutral-direction", Melody_spanner::calc_neutral_stem_direction_proc); +} + +ADD_INTERFACE (Melody_spanner, "melody-spanner-interface", + "Context dependent typesetting decisions.", + + "stems " + "neutral-direction "); + + diff --git a/lily/stem-engraver.cc b/lily/stem-engraver.cc index 019b05333f..f89381433f 100644 --- a/lily/stem-engraver.cc +++ b/lily/stem-engraver.cc @@ -169,7 +169,9 @@ Stem_engraver::try_music (Music *m) } #include "translator.icc" + ADD_ACKNOWLEDGER (Stem_engraver, rhythmic_head); + ADD_TRANSLATOR (Stem_engraver, /* doc */ "Create stems and single-stem tremolos. It also works together with " "the beam engraver for overriding beaming.", diff --git a/lily/stem.cc b/lily/stem.cc index 62f9c8669b..8238deb233 100644 --- a/lily/stem.cc +++ b/lily/stem.cc @@ -461,33 +461,37 @@ Stem::calc_direction (SCM smob) dir = get_grob_direction (me); } else - dir = get_default_dir (me); + { + SCM dd = me->get_property ("default-direction"); + dir = to_dir (dd); + if (!dir) + return me->get_property ("neutral-direction"); + } return scm_from_int (dir); } -/* A separate function, since this is used elsewhere too. */ -Direction -Stem::get_default_dir (Grob *me) +MAKE_SCHEME_CALLBACK(Stem, calc_default_direction, 1); +SCM +Stem::calc_default_direction (SCM smob) { + Grob *me = unsmob_grob (smob); + Direction dir = CENTER; int staff_center = 0; Interval hp = head_positions (me); if (!hp.is_empty ()) { - int udistance = (int) (UP *hp[UP] - staff_center); - int ddistance = (int) (DOWN *hp[DOWN] - staff_center); + int udistance = (int) (UP * hp[UP] - staff_center); + int ddistance = (int) (DOWN * hp[DOWN] - staff_center); - if (sign (ddistance - udistance)) - dir = Direction (sign (ddistance - udistance)); - else - dir = to_dir (me->get_property ("neutral-direction")); + dir = Direction (sign (ddistance - udistance)); } - return dir; + + return scm_from_int (dir); } - MAKE_SCHEME_CALLBACK (Stem, height, 1); SCM Stem::height (SCM smob) @@ -959,6 +963,7 @@ ADD_INTERFACE (Stem, "stem-interface", "avoid-note-head " "beam " "beaming " + "default-direction " "details " "direction " "duration-log " diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index 12af9bcebb..82d9a3654d 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -142,6 +142,7 @@ negative, no line is drawn at all.") dash-period. Should be between 0.0 (no line) and 1.0 (continuous line).") + (default-direction ,ly:dir? "Direction determined by note head positions.") (direction ,ly:dir? "Up or down, left or right?") (dot-color ,symbol? "Color of dots. Options include @code{black} and @code{white}.") diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index 44ba247e45..fbf6239b8b 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -929,6 +929,28 @@ text-interface font-interface)))))) + + (MeasureGrouping + . ( + (Y-offset . ,Side_position_interface::y_aligned_side) + (side-axis . ,Y) + + (stencil . ,Measure_grouping::print) + + (padding . 2) + (direction . 1) + (thickness . 1) + (height . 2.0) + (staff-padding . 3) + (meta . ((class . Spanner) + (interfaces . (side-position-interface + measure-grouping-interface)))))) + + (MelodyItem + . ( + (neutral-direction . ,DOWN) + (meta . ((class . Item) + (interfaces . (melody-spanner-interface spacing-interface)))))) (MensuralLigature . ( (thickness . 1.4) @@ -954,21 +976,6 @@ font-interface metronome-mark-interface)))))) - (MeasureGrouping - . ( - (Y-offset . ,Side_position_interface::y_aligned_side) - (side-axis . ,Y) - - (stencil . ,Measure_grouping::print) - - (padding . 2) - (direction . 1) - (thickness . 1) - (height . 2.0) - (staff-padding . 3) - (meta . ((class . Spanner) - (interfaces . (side-position-interface - measure-grouping-interface)))))) (MultiMeasureRest . ( @@ -1490,6 +1497,7 @@ (Stem . ( (direction . ,Stem::calc_direction) + (default-direction . ,Stem::calc_default_direction) (stem-end-position . ,Stem::calc_stem_end_position) (stem-info . ,Stem::calc_stem_info) (positioning-done . ,Stem::calc_positioning_done)