]> git.donarmstrong.com Git - lilypond.git/blob - lily/fingering-column-engraver.cc
Issue 5024: Rework the Preinit framework into something simpler
[lilypond.git] / lily / fingering-column-engraver.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 "engraver.hh"
21 #include "side-position-interface.hh"
22 #include "pointer-group-interface.hh"
23 #include "fingering-column.hh"
24 #include "item.hh"
25
26 #include "translator.icc"
27
28 /**
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
32 {
33   Drul_array<Grob *> fingering_columns_;
34   Drul_array<vector<Grob *> > scripts_;
35   vector<Grob *> possibles_;
36
37 public:
38   TRANSLATOR_DECLARATIONS (Fingering_column_engraver);
39 protected:
40   void acknowledge_finger (Grob_info);
41   void process_acknowledged ();
42   void stop_translation_timestep ();
43 };
44
45 Fingering_column_engraver::Fingering_column_engraver ()
46 {
47   for (LEFT_and_RIGHT (d))
48     fingering_columns_[d] = 0;
49 }
50
51 void
52 Fingering_column_engraver::stop_translation_timestep ()
53 {
54   for (vsize i = 0; i < possibles_.size (); i++)
55     if (!Item::is_non_musical (possibles_[i]))
56       {
57         if (Side_position_interface::get_axis (possibles_[i]) == X_AXIS)
58           {
59             Direction d = robust_scm2dir (possibles_[i]->get_property ("direction"), CENTER);
60             if (d)
61               scripts_[d].push_back (possibles_[i]);
62             else
63               possibles_[i]->warning ("Cannot add a fingering without a direction.");
64           }
65       }
66
67   for (LEFT_and_RIGHT (d))
68     {
69       if (scripts_[d].size () < 2 && fingering_columns_[d])
70         {
71           fingering_columns_[d]->suicide ();
72           fingering_columns_[d] = 0;
73         }
74       if (fingering_columns_[d])
75         {
76           for (vsize i = 0; i < scripts_[d].size (); i++)
77             Fingering_column::add_fingering (fingering_columns_[d], scripts_[d][i]);
78
79         }
80       scripts_[d].clear ();
81       fingering_columns_[d] = 0;
82     }
83   possibles_.clear ();
84 }
85
86 void
87 Fingering_column_engraver::acknowledge_finger (Grob_info inf)
88 {
89   Item *thing = dynamic_cast<Item *> (inf.grob ());
90   if (thing)
91     possibles_.push_back (thing);
92 }
93
94 void
95 Fingering_column_engraver::process_acknowledged ()
96 {
97   for (LEFT_and_RIGHT (d))
98     {
99       if (possibles_.size () > 1 && !fingering_columns_[d])
100         fingering_columns_[d] = make_item ("FingeringColumn", SCM_EOL);
101     }
102 }
103
104 void
105 Fingering_column_engraver::boot ()
106 {
107   ADD_ACKNOWLEDGER (Fingering_column_engraver, finger);
108 }
109
110 ADD_TRANSLATOR (Fingering_column_engraver,
111                 /* doc */
112                 "Find potentially colliding scripts and put them into a"
113                 " @code{FingeringColumn} object; that will fix the collisions.",
114
115                 /* create */
116                 "FingeringColumn ",
117
118                 /* read */
119                 "",
120
121                 /* write */
122                 ""
123                );