]> git.donarmstrong.com Git - lilypond.git/blob - lily/concurrent-hairpin-engraver.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / concurrent-hairpin-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2011--2015 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
22 #include "international.hh"
23 #include "pointer-group-interface.hh"
24 #include "spanner.hh"
25 #include "stream-event.hh"
26 #include "warn.hh"
27 #include "item.hh"
28
29 #include "translator.icc"
30
31 using std::vector;
32
33 class Concurrent_hairpin_engraver : public Engraver
34 {
35 public:
36   TRANSLATOR_DECLARATIONS (Concurrent_hairpin_engraver);
37
38 protected:
39   DECLARE_ACKNOWLEDGER (hairpin);
40   DECLARE_END_ACKNOWLEDGER (hairpin);
41
42   void stop_translation_timestep ();
43   void finalize ();
44
45 private:
46   vector<Grob *> arriving_hairpins_;
47   vector<Grob *> departing_hairpins_;
48   vector<Grob *> hairpins_hanging_out_;
49 };
50
51 Concurrent_hairpin_engraver::Concurrent_hairpin_engraver ()
52 {
53 }
54
55 void
56 Concurrent_hairpin_engraver::acknowledge_hairpin (Grob_info info)
57 {
58   arriving_hairpins_.push_back (info.grob ());
59 }
60
61 void
62 Concurrent_hairpin_engraver::acknowledge_end_hairpin (Grob_info info)
63 {
64   departing_hairpins_.push_back (info.grob ());
65 }
66
67 void
68 Concurrent_hairpin_engraver::stop_translation_timestep ()
69 {
70   for (vsize i = 0; i < departing_hairpins_.size (); i++)
71     for (vsize j = 0; j < hairpins_hanging_out_.size (); j++)
72       if (departing_hairpins_[i] == hairpins_hanging_out_[j])
73         {
74           hairpins_hanging_out_.erase (hairpins_hanging_out_.begin () + j);
75           break;
76         }
77   if (arriving_hairpins_.size ())
78     {
79       if (arriving_hairpins_.size () > 1)
80         for (vsize i = 0; i < arriving_hairpins_.size () - 1; i++)
81           for (vsize j = i + 1; j < arriving_hairpins_.size (); j++)
82             {
83               Pointer_group_interface::add_grob (arriving_hairpins_[i], ly_symbol2scm ("concurrent-hairpins"), arriving_hairpins_[j]);
84               Pointer_group_interface::add_grob (arriving_hairpins_[j], ly_symbol2scm ("concurrent-hairpins"), arriving_hairpins_[i]);
85             }
86
87       for (vsize i = 0; i < arriving_hairpins_.size (); i++)
88         for (vsize j = 0; j < hairpins_hanging_out_.size (); j++)
89           {
90             Pointer_group_interface::add_grob (arriving_hairpins_[i], ly_symbol2scm ("concurrent-hairpins"), hairpins_hanging_out_[j]);
91             Pointer_group_interface::add_grob (hairpins_hanging_out_[j], ly_symbol2scm ("concurrent-hairpins"), arriving_hairpins_[i]);
92           }
93     }
94   hairpins_hanging_out_.insert (hairpins_hanging_out_.end (), arriving_hairpins_.begin (), arriving_hairpins_.end ());
95   arriving_hairpins_.resize (0);
96   departing_hairpins_.resize (0);
97 }
98
99 void
100 Concurrent_hairpin_engraver::finalize ()
101 {
102   hairpins_hanging_out_.resize (0);
103 }
104
105 ADD_ACKNOWLEDGER (Concurrent_hairpin_engraver, hairpin);
106 ADD_END_ACKNOWLEDGER (Concurrent_hairpin_engraver, hairpin);
107
108 ADD_TRANSLATOR (Concurrent_hairpin_engraver,
109                 /* doc */
110                 "Collect concurrent hairpins.",
111
112                 /* create */
113                 "",
114
115                 /* read */
116                 "",
117
118                 /* write */
119                 ""
120                );