2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2012 Mike Solomon <mike@mikesolomon.org>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
21 #include "fingering-column.hh"
22 #include "pointer-group-interface.hh"
23 #include "staff-symbol-referencer.hh"
25 #include "paper-column.hh"
27 MAKE_SCHEME_CALLBACK (Fingering_column, calc_positioning_done, 1);
29 Fingering_column::calc_positioning_done (SCM smob)
31 Grob *me = unsmob_grob (smob);
35 me->set_property ("positioning-done", SCM_BOOL_T);
37 extract_grob_set (me, "fingerings", const_fingerings);
39 if (const_fingerings.size () < 2)
41 me->programming_error ("This FingeringColumn should have never been created.");
45 vector<Grob *> fingerings;
46 for (vsize i = 0; i < const_fingerings.size (); i++)
47 fingerings.push_back (const_fingerings[i]);
50 Grob *common[2] = {common_refpoint_of_array (fingerings, me, X_AXIS),
51 common_refpoint_of_array (fingerings, me, Y_AXIS)};
53 Real padding = robust_scm2double (me->get_property ("padding"), 0.2);
55 // order the fingerings from bottom to top
56 vector_sort (fingerings, pure_position_less);
58 vector<Real> shift(fingerings.size());
60 // Try stacking the fingerings top-to-bottom, and then bottom-to-top.
61 // Use the average of the resulting stacked locations as the final positions
64 Real stack_end = -d * infinity_f;
66 for (vsize i = (d == UP)? 0 : fingerings.size() - 1;
67 i < fingerings.size ();
70 Interval x_ext = fingerings[i]->extent(common[X_AXIS], X_AXIS);
71 Interval y_ext = fingerings[i]->extent(fingerings[i], Y_AXIS);
72 Real parent_y = fingerings[i]->get_parent(Y_AXIS)
73 ->relative_coordinate(common[Y_AXIS], Y_AXIS);
75 // Checking only between sequential neighbors, seems good enough
76 if (!intersection(x_ext, prev_x_ext).is_empty())
77 stack_end += d * (y_ext.length() + padding);
78 // minmax() returns whichever is further along in direction d
79 stack_end = minmax(d, stack_end, parent_y);
81 shift[i] += 0.5 * (stack_end - y_ext[d] - parent_y);
87 for (vsize i = 0; i < fingerings.size (); i++)
88 fingerings[i]->translate_axis(shift[i], Y_AXIS);
94 Fingering_column::add_fingering (Grob *fc, Grob *f)
96 Pointer_group_interface::add_grob (fc, ly_symbol2scm ("fingerings"), f);
97 f->set_parent (fc, X_AXIS);
98 f->set_property ("Y-offset", Grob::x_parent_positioning_proc);
101 ADD_INTERFACE (Fingering_column,
102 "Makes sure that fingerings placed laterally"