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