--- /dev/null
+\version "2.17.1"
+
+\header {
+ texidoc = "Horizontal @code{Fingering} grobs that collide do not intersect.
+Non-intersecting @code{Fingering} grobs are left alone.
+"
+}
+
+\relative c'' {
+ \set fingeringOrientations = #'(left)
+ \override Fingering #'staff-padding = #'()
+ \override Fingering #'add-stem-support = ##f
+ <d-0 c-3 f,-0>4 <d-0 f,-3 e-0>
+ <d^0 c^3 f,-0> <d^0 f,-0> <c^3 f,-0>
+ <d-0 c-0 b-0 a-0 g-0 f-0>
+}
--- /dev/null
+/*
+ This file is part of LilyPond, the GNU music typesetter.
+
+ Copyright (C) 1999--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+ LilyPond is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ LilyPond is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "engraver.hh"
+#include "side-position-interface.hh"
+#include "pointer-group-interface.hh"
+#include "fingering-column.hh"
+#include "item.hh"
+
+#include "translator.icc"
+
+/**
+ Find potentially colliding scripts, and put them in a
+ Fingering_column, that will fix the collisions. */
+class Fingering_column_engraver : public Engraver
+{
+ Drul_array<Grob *> fingering_columns_;
+ Drul_array<vector<Grob *> > scripts_;
+ vector<Grob *> possibles_;
+
+public:
+ TRANSLATOR_DECLARATIONS (Fingering_column_engraver);
+protected:
+ DECLARE_ACKNOWLEDGER (finger);
+ void process_acknowledged ();
+ void stop_translation_timestep ();
+};
+
+Fingering_column_engraver::Fingering_column_engraver ()
+{
+ for (LEFT_and_RIGHT (d))
+ fingering_columns_[d] = 0;
+}
+
+void
+Fingering_column_engraver::stop_translation_timestep ()
+{
+ for (vsize i = 0; i < possibles_.size (); i++)
+ if (!Item::is_non_musical (possibles_[i]))
+ {
+ if (Side_position_interface::get_axis (possibles_[i]) == X_AXIS)
+ {
+ Direction d = robust_scm2dir (possibles_[i]->get_property ("direction"), CENTER);
+ if (d)
+ scripts_[d].push_back (possibles_[i]);
+ else
+ possibles_[i]->warning ("Cannot add a fingering without a direction.");
+ }
+ }
+
+ for (LEFT_and_RIGHT (d))
+ {
+ if (scripts_[d].size () < 2 && fingering_columns_[d])
+ {
+ fingering_columns_[d]->suicide ();
+ fingering_columns_[d] = 0;
+ }
+ if (fingering_columns_[d])
+ {
+ for (vsize i = 0; i < scripts_[d].size (); i++)
+ Fingering_column::add_fingering (fingering_columns_[d], scripts_[d][i]);
+
+ }
+ scripts_[d].clear ();
+ fingering_columns_[d] = 0;
+ }
+ possibles_.clear ();
+}
+
+void
+Fingering_column_engraver::acknowledge_finger (Grob_info inf)
+{
+ Item *thing = dynamic_cast<Item *> (inf.grob ());
+ if (thing)
+ possibles_.push_back (thing);
+}
+
+void
+Fingering_column_engraver::process_acknowledged ()
+{
+ for (LEFT_and_RIGHT (d))
+ {
+ if (possibles_.size () > 1 && !fingering_columns_[d])
+ fingering_columns_[d] = make_item ("FingeringColumn", SCM_EOL);
+ }
+}
+
+ADD_ACKNOWLEDGER (Fingering_column_engraver, finger);
+ADD_TRANSLATOR (Fingering_column_engraver,
+ /* doc */
+ "Find potentially colliding scripts and put them into a"
+ " @code{FingeringColumn} object; that will fix the collisions.",
+
+ /* create */
+ "FingeringColumn ",
+
+ /* read */
+ "",
+
+ /* write */
+ ""
+ );
--- /dev/null
+/*
+ This file is part of LilyPond, the GNU music typesetter.
+
+ Copyright (C) 2002--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+ LilyPond is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ LilyPond is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "grob.hh"
+#include "fingering-column.hh"
+#include "pointer-group-interface.hh"
+#include "staff-symbol-referencer.hh"
+#include "item.hh"
+#include "paper-column.hh"
+
+#include <map>
+
+MAKE_SCHEME_CALLBACK (Fingering_column, calc_positioning_done, 1);
+SCM
+Fingering_column::calc_positioning_done (SCM smob)
+{
+ Grob *me = unsmob_grob (smob);
+ Real padding = robust_scm2double (me->get_property ("padding"), 0.0);
+ if (!me->is_live ())
+ return SCM_BOOL_T;
+
+ map<Grob *, bool> shifted;
+
+ Real ss = Staff_symbol_referencer::staff_space (me);
+
+ me->set_property ("positioning-done", SCM_BOOL_T);
+
+ extract_grob_set (me, "fingerings", const_fingerings);
+
+ if (const_fingerings.size () < 2)
+ {
+ me->programming_error ("This FingeringColumn should have never been created.");
+ return SCM_BOOL_T;
+ }
+
+ // order the fingerings from bottom to top
+ vector<Grob *> fingerings;
+ for (vsize i = 0; i < const_fingerings.size (); i++)
+ fingerings.push_back (const_fingerings[i]);
+
+ vector_sort (fingerings, pure_position_less);
+
+ Grob *common[2] = {common_refpoint_of_array (fingerings, me, X_AXIS),
+ common_refpoint_of_array (fingerings, me, Y_AXIS)};
+
+ for (vsize i = 0; i < fingerings.size (); i++)
+ fingerings[i]->translate_axis (-fingerings[i]->extent (common[Y_AXIS], Y_AXIS).length () / 2, Y_AXIS);
+
+ for (vsize i = min (fingerings.size () - 1, fingerings.size () / 2 + 1); i >= 1; i--)
+ for (vsize j = i; j--;)
+ {
+ Interval ex_i = fingerings[i]->extent (common[X_AXIS], X_AXIS);
+ Interval ex_j = fingerings[j]->extent (common[X_AXIS], X_AXIS);
+ Interval ey_i = fingerings[i]->extent (common[Y_AXIS], Y_AXIS);
+ Interval ey_j = fingerings[j]->extent (common[Y_AXIS], Y_AXIS);
+ Real tval = min (0.0, (ey_i[DOWN] - ey_j[UP] - padding) / 2);
+ if (tval != 0.0 && !intersection (ex_i, ex_j).is_empty ())
+ {
+ if (shifted[fingerings[i]] || shifted[fingerings[j]])
+ fingerings[j]->translate_axis (tval * 2, Y_AXIS);
+ else
+ {
+ fingerings[i]->translate_axis (-tval, Y_AXIS);
+ fingerings[j]->translate_axis (tval, Y_AXIS);
+ }
+ shifted[fingerings[i]] = true;
+ shifted[fingerings[j]] = true;
+ }
+ }
+
+ for (vsize i = fingerings.size () / 2 - 1; i < fingerings.size () - 1; i++)
+ for (vsize j = i + 1; j < fingerings.size (); j++)
+ {
+ Interval ex_i = fingerings[i]->extent (common[X_AXIS], X_AXIS);
+ Interval ex_j = fingerings[j]->extent (common[X_AXIS], X_AXIS);
+ Interval ey_i = fingerings[i]->extent (common[Y_AXIS], Y_AXIS);
+ Interval ey_j = fingerings[j]->extent (common[Y_AXIS], Y_AXIS);
+ Real tval = max (0.0, (ey_i[UP] - ey_j[DOWN] + padding) / 2);
+ if (tval != 0.0 && !intersection (ex_i, ex_j).is_empty ())
+ {
+ if (shifted[fingerings[i]] || shifted[fingerings[j]])
+ fingerings[j]->translate_axis (tval * 2, Y_AXIS);
+ else
+ {
+ fingerings[i]->translate_axis (-tval, Y_AXIS);
+ fingerings[j]->translate_axis (tval, Y_AXIS);
+ }
+ shifted[fingerings[i]] = true;
+ shifted[fingerings[j]] = true;
+ }
+ }
+
+
+ return SCM_BOOL_T;
+}
+
+void
+Fingering_column::add_fingering (Grob *fc, Grob *f)
+{
+ Pointer_group_interface::add_grob (fc, ly_symbol2scm ("fingerings"), f);
+ f->set_parent (fc, X_AXIS);
+ f->set_property ("Y-offset", Grob::x_parent_positioning_proc);
+}
+
+ADD_INTERFACE (Fingering_column,
+ "Makes sure that fingerings placed laterally"
+ " do not collide.",
+
+ /* properties */
+ "padding "
+ "positioning-done "
+ );
--- /dev/null
+/*
+ This file is part of LilyPond, the GNU music typesetter.
+
+ Copyright (C) 1999--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+ LilyPond is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ LilyPond is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef FINGERING_COLUMN_HH
+#define FINGERING_COLUMN_HH
+
+#include "lily-proto.hh"
+#include "grob-interface.hh"
+#include "std-vector.hh"
+
+struct Fingering_column
+{
+ static void add_fingering (Grob *, Grob *);
+ DECLARE_SCHEME_CALLBACK (calc_positioning_done, (SCM));
+ DECLARE_GROB_INTERFACE ();
+};
+
+#endif /* FINGERING_COLUMN_HH */
\consists "Script_engraver"
\consists "Script_column_engraver"
+ \consists "Fingering_column_engraver"
\consists "Rhythmic_column_engraver"
\consists "Note_spacing_engraver"
\consists "Spanner_break_forbid_engraver"
text-interface
text-script-interface))))))
+ (FingeringColumn
+ . (
+ (padding . 0.2)
+ (positioning-done . ,ly:fingering-column::calc-positioning-done)
+ (meta . ((class . Item)
+ (interfaces . (fingering-column-interface))))))
+
(Flag
. (
(glyph-name . ,ly:flag::glyph-name)