]> git.donarmstrong.com Git - lilypond.git/blob - lily/fingering-column.cc
Deletes Box_quarantine.
[lilypond.git] / lily / fingering-column.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2012 Mike Solomon <mike@mikesolomon.org>
5
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.
10
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.
15
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/>.
18 */
19
20 #include "grob.hh"
21 #include "fingering-column.hh"
22 #include "pointer-group-interface.hh"
23 #include "staff-symbol-referencer.hh"
24 #include "item.hh"
25 #include "paper-column.hh"
26
27 MAKE_SCHEME_CALLBACK (Fingering_column, calc_positioning_done, 1);
28 SCM
29 Fingering_column::calc_positioning_done (SCM smob)
30 {
31   Grob *me = unsmob_grob (smob);
32   if (!me->is_live ())
33     return SCM_BOOL_T;
34
35   me->set_property ("positioning-done", SCM_BOOL_T);
36
37   extract_grob_set (me, "fingerings", const_fingerings);
38
39   if (const_fingerings.size () < 2)
40     {
41       me->programming_error ("This FingeringColumn should have never been created.");
42       return SCM_BOOL_T;
43     }
44
45   vector<Grob *> fingerings;
46   for (vsize i = 0; i < const_fingerings.size (); i++)
47     fingerings.push_back (const_fingerings[i]);
48
49
50   Grob *common[2] = {common_refpoint_of_array (fingerings, me, X_AXIS),
51                      common_refpoint_of_array (fingerings, me, Y_AXIS)};
52
53   Real padding = robust_scm2double (me->get_property ("padding"), 0.2);
54
55   // order the fingerings from bottom to top
56   vector_sort (fingerings, pure_position_less);
57
58  vector<Real> shift(fingerings.size());
59
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
62   for (UP_and_DOWN (d))
63      {
64       Real stack_end = -d * infinity_f;
65       Interval prev_x_ext;
66       for (vsize i = (d == UP)? 0 : fingerings.size() - 1;
67            i < fingerings.size ();
68            i += d)
69         {
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);
74
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);
80
81           shift[i] += 0.5 * (stack_end - y_ext[d] - parent_y);
82
83           prev_x_ext = x_ext;
84         }
85      }
86
87   for (vsize i = 0; i < fingerings.size (); i++)
88     fingerings[i]->translate_axis(shift[i], Y_AXIS);
89
90  return SCM_BOOL_T;
91 }
92
93 void
94 Fingering_column::add_fingering (Grob *fc, Grob *f)
95 {
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);
99 }
100
101 ADD_INTERFACE (Fingering_column,
102                "Makes sure that fingerings placed laterally"
103                " do not collide.",
104
105                /* properties */
106                "padding "
107                "positioning-done "
108               );