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/>.
20 #include "engraver.hh"
21 #include "side-position-interface.hh"
22 #include "pointer-group-interface.hh"
23 #include "fingering-column.hh"
26 #include "translator.icc"
29 Find potentially colliding scripts, and put them in a
30 Fingering_column, that will fix the columns. */
31 class Fingering_column_engraver : public Engraver
33 Drul_array<Grob *> fingering_columns_;
34 Drul_array<vector<Grob *> > scripts_;
35 vector<Grob *> possibles_;
38 TRANSLATOR_DECLARATIONS (Fingering_column_engraver);
40 void acknowledge_finger (Grob_info);
41 void process_acknowledged ();
42 void stop_translation_timestep ();
45 Fingering_column_engraver::Fingering_column_engraver ()
47 for (LEFT_and_RIGHT (d))
48 fingering_columns_[d] = 0;
52 Fingering_column_engraver::stop_translation_timestep ()
54 for (vsize i = 0; i < possibles_.size (); i++)
55 if (!Item::is_non_musical (possibles_[i]))
57 if (Side_position_interface::get_axis (possibles_[i]) == X_AXIS)
59 Direction d = robust_scm2dir (possibles_[i]->get_property ("direction"), CENTER);
61 scripts_[d].push_back (possibles_[i]);
63 possibles_[i]->warning ("Cannot add a fingering without a direction.");
67 for (LEFT_and_RIGHT (d))
69 if (scripts_[d].size () < 2 && fingering_columns_[d])
71 fingering_columns_[d]->suicide ();
72 fingering_columns_[d] = 0;
74 if (fingering_columns_[d])
76 for (vsize i = 0; i < scripts_[d].size (); i++)
77 Fingering_column::add_fingering (fingering_columns_[d], scripts_[d][i]);
81 fingering_columns_[d] = 0;
87 Fingering_column_engraver::acknowledge_finger (Grob_info inf)
89 Item *thing = dynamic_cast<Item *> (inf.grob ());
91 possibles_.push_back (thing);
95 Fingering_column_engraver::process_acknowledged ()
97 for (LEFT_and_RIGHT (d))
99 if (possibles_.size () > 1 && !fingering_columns_[d])
100 fingering_columns_[d] = make_item ("FingeringColumn", SCM_EOL);
105 Fingering_column_engraver::boot ()
107 ADD_ACKNOWLEDGER (Fingering_column_engraver, finger);
110 ADD_TRANSLATOR (Fingering_column_engraver,
112 "Find potentially colliding scripts and put them into a"
113 " @code{FingeringColumn} object; that will fix the collisions.",